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

PHP - enums as string

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Won't Fix
    • Affects Version/s: None
    • Fix Version/s: None
    • Labels:
    • Patch Info:
      Patch Available

      Description

      I've created patch for php code generator and for php library, which will allow you to use string in enums (these string will be converted from/to integers while receiving/sending).

      Example:
      // thrift definition
      enum CheckService {
      ping = 1,
      ssh = 2,
      http = 3,
      telnet = 4,
      }

      Now, you can send as value 'ping' or 1, the protocol will always transfer I32 of value 1.
      When receiving on other side, 1 is automatically converted to 'ping'.

      By default, this patch has no effect. To turn on the conversion, you have to activate on whole thrift by
      TBase::$allowEnumConversion = true;
      or per struct MyStruct::$allowEnumConversion = true; which will turn on convertion for all enums directly accessible from this struct (but not in structs on deeper level)

      (this patch includes patch for namespaces, I posted some days before)

      Link 1 (php library patch): http://helemik.cz/juzna/opensource/php/thrift/p-enum.patch
      Link 2 (php compiler patch): http://helemik.cz/juzna/opensource/php/thrift/p-enum2.patch

      (Is it possible to join in to upstream? Please, someone "who's in" charge, concat me on my email or on IRC)

      juzna

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              juzna.cz Jan Dolecek
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 0.5h
                0.5h
                Remaining:
                Remaining Estimate - 0.5h
                0.5h
                Logged:
                Time Spent - Not Specified
                Not Specified