chomenko / inline-routing
Inline routing from Nette framework
Installs: 123
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:extension
Requires
- php: >=7.2
- chomenko/presenter-factory-listener: ^1.0
- kdyby/annotations: ^2.5
- kdyby/doctrine: ^3.3
- nette/di: ^2.4 || ^3.0
- symfony/config: ^4.3
- symfony/routing: ^4.3
This package is auto-updated.
Last update: 2024-10-23 22:28:09 UTC
README
Symfony Routing adapter into Nette
Required
Install these packages with composer. Packages kdyby/doctrine, kdyby/annotations require configurations.
Install and configure
The best way to install chomenko/inline-routing is using Composer:
composer require chomenko/inline-routing
and now enable the extension using your neon config
extensions: console: Kdyby\Console\DI\ConsoleExtension events: Kdyby\Events\DI\EventsExtension annotations: Kdyby\Annotations\DI\AnnotationsExtension doctrine: Kdyby\Doctrine\DI\OrmExtension inlineRouting: Chomenko\InlineRouting\DI\InlineRoutingExtension
and adding trait into base presenter
<?php namespace App; use Chomenko\InlineRouting\InlineRouting; use Nette\Application\UI\Presenter; abstract class BasePresenter extends Presenter { use InlineRouting; }
Usage
Create simple route. You can create a route by using annotations @Inline\Route
The basic Nette route must be created for the presenter.
<?php namespace App; use Chomenko\InlineRouting\Inline; class SimplePresenter extends BasePresenter { /** * @link http://example.com/helow-world * * @Inline\Route("/hello-world", name="first-route") */ public function helloWorld() { $this->payload->hello = "world"; $this->sendPayload(); } /** * @link http://example.com/hello-parameters/this-si-foo/prefix-this-is-bar * * @Inline\Route("/hello-parameters/{foo}/prefix-{bar}", name="hello-parameters") * * @param mixed $foo * @param mixed $bar */ public function helloParameters($foo, $bar) { $this->payload->foo = $foo; $this->payload->bar = $bar; $this->sendPayload(); } }
you can also create a routine over the presenter
<?php namespace App; use Chomenko\InlineRouting\Inline; /** * @Inline\Route("/prefix", name="prefix_") */ class SimplePresenter extends BasePresenter { /** * @link http://example.com/prefix/hello-world * * @Inline\Route("/hello-world", name="first-route") */ public function helloWorld() { $this->payload->hello = "world"; $this->sendPayload(); } }
you can also transform a value into an entity
<?php namespace App; use Chomenko\InlineRouting\Inline; use Entity\User; /** * @Inline\Route("/user", name="users-") */ class SimplePresenter extends BasePresenter { /** * @link http://example.com/user/detail/1 * * @Inline\Route("/detail/{userId}", name="detail") * @Inline\EntityTransform( * class="Entity\User", * parameter="userId" * ) * * @param User $user */ public function detail(User $user) { $this->payload->userName = $user->getName(); $this->sendPayload(); } }