2019-09-18
Smart code refers to a special notation for writing variables.
Technically, a smart code is an alias for the BabyYaml inline syntax.
So for instance:
SmartCode | Php value equivalent |
---|---|
hello | string hello |
123 | int 123 |
12.3 | float 12.3 |
null | null |
true | true |
false | false |
[a, b] | array ["a", "b"] |
{a: 123, b: 456 } | array ["a" => 123, "b" => 456] |
{a: 123, b: [e, t] } | array ["a" => 123, "b" => ["e", "t"]] |
Now this syntax is very flexible. As it turns out, it has been used in various ways, mostly to provide developers with a tool for creating custom notations on the fly.
Some examples include:
- SmartCodeTool::parse, to parse the smart code as is
- SmartCodeTool::parseArguments, to parse arguments using the smart code notation
- SmartCodeTool::replaceSmartCodeFunction, to replace smart code recursively in an array using a function-like notation
- ClassTool::executePhpMethod, a little bit more involved notation to create class instances or call services