PHP code example of brainlight / brainlight-php

1. Go to this page and download the library: Download brainlight/brainlight-php 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/ */

    

brainlight / brainlight-php example snippets


use Brainlight\BrainlightPhp\Engine;

$engine = new Engine([
    'cacheDir' => __DIR__ . '/cache',
    'templatesDir' => __DIR__,
]);

echo $engine->render('templateName', [
    'title' => 'Homepage',
]);

use Brainlight\BrainlightPhp\Engine;

$engine = new Engine([
    'cacheDir' => __DIR__ . '/cache',
    'templatesDir' => __DIR__,
    'logicNamespace' => 'Logic',
]);

namespace Logic;

use Brainlight\BrainlightPhp\Logic;

class Button extends Logic
{
    // ...
}

namespace Logic;

use Brainlight\BrainlightPhp\Logic;

class Button extends Logic
{
    protected function getVariables(array $parameters): array
    {
        return $parameters;
    }
}

namespace Logic\Inclusions;

use Brainlight\BrainlightPhp\Logic;

class Page extends Logic
{
    protected array $mandatory = [
        'title',
    ];

    protected array $mandatorySlots = [
        'content',
    ];

    // ...
}

namespace Logic;

use Brainlight\BrainlightPhp\Logic;

class Button extends Logic
{
    public ?string $template = 'buttons.custom-template';

    // ...
}

$engine->render('button', [], true);

use Brainlight\BrainlightPhp\Engine;

$engine = new Engine([
    'cacheDir' => __DIR__ . '/cache',
    'templatesDir' => false,
]);

echo $engine->render(__DIR__ . '/templateName.brain');

[
    'escapeFlags' => ENT_QUOTES,
    'escapeEncoding' => 'UTF-8',
    'escapeDoubleEncode' => true,
]

composer