此包已被废弃且不再维护。作者建议使用https://github.com/adrosoftware/lmrp-loader包。

Zend Expressive 辅助类,用于加载路由文件和管道。

1.0.0 2019-08-12 00:45 UTC

This package is auto-updated.

Last update: 2020-03-06 21:08:42 UTC


README

自从Zend迁移到Laminas后,现在我为Mezzio创建了一个新的

Zend Expressive 路由和管道加载器

Build status Coverage Status Latest Stable Version License

目的

当在Zend Expressive上构建中到大型应用时,如果你能组织你的路由会更好。默认情况下,expressiveconfig目录下的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.phpconfig/routes.api.php等,然后替换为以下内容:

(require 'config/routes.php')($app, $factory, $container);

如下所示:

(new \AdroSoftware\Zerp\Loader('config/routes.*.php'))->load($app, $factory, $container);

作者

Adro Rocker.