Hello,
I’m currently migrating from old zend framework to laminas.
I have been lead to use laminas-router.
Since i installed the library in version 3.4.4 (latest stable if i’m not wrong), I have been having the following warning:
PHP Warning: preg_match(): No ending matching delimiter ‘)’ found in /path-to-vendors /vendor/laminas/laminas-router/src/Http/Hostname.php on line 298
I went to check the line here is what i found:
$result = preg_match('(^' . $this->regex . '$)', $host, $matches);
Any idea on how to remove those warning?
Thank you very much
Hello and welcome to our forums!
Can you provide the related route definition for the Hostname route? This will help to reproduce the problem. Thanks!
And please check the following if there are errors:
$route = new Laminas\Router\Http\Hostname('example.com');
$request = new Laminas\Http\Request();
$request->setUri('http://example.com');
var_dump($route->match($request)); // Laminas\Router\Http\RouteMatch
$request->setUri('http://example.de');
var_dump($route->match($request)); // null
Hello thank you for welcoming me.
How can i find or provide you the route definition?
I tested what you asked.
I used a print of get_class instead of var_dump but i think it doesnt matter.
get_class($route->match($request))
This part:
$request->setUri(‘http://example.com ’);
var_dump($route->match($request));
Returned an object of class Laminas\Router\Http\RouteMatch
This part:
$request->setUri(‘http://example.de ’);
var_dump($route->match($request));
Returned null
So no Error in the end. My message is about a warning that doesn’t really make php bug.
If your application is based on laminas-mvc and you have followed the standard directory structure, then it is defined in the configuration. For example in the file /modules/Application/config/module.config.php
:
'router' => [
'routes' => [
'home' => [
'type' => Literal::class,
'options' => [
'route' => '/',
'defaults' => [
'controller' => Controller\IndexController::class,
'action' => 'index',
],
],
],
'application' => [
'type' => Segment::class,
'options' => [
'route' => '/application[/:action]',
'defaults' => [
'controller' => Controller\IndexController::class,
'action' => 'index',
],
This file has been truncated. show original
See also the documentation or the getting started tutorial:
Ok i see which part you mean.
Sadly i got 7 modules with a tone of routes and childroutes.
Those routes contains quite sensitive structural information about my application.
Anything in particular you want to check?
'router' => [
'routes' => [
'application' => [
'type' => Hostname::class,
'options' => [
'route' => '[:fulldomain]',
'constraints' => [
'fulldomain' => 'application.*'
],
'defaults' => [
'__NAMESPACE__' => 'Application\Controller',
'controller' => 'Index',
'action' => 'index',
],
],
'may_terminate' => true,
'child_routes' => [ ....... Lots of child routes ... ]],
],
],
It is an anonymized subset of the routing system i was testing.
Thank you again for your help.
The error message comes from the Hostname route, so all of these should be checked. This means we need all entries with the type Laminas\Router\Http\Hostname::class
.
The route from your code example works:
$route = new Laminas\Router\Http\Hostname(
'[:fulldomain]',
[
'fulldomain' => 'application.*',
]
);
$request = new Laminas\Http\Request();
$request->setUri('http://application.example.com');
var_dump($route->match($request)); // Laminas\Router\Http\RouteMatch
$request->setUri('http://application.com');
var_dump($route->match($request)); // Laminas\Router\Http\RouteMatch
$request->setUri('http://application.com/album/list');
var_dump($route->match($request)); // Laminas\Router\Http\RouteMatch
You can use a debugger that shows the current values when the error message occurs.