Development Overview

March 16, 2017 ยท View on GitHub

Application structure

All references are inside the Radic\BladeExtensions namespace.

ReferenceDescription
BladeExtensions::classProvides 'features': compileString and pushToStack
DirectiveRegistry::classHandles all the directives logic
HelperRepository::classContains instances for some helpers
Contracts\...Contracts for the BladeExtensions, DirectiveRegistery and HelperRepository. Should be prefered to use with DI
Directives\...Contains all the core directive classes
Directives\DirectiveInterface::classInterface for directives
Directives\AbstractDirective::classOptional abstract class for directives
Helpers\...Contains helper classes that (are/can be) used by directives
Exceptions\*::classException classes
Facades\BladeExtensions::classThe Facade that can be registered

Directives

  • All directive classes need to implement the interface Radic\BladeExtensions\Directives\DirectiveInterface. In most cases, using the abstract class Radic\BladeExtensions\Directives\AbstractDirective is faster.
  • Core directive classes are located in Radic\BladeExtensions\Directives.
  • Core directive test classes are located in Radic\Tests\BladeExtensions\Directives
  • Directive test classes usually extend the Radic\Tests\BladeExtensions\DirectivesTestCase.
  • The DirectiveRegistry contains the directives and the logic for handling them.
  • Directives and version overrides are added to the DirectiveRegistry by adding them to the blade-extensions configuration.

Helpers

  • Can be traits, interfaces or (abstract) classes ment to aid in a specific directive or multiple directives.
  • The HelperRepository is used for storing instances of helper classes.

Lifecycle

1. The Radic\BladeExtensions\BladeExtensionsServiceProvider binds Radic\BladeExtensions\DirectiveRegistry.

2. When resolving the DirectiveRegistry the blade-extensions configuration is loaded into the registry.

$directives->register($app['config']['blade-extensions.directives']);
$directives->setVersionOverrides($app['config']['blade-extensions.version_overrides']);

3. The BladeExtensionsServiceProvider adds a callback to Application::booted that executes DirectiveRegistry@hookToCompiler()

4. The hookToCompiler method (by default) uses the Illuminate\View\Compilers\BladeCompiler@extend method, loops trough all directives and runs them using the DirectiveRegistry->call($name, $params = []) method.

// in `Radic\BladeExtensions\DirectiveRegistry::hookToCompiler()` 
foreach ($this->getNames() as $name) {
   $this->getCompiler()->extend(function ($value) use ($name) {
       return $this->call($name, [$value]);
   });
}

5. The DirectiveRegistry@call method 'resolves' the directive if not already resolved, then calls it.