Convert both Partial & Component classes to enable object instantiation
This MR:
- Adds constructor methods to both the
\Granola\Partial
&\Granola\Component
classes, allowing us to instantiate Components and so access instance path/name/args properties:
$component = new \Granola\Component($name, $args); // Instantiate component.
$items = $component->args['items']; // Later, retrieve "calculated" component argument, post-filtering.
- Adds a
__toString()
Magic Method to the Partial class which enables the option toecho
these objects:
echo new \Granola\Component($name, $args);
- Updates the Partial
get()
function (and uses✨ late static binding✨ ) to retain the existing static partial/component generation across the theme:
$component = \Granola\Component::get($name, $args); // still valid.
- Refactors the
global $granolaPartialStack
. This could/can be used to contextually find out if the current partial was nested inside another partial (though there was a minor downside of not having the 'calculated' $args as the partial data was pushed onto the stack before the $args were run through the core Granola filters).
This has now been convered into a publically accessible 'parent' class property for each partial instance, which nests 'upwards'; each partial's parent can have its own parent until the root partial which has a null
parent. This is handled via a protected static class variable which is updated both before the $args are filtered and before output so nested partials have the correct parent partial whether they're added in their parent's $args filter function, or their parent's template file.