Properties

$compiledClasses

$compiledClasses : array

Type

array — All classes that were compiled by us or our sub-compilers.

$uncompiledPropertyClasses

$uncompiledPropertyClasses : array

Type

array — Uncompiled classes seen in properties by us or our sub-compilers.

$_isRootCompiler

$_isRootCompiler : boolean

Type

boolean — Whether this is the root-level compiler or a sub-compiler.

$_solveClassName

$_solveClassName : string

Type

string — Path of the solve-class, without leading backslash.

$_strictSolveClassName

$_strictSolveClassName : string

Type

string — Strict global path (with leading backslash) to solve-class.

$_classHierarchy

$_classHierarchy : array

Type

array — The reflected class hierarchy for the solve-class.

$_ourCompilerClassLocks

$_ourCompilerClassLocks : array

Type

array — Classes that WE have locked during hierarchy compilation.

$_previousMapConstantValue

$_previousMapConstantValue : mixed

Type

mixed — Used by old PHP (before 7.1) for detecting unique (non-inherited) class constants.

$_currentClassInfo

$_currentClassInfo : array

Type

array — The current class we're processing in the hierarchy.

$_currentClassPropertyMap

$_currentClassPropertyMap : array

Type

array — Holds current class' property map as it's being built.

Methods

compileClassPropertyMap()

compileClassPropertyMap(\LazyJsonMapper\Property\PropertyMapCache  $propertyMapCache, string  $solveClassName) 

Compiles the JSON property map for a class (incl. class inheritance).

Parses the entire chain of own, inherited and imported JSON property maps for the given class, and validates all definitions in the entire map.

Each class definition is only resolved and parsed a single time; the first time we encounter it. From then on, it is stored in the cache so that object creations can instantly link to their compiled map. And so any other classes which rely on that class can instantly re-use its map.

And all maps are built hierarchically, starting with their base class. Every sub-object which extends that object re-uses its parent's compiled PropertyDefinition objects, to reduce the memory requirements even more. The same is true for any imported maps via the import mechanism.

As an additional layer of protection, ALL properties (in the current class and its extends/import-hierarchy) that point to uncompiled classes will ALSO be verified and compiled, to ensure that THEIR class property maps compile successfully. And it will happen recursively until all linked classes (inheritance, imports and property links) have been fully compiled throughout the entire linked hierarchy. It ensures that users will be able to FULLY trust that EVERY property in their class and its ENTIRE tree of related classes are pointing at classes that have been successfully compiled and are known to work and are ready for reliable use at runtime.

That extra protection does however also mean that your runtime's initial compile-calls will take the longest, since they'll spider-crawl the ENTIRE hierarchy of extends, imports, and ALL properties of each, and then ALL extends and imports and properties of the classes pointed to by those properties, and so on... But despite all of that extra work, it's STILL blazingly FAST at compiling, and the extra security is well worth it! And as soon as all relevant maps are compiled during your current runtime, this function won't have to do any work anymore! Then you can just relax and fully trust that all of your class maps are perfect! :-)

If there are ANY compilation problems, then an automatic rollback takes place which restores the PropertyMapCache to its original pre-call state.

This compiler algorithm provides perfect peace of mind. If it doesn't throw any errors, it means that your entire class hierarchy has been compiled and is ready for use in your cache!

Parameters

\LazyJsonMapper\Property\PropertyMapCache $propertyMapCache

The cache to use for storage and lookups. Will be written to.

string $solveClassName

The full path of the class to compile, but without any leading \ global prefix. To save time, we assume the caller has already verified that it is a valid LazyJsonMapper class.

Throws

\LazyJsonMapper\Exception\BadPropertyDefinitionException

If there is a problem with any of the property definitions.

\LazyJsonMapper\Exception\BadPropertyMapException

If there is a problem with the map structure itself.

\LazyJsonMapper\Exception\CircularPropertyMapException

If there are bad circular map imports within either the class hierarchy (parents) or the imports of any part of the class you're trying to compile. This is a serious exception!

compile()

compile() 

Compile the solve-class, and its parent/import hierarchy (as-necessary).

Intelligently watches for compilation errors, and if so it performs an auto-rollback of ALL classes compiled by this compile()-call AND by all of its recursive sub-compilations (if any took place).

It performs the rollback if there were ANY issues with the solve-class or ANY part of its inheritance hierarchy (extends/imports) OR with the final post-processing compilation of all of the classes that THEIR properties were pointing at. And note that the post-processing is ALSO recursive and will FULLY validate the entire hierarchies and property trees of ALL classes that IT compiles, and so on... until no more work remains.

So if this function DOESN'T throw, then you can TRUST that the ENTIRE hierarchy of property maps related to the requested solve-class has been compiled. However, note that their final PROPERTY CLASS compilation step and final success-validation doesn't happen until the top-level rootCompiler is reached again, since it's the job of the root to handle the recursive compilation and resolving of all classes encountered in properties. So it's only the rootCompiler's compile()-call that TRULY matters and will determine whether EVERYTHING was successful or not.

