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";
})
];
}
}