Giter Club home page Giter Club logo

zend-expressive-zendrouter's Introduction

zend-expressive-zendrouter's People

Contributors

weierophinney avatar michalbundyra avatar geerteltink avatar xerkus avatar koopzington avatar rockstar04 avatar harikt avatar renanbr avatar

Stargazers

Djordje Milojevic avatar Povilas Brilius avatar Saif Eddin Gmati avatar  avatar Rodrigo Quiñones Pichioli avatar Trịnh Dũng avatar Sandro Keil avatar Emanuel Heymann avatar Alejandro Celaya avatar Abdul Malik Ikhsan avatar

Watchers

Pádraic Brady avatar  avatar Ryan Mauger avatar Frank Brückner avatar Marco Pivetta avatar Dranzd Viper avatar Ben Scholzen avatar Enrico Zimuel avatar  avatar Emanuel Heymann avatar James Cloos avatar Ralf Eggert avatar  avatar Marcel avatar  avatar

zend-expressive-zendrouter's Issues

Regex in zend-expressive-zendrouter

Hello,
we will migrate our ZF2 MVC Application to ZF3 Expressive. For some functions we use Regex to build the routes. When can I use Regex in zend-expressive-zendrouter?

For example:

'vcalendar' => [
  'type' => 'regex',
  'options' => [
    'regex' => '/vcalendar/(?<room>[0-9]+)(\.(?<format>(html|ics)))?',
    'defaults' => [
      'action' => 'vcalendar',
      'format' => 'ics'
    ],
    'spec' => '/vcalendar/%room%.%format%',
  ],
],

optional parameters

Hello @weierophinney.

I am still not %100 sure this is the right place for this issue.

As You suggested in : zendframework/zend-expressive#186 (comment) i tried the same route configuration with zend-mvc 2.5.x and 2.6 and it works with both versions.

what i would like to achieve is to be able tu use the UrlHelper to generate urls without the need of specifying empty string parameters for optional (nested) route parameters, as i am able to do in zf2.

a simple test front controller script:

<?php
// composer require zendframework/(zend-mvc|zend-uri);

use Zend\Mvc\Router\Http\TreeRouteStack;

include dirname(__DIR__) . '/vendor/autoload.php';

$router = new TreeRouteStack();

$router->addRoute('user', [
    'type' => 'segment',
    'options' => [
        'route' => 'user[/:action[/:id]]',
//                'defaults' => [
//                    'action' => 'index',
//                ]
    ],
]);

header('Content-Type: text/plain; charset=utf-8');

$params = [];
$uri = $router->assemble($params, [
    'name' => 'user',
]);

echo 'Uri with params=' . json_encode($params) . ' = ' . $uri . "\n";

$params = [
    'action' => 'read',
    'id' => 123,
];
$uri = $router->assemble($params, [
    'name' => 'user',
]);

echo 'Uri with params=' . json_encode($params) . ' = ' . $uri . "\n";

i tried this type of route with the standard module route configuration in full-stack zf2 without 'defaults' option and it works.

when i try to generate routes with expressive UrlHelper ( and with zend-mvc router implementation),
a Zend\Mvc\Router\Exception\InvalidArgumentException is thrown
with message Missing parameter "action" (or "id")

the only way to solve this is to add:

            'options' => [
                'defaults' => [
                    'action' => '',
                    'id' => '',
                ],
            ],

to the route configuration of zend-expressive and use this kind of route definition:
/user[/[:action[/[:id]]]]
to avoid having generated urls with double forward slashes.

The missing parameter exception is raised when a paramater is not set and (!$isOptional || $hasChild).
But since it works with zf2, I believe that it has something to do with the route building process in the zend-router brigde ($hasChild is set to true to this kind of route segment?)

Any clues?

Thanks

Routes from TreeRouterStack supplied in contructor are ignored since 1.3

I just wanted to ask if the following usage is allowed:

$config = [
	'routes' => [
		'test' => [
			'type' => 'Literal', 
			'options' => [
				'route' => '/test',
			]
		]
	],
	'default_params' => [
		'middleware' => 'MyMiddleware',
	],
];

$treeRouter =\Zend\Router\Http\TreeRouteStack::factory($config);
$zendRouter = new \Zend\Expressive\Router\ZendRouter($treeRouter);
$zendRouter->match(/*request to /test */);

Before 1.3 it was working fine, but since 1.3 route matching does not work because Zend\Expressive\Router\ZendRouter::addRoute is not called and this line returns null. And that is a shame because it was reallly convinient to use tree-like configuration via simple custom factory :( .

The Zend Router cannot have routes directly added

This seems to be because of the following change:

https://github.com/zendframework/zend-expressive-zendrouter/pull/12/files#diff-4c16e0300398ea4465dac55ba5fcade3L149

The condition that should never happen is indeed happening for me. This is because $this->routes is empty as all my routes are defined in the injected Zend\Router\Http\TreeRouteStack.

Previously, the result was created from the match and didn't require a route (or middleware).

I'm not sure if I was potentially using this package incorrectly before and it was working by accident. It was very useful when migrating a legacy application that has all its routes defined using the zend style calls.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.