$compiledClasses
$compiledClasses : array
Compiles a class property map into object form.
$_propertyMapCache : \LazyJsonMapper\Property\PropertyMapCache
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!
\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 |
If there is a problem with any of the property definitions.
If there is a problem with the map structure itself.
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 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!
__construct(boolean $isRootCompiler, \LazyJsonMapper\Property\PropertyMapCache $propertyMapCache, string $solveClassName)
Private Constructor.
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 |
_compile()
The real, internal compiler algorithm entry point.
MUST be wrapped in another function which handles compilation failures!
_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!)
_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.
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. |
_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.
string | $propName | The property name. |
string | $propDefStr | A string describing the property. |
_importClassMap(string $strictImportClassName)
Import another class map into the current class.
string | $strictImportClassName | The strict, global path to the
class, with leading backslash |
_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.
string | $className | The full path of the class to sub-compile, but
without any leading |