PHP code example of decodelabs / horizon

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

    

decodelabs / horizon example snippets


use DecodeLabs\Horizon\Page;
use DecodeLabs\Tagged as Html;

$page = new Page(function($page) {
    $page->title = 'Hello, World!';
    $page->setMeta('description', 'This is a test page');

    $page->addLink(
        key: 'styles',
        rel: 'stylesheet',
        href: '/styles.css'
    );

    $page->addLink(
        key: 'favicon',
        rel: 'icon',
        href: '/favicon.ico'
    );

    $page->addBodyScript(
        key: 'bundle',
        src: '/bundle-45346534.js'
    );

    $page->bodyTag->addClass('section-home');

    yield Html::{'h1'}('Hello, World!');
    yield Html::{'p'}('This is a test page');
});

namespace DecodeLabs\Horizon\Decorator;

use DecodeLabs\Horizon\Decorator;
use DecodeLabs\Horizon\Page;

class MyDecorator implements Decorator
{
    public function decorate(
        Page $page, // Require parameter
        string $basePath // Decorator-specific parameter
    ): void {
        $page->title = 'My Decorated Page';

        $page->addBodyScript(
            key: 'analytics',
            src: $basePath.'/analytics.js'
        );
    }
}

$page = new Page(function($page) {
    yield Html::{'h1'}('Hello, World!');
    yield Html::{'p'}('This is a test page');
});

$page->decorate('MyDecorator', '/base/path');

use DecodeLabs\Greenleaf\Action;
use DecodeLabs\Greenleaf\Action\ByMethodTrait;
use DecodeLabs\Horizon\Harvest;

class MyAction implements Action
{
    use ByMethodTrait;

    public function get(): Page
    {
        return new Page(function() {
            yield 'My content';
        });
    }
}