symplify / symbiotic-controller
This package is abandoned and no longer maintained.
The author suggests using the nette/application package instead.
v2.5.8
2017-09-19 17:58 UTC
Requires
- php: ^7.1
- contributte/event-application-bridge: ^0.1
- contributte/event-dispatcher: ^0.3
- latte/latte: ^2.4|^3.0
- nette/application: ^2.4|^3.0
- nette/di: ^2.4|^3.0
- symplify/package-builder: ^2.3
Requires (Dev)
- nette/security: ^2.4|^3.0
- phpunit/phpunit: ^6.0
- tracy/tracy: ^2.4|^3.0
- dev-master
- v2.5.8
- v2.5.7
- v2.5.6
- v2.5.5
- v2.5.4
- v2.5.3
- v2.5.1
- v2.5.0
- v2.4.3
- v2.4.2
- v2.4.1
- v2.4.0
- v2.3.4
- v2.3.3
- v2.3.2
- v2.3.1
- v2.3.0
- v2.2.15
- v2.2.14
- v2.2.13
- v2.2.12
- v2.2.11
- v2.2.10
- v2.2.9
- v2.2.8
- v2.2.7
- v2.2.6
- v2.2.5
- v2.2.4
- v2.2.3
- v2.2.2
- v2.2.1
- v2.2.0
- v2.1.8
- v2.1.7
- v2.1.6
- v2.1.5
- v2.1.4
- v2.1.3
- v2.1.2
- v2.1.1
- v2.1.0
- v2.0.1
- v2.0.0
- v2.0.0-RC3
- v2.0.0-RC2
- v2.0.0-RC1
- v1.4.10
- v1.4.9
This package is not auto-updated.
Last update: 2019-02-20 19:11:15 UTC
README
Write controller once and let many other frameworks use it.
This repository is maintained by @Lexinek.
Install
composer require symplify/symbiotic-controller
Usage in Nette
Register Extensions to you App
# app/config/config.neon extensions: - Symplify\SymbioticController\Adapter\Nette\DI\SymbioticControllerExtension - Contributte\EventDispatcher\DI\EventDispatcherExtension
1. Create app/Presenters/ContactPresenter.php
Presenter with __invoke()
Method
A. Classic Render Action
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' ); } }
B. The Simplest Response
namespace App\Presenters; use Nette\Application\Responses\TextResponse; final class ContactPresenter { public function __invoke(): TextResponse { return new TextResponse('Hi!'); } }
C. Or Json Response
namespace App\Presenters; use Nette\Application\Responses\JsonResponse; final class ContactPresenter { public function __invoke(): TextResponse { return new JsonResponse('Hi!'); } }
2. Create app/templates/Contact.latte
template
Hey :-)
3. Register Presenter Route
# 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; } }
4. Open page in Browser and Enjoy
That's all :)