Write controller once and let many other frameworks use it.
This repository is maintained by @Lexinek.
composer require symplify/symbiotic-controller
# app/config/config.neon
extensions:
- Symplify\SymbioticController\Adapter\Nette\DI\SymbioticControllerExtension
- Contributte\EventDispatcher\DI\EventDispatcherExtension
This is what you use the most often.
namespace App\Presenter;
use Symplify\SymbioticController\Contract\Template\TemplateRendererInterface;
final class StandalonePresenter
{
/**
* @var TemplateRendererInterface
*/
private $templateRenderer;
public function __construct(TemplateRendererInterface $templateRenderer)
{
$this->templateRenderer = $templateRenderer;
}
public function __invoke(): string
{
return $this->templateRenderer->renderFileWithParameters(
__DIR__ . '/templates/Contact.latte'
);
}
}
namespace App\Presenters;
use Nette\Application\Responses\TextResponse;
final class ContactPresenter
{
public function __invoke(): TextResponse
{
return new TextResponse('Hi!');
}
}
namespace App\Presenters;
use Nette\Application\Responses\JsonResponse;
final class ContactPresenter
{
public function __invoke(): TextResponse
{
return new JsonResponse('Hi!');
}
}
Hey :-)
# app/Router/RouterFactory.php
namespace App\Router;
final class RouterFactory
{
public function create(): RouteList
{
$routes = new RouteList;
$routes[] = new PresenterRoute('/contact', ContactPresenter::class);
$routes[] = new Route('<presenter>/<action>', 'Homepage:default');
return $routes;
}
}
That's all :)