diff --git a/config/autoload/dependencies.global.php b/config/autoload/dependencies.global.php index 4777cd7..dbdd08e 100644 --- a/config/autoload/dependencies.global.php +++ b/config/autoload/dependencies.global.php @@ -1,5 +1,6 @@ [ // Fully\Qualified\InterfaceName::class => Fully\Qualified\ClassName::class, - Helper\ServerUrlHelper::class => Helper\ServerUrlHelper::class, ], // Use 'factories' for services provided by callbacks/factory classes. 'factories' => [ Application::class => Container\ApplicationFactory::class, Delegate\NotFoundDelegate::class => Container\NotFoundDelegateFactory::class, + Helper\ServerUrlHelper::class => AppHelper\ServerUrlHelperFactory::class, Helper\ServerUrlMiddleware::class => Helper\ServerUrlMiddlewareFactory::class, Helper\UrlHelper::class => Helper\UrlHelperFactory::class, Helper\UrlHelperMiddleware::class => Helper\UrlHelperMiddlewareFactory::class, diff --git a/config/autoload/los-basepath.global.php.dist b/config/autoload/los-basepath.global.php.dist index f6070fa..887f24a 100644 --- a/config/autoload/los-basepath.global.php.dist +++ b/config/autoload/los-basepath.global.php.dist @@ -1,21 +1,10 @@ '/cps', - 'dependencies' => [ 'factories' => [ LosMiddleware\BasePath\BasePath::class => LosMiddleware\BasePath\BasePathFactory::class, ], ], - - 'middleware_pipeline' => [ - 'always' => [ - 'middleware' => [ - LosMiddleware\BasePath\BasePath::class - ], - ], - ], - ]; diff --git a/config/pipeline.php b/config/pipeline.php index 1e69a67..988ea80 100644 --- a/config/pipeline.php +++ b/config/pipeline.php @@ -17,6 +17,7 @@ use Zend\Stratigility\Middleware\ErrorHandler; // all Exceptions. $app->pipe(ErrorHandler::class); $app->pipe(ServerUrlMiddleware::class); +$app->pipe(LosMiddleware\BasePath\BasePath::class); // Pipe more middleware here that you want to execute on every request: // - bootstrapping diff --git a/src/App/Helper/ServerUrlHelperFactory.php b/src/App/Helper/ServerUrlHelperFactory.php new file mode 100644 index 0000000..6a978fa --- /dev/null +++ b/src/App/Helper/ServerUrlHelperFactory.php @@ -0,0 +1,34 @@ +get('config'); + $path = array_key_exists('los_basepath', $config) && !empty($config['los_basepath']) + ? $config['los_basepath'] + : null; + + $serverUrlHelper = new ServerUrlHelper(); + if ($path) { + $uri = (new Uri())->withPath($path); + $serverUrlHelper->setUri($uri); + } + return $serverUrlHelper; + } +}