mtymek / blast-base-url Goto Github PK
View Code? Open in Web Editor NEWPSR-7 middleware and helpers for working with base URL.
PSR-7 middleware and helpers for working with base URL.
in BasePathViewHelperFactory.php
Interop\Container\ContainerInterface does not define a getServiceLocator() method, this is defined in zend view helper plugin manager
My happy path goes through here and as such basePath is '/' when I think it should be ''. (Well it works when I define it as ''.) Not sure if I am doing it wrong?
I now always get a 404 for any uri other then the homepage.
After updating Mezzio to its latest Version (3.9), it appears that the mapping between the outdated (Zend) and the current (Laminas) namespaces has been removed. My project doesn't bootstrap anymore with the following error being reported:
PHP Fatal error: Uncaught Laminas\ServiceManager\Exception\ServiceNotFoundException: Unable to resolve service "Blast\BaseUrl\BasePathHelper" to a factory; are you certain you provided it during configuration?
I managed to work around this by changing use Zend\ServiceManager\Factory\InvokableFactory;
to use Laminas\ServiceManager\Factory\InvokableFactory;
in \Blast\BaseUrl\ConfigProvider.
I guess it would make sense though to update the composer package appropriately so that everything works out of the box.
Hello,
I have followed the cookbook guide relative to use zend expressive on subdirectory. And the default homepage action works fine. I'm using the expressive skeleton.
Unfortunately I'm unable to make this work as i receive the following error:
Catchable fatal error: Argument 1 passed to Zend\Expressive\Helper\UrlHelperMiddleware::__construct() must be an instance of Zend\Expressive\Helper\UrlHelper, none given, called in /home/ubuntu/workspace/vendor/zendframework/zend-expressive/src/MarshalMiddlewareTrait.php on line 124 and defined in /home/ubuntu/workspace/vendor/zendframework/zend-expressive-helpers/src/UrlHelperMiddleware.php on line 27
This is my dependencies config file:
<?php
use Zend\Expressive\Application;
use Zend\Expressive\Container\ApplicationFactory;
use Zend\Expressive\Helper;
return [
// Provides application-wide services.
// We recommend using fully-qualified class names whenever possible as
// service names.
'dependencies' => [
// Use 'invokables' for constructor-less services, or services that do
// not require arguments to the constructor. Map a service name to the
// class name.
'invokables' => [
// Fully\Qualified\InterfaceName::class => Fully\Qualified\ClassName::class,
Helper\ServerUrlHelper::class => Helper\ServerUrlHelper::class,
Blast\BaseUrl\BasePathHelper::class => Blast\BaseUrl\BasePathHelper::class,
],
// Use 'factories' for services provided by callbacks/factory classes.
'factories' => [
Application::class => ApplicationFactory::class,
Doctrine\DBAL\DriverManager::class => App\Catalog\Factory\DoctrineDbalConnectionFactory::class,
Blast\BaseUrl\UrlHelper::class => Blast\BaseUrl\UrlHelperFactory::class,
App\Catalog\Config\ConfigDbMiddleware::class => App\Catalog\Factory\ConfigDbMiddlewareFactory::class,
bitExpert\Http\Middleware\Psr7\Prophiler\ProphilerMiddleware::class => App\Catalog\Factory\ProphilerFactory::class,
App\Catalog\Http\UserAgentMiddleware::class => App\Catalog\Factory\UserAgentMiddlewareFactory::class,
App\Catalog\Log\LogMiddleware::class => App\Catalog\Factory\LogMiddlewareFactory::class,
App\Catalog\Http\SessionMiddleware::class => App\Catalog\Factory\SessionMiddlewareFactory::class,
App\Catalog\Http\SessionHandlerMiddleware::class => App\Catalog\Factory\SessionHandlerFactory::class,
Aura\Session\Session::class => App\Catalog\Factory\AuraSessionFactory::class,
Doctrine\ORM\EntityManager::class => App\Catalog\Factory\DoctrineFactory::class,
Doctrine\Common\Cache\Cache::class => App\Catalog\Factory\DoctrineFileCacheFactory::class,
App\Catalog\i18n\LanguageMiddleware::class => App\Catalog\Factory\LanguageMiddlewareFactory::class,
App\Catalog\Mail\MailMiddleware::class => App\Catalog\Factory\MailMiddlewareFactory::class,
],
'aliases' => [
// alias default UrlHelper with Blast\BaseUrl alternative
Helper\UrlHelper::class => Blast\BaseUrl\UrlHelper::class,
],
],
];
And this the middleware pipeline
<?php
use Zend\Expressive\Container\ApplicationFactory;
use Zend\Expressive\Helper;
use Zend\Expressive\App;
return [
'dependencies' => [
'invokables' => [
/* ... */
],
'factories' => [
Helper\ServerUrlMiddleware::class => Helper\ServerUrlMiddlewareFactory::class,
// Helper\UrlHelperMiddleware::class => Helper\UrlHelperMiddlewareFactory::class,
Helper\UrlHelper::class => Helper\UrlHelperFactory::class,
Blast\BaseUrl\BaseUrlMiddleware::class => Blast\BaseUrl\BaseUrlMiddlewareFactory::class,
],
],
// This can be used to seed pre- and/or post-routing middleware
'middleware_pipeline' => [
// An array of middleware to register. Each item is of the following
// specification:
//
// [
// Required:
// 'middleware' => 'Name or array of names of middleware services and/or callables',
// Optional:
// 'path' => '/path/to/match', // string; literal path prefix to match
// // middleware will not execute
// // if path does not match!
// 'error' => true, // boolean; true for error middleware
// 'priority' => 1, // int; higher values == register early;
// // lower/negative == register last;
// // default is 1, if none is provided.
// ],
//
// While the ApplicationFactory ignores the keys associated with
// specifications, they can be used to allow merging related values
// defined in multiple configuration files/locations. This file defines
// some conventional keys for middleware to execute early, routing
// middleware, and error middleware.
'always' => [
'middleware' => [
// Add more middleware here that you want to execute on
// every request:
// - bootstrapping
// - pre-conditions
// - modifications to outgoing responses
Helper\ServerUrlMiddleware::class,
Blast\BaseUrl\BaseUrlMiddleware::class,
bitExpert\Http\Middleware\Psr7\Prophiler\ProphilerMiddleware::class,
\App\Catalog\Config\ConfigDbMiddleware::class,
\App\Catalog\Http\SessionHandlerMiddleware::class,
\App\Catalog\Http\UserAgentMiddleware::class,
\App\Catalog\Http\SessionMiddleware::class,
],
'priority' => 10000,
],
'routing' => [
'middleware' => [
ApplicationFactory::ROUTING_MIDDLEWARE,
// Add more middleware here that needs to introspect the routing
// results; this might include:
// - route-based authentication
// - route-based validation
// - etc.
Helper\UrlHelperMiddleware::class,
\App\Catalog\i18n\LanguageMiddleware::class,
ApplicationFactory::DISPATCH_MIDDLEWARE,
],
'priority' => 1,
],
'error' => [
'middleware' => [
\App\Catalog\Log\LogMiddleware::class,
],
'error' => true,
'priority' => -10000,
],
],
];
Is it possible to get full URL like http://url-site.com/
I am using it in Expressive app and need full URL to share page on social media like facebook.
For eg.
// this should return http://url-site.com/share-page-facebook
$this->basePath('/share-page-to-facebook');
This lib asks for a Container Interop package, yet it isn't defined in your composer.json, so the Middleware factory breaks.
Also, shouldn't that be replaced with the PSR-11 interfaces?
https://github.com/mtymek/blast-base-url/blob/master/src/BaseUrlMiddlewareFactory.php#L5
(...this is in some way related to the discussion about the helper factory)
Since you are using zend-view (which includes its own helper), we could just use the zend-view BasePath view helper and just call setBasePath on it without having a custom view helper which basically does the same.
i tried it and it works just fine (zend-servicemanager3), see following code fragments:
//...
use Zend\View\HelperPluginManager;
use Zend\View\Helper\BasePath;
//...
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
{
//...
if ($this->container->has(HelperPluginManager::class)) {
$manager = $this->container->get(HelperPluginManager::class);
if ($manager->has(BasePath::class)) {
$helper = $manager->get(BasePath::class);
$helper->setBasePath($this->basePath . '/');
}
}
//...
return $next($request, $response);
}
you can close the issue of course since it's not an issue :-)
kind regards
Hi Mateusz,
Thank you for your pointers in my expressive issue. When updating my project from the cookbook, I ran into trouble. Aparantly I did something wrong in creating the pointer to the factory. I include the configuration file "middleware-pipeline.global.php". I am new to zend, so I could easily have misinterpreted the instructions. If you need more info, just let me know. Apart from the instructions in the cookbook, the project is the expressive-skeleton.
Could you have a look?
At the moment, it supports by default "only" Zend View, would it be possible to also support Zend Expressive Twig Renderer through ConfigProvider.php
?
Thanks a lot :)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.