PHP code example of boke0 / boke0ick_mecha

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

    

boke0 / boke0ick_mecha example snippets




namespace Boke0\Mechanism\Plugins\SamplePlugin;

use \Boke0\Mechanism\Api\Plugin;

$plugin=new Plugin();
$plugin->endpoint(SampleEndpoint::class);
$plugin->templateExtension(SampleTemplateExtension::class);

return $plugin;



namespace Boke0\Mechanism\Plugins\SamplePlugin;
use \Boke0\Mechanism\Api\Endpoint;

/**
 * @path /sampleendpoint
 */
class SampleEndpoint extends Endpoint{
    public function handle($req,$args){
        $res=$this->createResponse();
        $body=$res->getBody();
        $body->write("Hello world!");
        return $res->withBody($body);
    }
}



namespace Boke0\Mechanism\Plugins\SamplePlugin;
use \Boke0\Mechanism\Api\Endpoint;

/**
 * @path /sampleendpoint
 */
class SampleEndpoint extends Endpoint{
    public function handle($req,$args){
        return $this->twig("sample.tpl.html");
    }
}



namespace Boke0\Mechanism\Plugins\SamplePlugin;
use \Boke0\Mechanism\Api\TemplateExtension;

class SampleTemplateExtension extends TemplateExtension{
    public function getFunctions(){
        return [
            new \Twig\TwigFunction("sample",function(){
                echo "sample function this is";
            })
        ];
    }
}

/asset?theme=<テーマ名>&filename=<ディレクトリ内のパス>

/asset?plugin=<プラグイン名>&filename=<assetsディレクトリ以下のパス>