froschdesign / zend-expressive-navigation

Page, middleware and factories for navigations in a zend-expressive application
BSD 3-Clause "New" or "Revised" License
5 stars 5 forks source link

Exceptions with multiple navigations in config #3

Open av3 opened 6 years ago

av3 commented 6 years ago

Hello froschdesign,

currently I have a project where I use the "old" https://github.com/froschdesign/zend-navigation/tree/feature/expressive-support for using Zend-Navigation with multiple navigations in Expressive.

Because I wanted to switch to Zend Expressive 3 (which isn't compatible to the old branch), I wanted to switch to this zend-expressive-navigation and already tested the newest version with your quickstart description.

If I have only one "default" key in my configuration array, everything works fine. But if I add a "footer" key (with an empty array, without pages), I get an error message (also without trying to call the view helper for that navigation):

Zend \ ServiceManager \ Exception \ ServiceNotCreatedException

Service with name "Zend\Navigation\Footer" could not be created. Reason: Invalid argument: Unable to determine class to instantiate

In my ConfigAggregator I have

    \Zend\Navigation\ZendView\ConfigProvider::class,
    \Zend\Expressive\Navigation\ConfigProvider::class,

This was the first error without any pages; if the default key has an empty array as value, there is no error, just an empty navigation output.

Then I added a page to my footer array. Example:

            'default' => [
                [

                    'type' => \Zend\Expressive\Navigation\Page\ExpressivePage::class,
                    'label' => 'Startseite',
                    'route' => 'home',
                ]
            ],
            'footer' => [
                [

                    'type' => \Zend\Expressive\Navigation\Page\ExpressivePage::class,
                    'label' => 'Startseite',
                    'route' => 'home',
                ]
            ]

No I get the another exception:

Whoops \ Exception \ ErrorException (E_ERROR) Method Zend\View\Helper\Navigation\Menu::__toString() must not throw an exception, caught TypeError: Argument 1 passed to Zend\Expressive\Helper\UrlHelper::setRouteResult() must be an instance of Zend\Expressive\Router\RouteResult, null given, called in /application/vendor/zendframework/zend-expressive-navigation/src/Page/ExpressivePage.php on line 92

froschdesign commented 6 years ago

Right, this is a bug. A workaround:

'abstract_factories' => [
    \Zend\Expressive\Navigation\Service\ExpressiveNavigationAbstractServiceFactory::class,
],
'aliases'            => [
    'navigation' => \Zend\Navigation\Navigation::class,
],
'factories'          => [
    Zend\Expressive\Navigation\Middleware\NavigationMiddleware::class => Zend\Expressive\Navigation\Middleware\NavigationMiddlewareFactory::class,
],

(without the factory ExpressiveNavigationFactory)

av3 commented 6 years ago

Thank you! Then I have to use Zend\Navigation\Footer for the view helper (even if I use 'footer' with a small f for the key) and I'm getting my footer navigation. :)

froschdesign commented 5 years ago

The current idea is to remove the ExpressiveNavigationFactory because the abstract factory (ExpressiveNavigationAbstractServiceFactory) can do all the work with the same result.

I have already written some unit tests but some tests in an application are required.