PHP code example of jakewhiteley / bladezero

1. Go to this page and download the library: Download jakewhiteley/bladezero library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jakewhiteley / bladezero example snippets


use Bladezero\Factory;

$templatesPath = realpath('./files');
$cachePath = realpath('./cache');

$blade = new Factory($templatesPath, $cachePath);

// Make and output a view with some data
echo $blade->make('example', ['title' => 'It Works!']);

// Add a new templates directory
$blade->addLocation(realpath('./shared/components'));

// Add a namespace
$blade->addNamespace('shared', realpath('./shared/components'));

// Register a component
$blade->component('components.alert', 'alert');

// Register a custom directive
$blade->directive('foo', function($expression) {
    return " echo 'foo' . $expression; 

$blade->setCsrfHandler(function(): string {
    return MySessionClass::getUserToken();
});

$blade->setAuthHandler(function(string $guard = null): bool {
    return MyUserClass::currentUserIs($guard);
});

$blade->setcanHandler(function($abilities, $arguments = []): bool {
    return MyUserClass::currentUserCan($abilities, $arguments);
});

$blade->setInjectHandler(function(string $service) {
    return MyContainer::resolveService($service);
});

$blade->setErrorHandler(function(string $key) {
    return MyErrorBag::getErrorMessageFor($key);
});