adrosoftware/zerp-loader

This package is abandoned and no longer maintained. The author suggests using the https://github.com/adrosoftware/lmrp-loader package instead.

Zend Expressive helper class to load routes files and pipelines.

1.0.0 2019-08-12 00:45 UTC

This package is auto-updated.

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


README

Since Zend migrated to be Laminas, now I created a new package for Mezzio

Zend Expressive Routes and Pipeline Loader

Build status Coverage Status Latest Stable Version License

Purpose

When building a medium to large applications on Zend Expressive is better if you can organize your routes. By default expressive define all the routes in the routes.php file under the config directory. For me is better if you can at least organize the routes by modules of routes prefix. For example routes.web.php for all the web routes and routes.api.php for al the api routes.

Usage

$ composer require adrosoftware/zerp-loader

The public/index.php file by default look like this:

<?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();
})();

Assuming you have config/routes.web.php and config/routes.api.php and so on, then replace:

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

With something like this:

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

Authors:

Adro Rocker.