PHP code example of imponeer / smarty-sunrise-http-router

1. Go to this page and download the library: Download imponeer/smarty-sunrise-http-router 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/ */

    

imponeer / smarty-sunrise-http-router example snippets


use Imponeer\Smarty\Extensions\SunriseHTTPRouter\SunriseHttpRouterExtension;
use Sunrise\Http\Router\RouterInterface;

// $router is a configured Sunrise\Http\Router\RouterInterface instance
$router = $container->get(RouterInterface::class);

$smarty = new \Smarty\Smarty();
$smarty->addExtension(new SunriseHttpRouterExtension($router));

use Imponeer\Smarty\Extensions\SunriseHTTPRouter\SunriseHttpRouterExtension;
use Sunrise\Http\Router\RouterInterface;
use function DI\create;
use function DI\get;

return [
    SunriseHttpRouterExtension::class => create()->constructor(get(RouterInterface::class)),
    \Smarty\Smarty::class => create()->method('addExtension', get(SunriseHttpRouterExtension::class)),
];

use Imponeer\Smarty\Extensions\SunriseHTTPRouter\SunriseHttpRouterExtension;
use Sunrise\Http\Router\RouterInterface;

$container = new \League\Container\Container();

$container->add(RouterInterface::class, function () {
    // Build and return your RouterInterface implementation
});

$container->add(\Smarty\Smarty::class, function () use ($container) {
    $smarty = new \Smarty\Smarty();
    $smarty->addExtension(new SunriseHttpRouterExtension($container->get(RouterInterface::class)));

    return $smarty;
});