Basically: If we fail ANY aspect of the request to compile, then we'll FULLY roll back everything that we've changed during our processing. Which safely guarantees that the FINAL map compilation cache ONLY contains fully verified and trustable classes and their COMPLETE class inheritance and property hierarchies!

Throws

\LazyJsonMapper\Exception\BadPropertyDefinitionException
\LazyJsonMapper\Exception\BadPropertyMapException
\LazyJsonMapper\Exception\CircularPropertyMapException

__construct()

__construct(boolean  $isRootCompiler, \LazyJsonMapper\Property\PropertyMapCache  $propertyMapCache, string  $solveClassName) 

Private Constructor.

Parameters

boolean $isRootCompiler

Whether this is the root-level compiler in a compile-stack.

\LazyJsonMapper\Property\PropertyMapCache $propertyMapCache

The class/lock cache to use.

string $solveClassName

The full path of the class to compile, but without any leading \ global prefix. To save time, we assume the caller has already verified that it is a valid LazyJsonMapper class.

Throws

\LazyJsonMapper\Exception\BadPropertyMapException

_compile()

_compile() 

The real, internal compiler algorithm entry point.

MUST be wrapped in another function which handles compilation failures!

Throws

\LazyJsonMapper\Exception\BadPropertyDefinitionException
\LazyJsonMapper\Exception\BadPropertyMapException
\LazyJsonMapper\Exception\CircularPropertyMapException

_reflectSolveClassHierarchy()

_reflectSolveClassHierarchy() 

Reflect all classes in the solve-class hierarchy.

Builds a list of all classes in the inheritance chain, with the base-level class as the first element, and the solve-class as the last element. (The order is important!)

Throws

\LazyJsonMapper\Exception\BadPropertyMapException

_checkCurrentLocks()

_checkCurrentLocks() 

Check for already-locked classes in the solve-class hierarchy.

Analyzes the solve-class hierarchy and verifies that we don't violate any current anti-circular map locks.

Throws

\LazyJsonMapper\Exception\CircularPropertyMapException

_lockUncompiledClasses()

_lockUncompiledClasses() 

Lock all uncompiled classes in the solve-class hierarchy.

Throws

\LazyJsonMapper\Exception\BadPropertyMapException

_processCurrentClass()

_processCurrentClass() 

Process the current class in the solve-class hierarchy.

Throws

\LazyJsonMapper\Exception\BadPropertyDefinitionException
\LazyJsonMapper\Exception\BadPropertyMapException
\LazyJsonMapper\Exception\CircularPropertyMapException

_processPropertyMapEntry()

_processPropertyMapEntry(string|integer  $propName, mixed  $propDefStr) 

Process a property map entry for the current class.

Validates and compiles a map entry, and merges it with the current class property map if everything went okay and the entry was new/different.

Parameters

string|integer $propName

The property name, or a numeric array key.

mixed $propDefStr

Should be a string describing the property or the class to import, but may be something else if the user has written an invalid class property map.

Throws

\LazyJsonMapper\Exception\BadPropertyDefinitionException
\LazyJsonMapper\Exception\BadPropertyMapException
\LazyJsonMapper\Exception\CircularPropertyMapException

_processPropertyDefinitionString()

_processPropertyDefinitionString(string  $propName, string  $propDefStr) 

Compile a property definition string and add it to the current class.

Attempts to compile the definition, and then appends it to the current class' final compiled map, IF the definition is valid and describes a new/different value compared to what's already in the current class map.

Parameters

string $propName

The property name.

string $propDefStr

A string describing the property.

Throws

\LazyJsonMapper\Exception\BadPropertyDefinitionException

_importClassMap()

_importClassMap(string  $strictImportClassName) 

Import another class map into the current class.

Parameters

string $strictImportClassName

The strict, global path to the class, with leading backslash \. To save time, we assume the caller has already verified that it is a valid LazyJsonMapper class.

Throws

\LazyJsonMapper\Exception\BadPropertyDefinitionException
\LazyJsonMapper\Exception\BadPropertyMapException
\LazyJsonMapper\Exception\CircularPropertyMapException

_subcompile()

_subcompile(string  $className) 

Used internally when this compiler needs to run a sub-compilation.

Performs the sub-compile. And if it was successful (meaning it had no auto-rollbacks due to ITS compile() call failing), then we'll merge its compiler state with our own so that we preserve important state details.

Parameters

string $className

The full path of the class to sub-compile, but without any leading \ global prefix. To save time, we assume the caller has already verified that it is a valid LazyJsonMapper class.

Throws

\LazyJsonMapper\Exception\BadPropertyDefinitionException
\LazyJsonMapper\Exception\BadPropertyMapException
\LazyJsonMapper\Exception\CircularPropertyMapException