bytic /
router
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Nip\Router\ServiceProvider\Traits; |
||
| 4 | |||
| 5 | use Symfony\Component\Config\FileLocator; |
||
| 6 | use Symfony\Component\Routing\Loader\DirectoryLoader; |
||
| 7 | use Symfony\Component\Routing\Loader\PhpFileLoader; |
||
| 8 | |||
| 9 | /** |
||
| 10 | * Trait LoaderTrait |
||
| 11 | * @package Nip\Router\ServiceProvider\Traits |
||
| 12 | */ |
||
| 13 | trait LoaderTrait |
||
| 14 | { |
||
| 15 | 3 | public function registerLoader() |
|
| 16 | { |
||
| 17 | $this->getContainer()->share('routing.loader', function () { |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 18 | 3 | return $this->createLoader(); |
|
| 19 | 3 | }); |
|
| 20 | 3 | } |
|
| 21 | |||
| 22 | /** |
||
| 23 | * @return \Symfony\Component\Config\Loader\DelegatingLoader |
||
| 24 | */ |
||
| 25 | 3 | protected function createLoader() |
|
| 26 | { |
||
| 27 | 3 | $app = $this->getContainer()->get('app'); |
|
| 28 | |||
| 29 | 3 | $locator = new FileLocator([ |
|
| 30 | 3 | $app->basePath() . DIRECTORY_SEPARATOR . 'routes', |
|
| 31 | 3 | $app->path(), |
|
| 32 | 3 | $app->basePath(), |
|
| 33 | ]); |
||
| 34 | |||
| 35 | 3 | $resolver = new \Symfony\Component\Config\Loader\LoaderResolver(); |
|
| 36 | 3 | $resolver->addLoader(new PhpFileLoader($locator)); |
|
| 37 | 3 | $resolver->addLoader(new DirectoryLoader($locator)); |
|
| 38 | |||
| 39 | 3 | $loader = new \Nip\Router\Loader\DelegatingLoader($resolver); |
|
| 40 | |||
| 41 | 3 | return $loader; |
|
| 42 | } |
||
| 43 | } |
||
| 44 |