\LazyJsonMapper\MagicPropertyTranslation

Automatically translates a property name into equivalent FunctionCase name.

The translation into a function name will differ based on the style of the property name that was sent in as a parameter. That's intentional.


NOTE: We support snake_case and camelCase property styles. We do NOT support any other styles or any badly_mixed_Styles. If you cannot simply rename your badly named properties to valid names, then you can still access them via the internal LazyJsonMapper API instead of this magic translation!


WARNING: We do NOT support property names in "HumpBack" notation, whose first word is uppercased (even if it sits after leading underscores).

For example, __MessageList or MessageList as HumpBack input are invalid, but __message_list/message_list (snake) or __messageList/messageList (camel) are valid property names.

We WILL however accept HumpBack input and will provide a translation for it, but it will NOT be possible for FunctionTranslation to translate HumpBack style back to a property name. Just be aware of that! It's intentional, since HumpBack style is extremely rare and we save processing by not supporting it.


Translation Examples (RESULT LISTED FIRST, then what input was used):

  • __Foo_Bar__XBaz__ => __foo__bar___x_baz__ (snake) __foo_Bar__XBaz__ (camel)
  • 0m__AnUn0x => 0m___an_un0x (snake) & 0m__AnUn0x (camel)
  • Some0XThing => some0_x_thing (snake) & some0XThing (camel)
  • Some0xThing => some0x_thing (snake) & some0xThing (camel)
  • SomeThing => some_thing (snake) & someThing (camel)
  • Something => something (snake & camel identical; no ucwords)
  • ___ => ___ (snake & camel identical; no ucwords)
  • _0 => _0 (snake & camel identical; no ucwords)
  • _Messages => _messages (snake & camel identical; no ucwords)
  • __MessageList => __message_list (snake) & __messageList (camel)
  • 123 => 123 (snake & camel identical; no ucwords)
  • 123prop => 123prop (snake & camel identical; no ucwords)
  • 123Prop => 123_prop (snake) & 123Prop (camel)

NOTE: The class validates all parameters, but provides public properties to avoid needless function calls. It's therefore your responsibility to never assign any bad values to the public properties after this object's creation!

Summary

Methods
Properties
Constants
__construct()
$propFuncCase
No constants found
_propToFunctionCase()
No protected properties found
N/A
No private methods found
No private properties found
N/A

Properties

$propFuncCase

$propFuncCase : string

The property name in "FunctionCase" style.

For example AwesomeProperty.

Type

string

Methods

__construct()

__construct(string  $propertyName) 

Constructor.

Parameters

string $propertyName

The name of the property to translate, in either snake_case or camelCase style, such as awesome_property (snake) or awesomeProperty (camel). The translations will differ based on which style is used. (That's intentional.)

Throws

\LazyJsonMapper\Exception\MagicTranslationException

If the property name is unparseable.

_propToFunctionCase()

_propToFunctionCase(string  $propName) : string

Converts a property name to FunctionCase.

See input/output examples in class documentation above.

Parameters

string $propName

The property name, as either snake_case or camelCase. The translations will differ based on which style is used. (That's intentional.)

Returns

string