Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-1926

PHP Constant Generation Refactoring

    XMLWordPrintableJSON

Details

    • Patch Available

    Description

      When I have added PHP namespace, one point was missing from my refactoring: the constants.

      Actually, PHP constants are generated into $GLOBALS because PHP cannot generate constants for array or object with the function "define".

      But there is some problems:

      • Add vars in $GLOBALS is not a good pratice
      • These vars are not constant because user can modify them
      • Object constants instanciate a new object everytime the constant is call

      So I have added a new PHP Class in library called TConstant. The goal of this class which is a Singleton, is to isolate Constant, and instanciate them on-demand (only one time) in static properties. There is no setter so constants cannot be edited and the class is abstract.

      I have edited the PHP generator to create those constants given to the definition file. Every constant create a static property and an init method in a final class called Constant in the definition Namespace.

      To get a constant, you just have to write:
      \MyDefinitionNamepace\Constant::get('CONSTANT_NAME');

      If the constant doesn't exists, it throws a Fatal error like it is done in PHP when you call a static property which doesn't exists. Maybe we can add an exception.

      I have attached a diff patch made from the c613cd2d9bc01ee4eb43a3d40a8691c736f7a316 commit (Thrift-1846:Restore socket.h header to support builds with Android NDK). Because you aren't not in SVN anymore, I don't know how to send you this patch, I hope this one is good.

      I hope you like my patch.

      Attachments

        Activity

          People

            jensg Jens Geyer
            xkobal Xavier HAUSHERR
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: