1.0.0
2019-08-12 00:45 UTC
Requires
- php: ^7.0
- zendframework/zend-stdlib: ^3.1.0
Requires (Dev)
- phpunit/phpunit: ^6.3
This package is auto-updated.
Last update: 2020-03-06 21:08:42 UTC
README
Zend Expressive 路由和管道加载器
目的
当在Zend Expressive上构建中到大型应用时,如果你能组织你的路由会更好。默认情况下,expressive在config
目录下的routes.php
文件中定义所有路由。对我而言,最好是至少按路由前缀模块组织路由。例如,routes.web.php
用于所有Web路由,而routes.api.php
用于所有API路由。
用法
$ composer require adrosoftware/zerp-loader
默认情况下,public/index.php
文件看起来像这样:
<?php declare(strict_types=1); // Delegate static file requests back to the PHP built-in webserver if (PHP_SAPI === 'cli-server' && $_SERVER['SCRIPT_FILENAME'] !== __FILE__) { return false; } chdir(dirname(__DIR__)); require 'vendor/autoload.php'; /** * Self-called anonymous function that creates its own scope and keep the global namespace clean. */ (function () { /** @var \Psr\Container\ContainerInterface $container */ $container = require 'config/container.php'; /** @var \Zend\Expressive\Application $app */ $app = $container->get(\Zend\Expressive\Application::class); $factory = $container->get(\Zend\Expressive\MiddlewareFactory::class); // Execute programmatic/declarative middleware pipeline and routing // configuration statements (require 'config/pipeline.php')($app, $factory, $container); (require 'config/routes.php')($app, $factory, $container); $app->run(); })();
假设你有config/routes.web.php
和config/routes.api.php
等,然后替换为以下内容:
(require 'config/routes.php')($app, $factory, $container);
如下所示:
(new \AdroSoftware\Zerp\Loader('config/routes.*.php'))->load($app, $factory, $container);