Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Added zend-expressive support - fixes #56 #61

Conversation

froschdesign
Copy link
Member

@froschdesign froschdesign commented Mar 10, 2017

This proposal does not change existing classes of the component, because I wanted an implementation for version 2 of zend-navigation.

Caution

This PR based on PHPUnit 5.7 || 6.0! See: #59

ping @weierophinney @RalfEggert @webimpress

@froschdesign
Copy link
Member Author

froschdesign commented Mar 10, 2017

Usage for a single container

dependencies.global.php

'dependencies' => [
    'factories'  => [
        Zend\Navigation\Navigation::class =>
            Zend\Navigation\Service\ExpressiveNavigationFactory::class,
    ],
    'delegators' => [
        Zend\View\HelperPluginManager::class => [
            Zend\Navigation\View\ViewHelperManagerDelegatorFactory::class,
        ],
    ],
    'factories' => [
        Zend\Navigation\Middleware\NavigationMiddleware::class =>
            Zend\Navigation\Middleware\NavigationMiddlewareFactory::class,
    ],
],

pipeline.php

$app->pipeRoutingMiddleware();
// …
$app->pipe(Zend\Navigation\Middleware\NavigationMiddleware::class);
// …
$app->pipeDispatchMiddleware();

Usage for multiple containers

dependencies.global.php

'dependencies' => [
    'abstract_factories' => [
        Zend\Navigation\Service\ExpressiveNavigationAbstractServiceFactory::class,
    ],
],

Notice

Do not use the ConfigProvider class, because at the moment the ConfigProvider only includes the configuration for zend-mvc-based applications!

composer.json Outdated
"zendframework/zend-log": "^2.7.1",
"zendframework/zend-mvc": "^2.7.9 || ^3.0",
"zendframework/zend-router": "^3.0",
"zendframework/zend-config": "^3.1",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we have here also 2.6 version?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but this is related to #59. I will this fixed there.

@froschdesign
Copy link
Member Author

@webimpress
Can you look at the Middleware? Thanks!

@@ -0,0 +1,69 @@
<?php

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing license header

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

use Zend\Navigation\AbstractContainer;
use Zend\Navigation\Exception;
use Zend\Navigation\Page\ExpressivePage;
use Zend\Expressive\Router\RouteResult;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use alphabetical order of use statements.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

if (! $container instanceof AbstractContainer) {
throw new Exception\InvalidArgumentException(
'Invalid argument: container must be an instance of '
. 'Zend\Navigation\AbstractContainer'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd use ::class here and sprintf.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -0,0 +1,83 @@
<?php

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing license header.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

/**
* Top-level configuration key indicating navigation configuration
*
* @var string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we use @const instead of @var for constants?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

phpDocumentor

@const is not documented and supported.

PHP-Fig

You may use the @var tag to document the "Type" of the following "Structural Elements":

  • Constants, both class and global scope
  • Properties
  • Variables, both global and local scope

https://github.com/php-fig/fig-standards/blob/master/proposed/phpdoc.md#722-var

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok fine. Please just note it is proposed standard, not yet accepted. It's a bit odd that constant has annotation variable, isn't it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please just note it is proposed standard, not yet accepted.

Right, therefore the hint to phpDocumentor. 😉
As far as I know, APiGen does the same like phpDocumentor.

It's a bit odd that constant has annotation variable, isn't it?

I do not know where comes from. But, if it is not supported, why should we use that? And if we follow the PSR-5 proposal, than the "type" of the value should be described, not the element itself.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@webimpress It's been this way forever in both phpDocumentor (which predates PSR-5 by 15 years; PSR-5 is largely an attempt to codify what phpDocumentor has been doing all along) and in IDE support; it's the only supported, recognized way of annotating constants. No tools recognize @const, unfortunately.

public function testGetHref()
{
$page = new ExpressivePage(
[
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can move it to line above, and then content can have one less indent and closing bracket could be with );

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • I can't find any documentation for this case.
  • PHPStorm does the same formatting. 😉

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


AbstractPage::factory([
'type' => 'ZendTest\Navigation\TestAsset\InvalidPage',
'label' => 'My Invalid Page'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add trailing comma.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is related to #59

);

AbstractPage::factory([
'label' => 'My Invalid Page'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add trailing comma.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is related to #59

@@ -0,0 +1,89 @@
<?php

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing license header.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -0,0 +1,106 @@
<?php

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing license header.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

<?php
/**
* @see https://github.com/zendframework/zend-navigation for the canonical source repository
* @copyright Copyright (c) 2016-2017 Zend Technologies USA Inc. (http://www.zend.com)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it it new file, we should have here just 2017 year.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

use Interop\Http\ServerMiddleware\DelegateInterface;
use Interop\Http\ServerMiddleware\MiddlewareInterface;
use RecursiveIteratorIterator;
use Psr\Http\Message\ServerRequestInterface;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use alphabetical order here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

/**
* @var AbstractContainer[]
*/
private $containers;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have here default value []?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

* @param ServerRequestInterface $request
* @param DelegateInterface $delegate
* @return \Psr\Http\Message\ResponseInterface
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use here @inheritDoc instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


public function testGetHrefSetsHrefCache()
{

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove above empty line.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}

/**
* @inheritdoc
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix camel case, it should be @inheritDoc.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -0,0 +1,128 @@
<?php

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still can't see it.

@@ -0,0 +1,65 @@
<?php

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing license header in the file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

<?php
/**
* @see https://github.com/zendframework/zend-navigation for the canonical source repository
* @copyright Copyright (c) 2016-2017 Zend Technologies USA Inc. (http://www.zend.com)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it is new file, please update year to 2017 only.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@froschdesign
Copy link
Member Author

ping @weierophinney

@froschdesign
Copy link
Member Author

@weierophinney @RalfEggert

My suggestion for a release:

  • zend-navigation 2.9
  • zend-expressive-navigation 1.0

Later than:

  • zend-navigation 3.0
  • zend-expressive-navigation 2.0
  • zend-mvc-navigation 1.0

@RalfEggert
Copy link
Contributor

👍

@weierophinney
Copy link
Member

We can even split out zend-mvc-navigation early, and have it include the Page\Mvc class and all zend-view helpers; if it is registered later than zend-navigation and zend-view in the list of modules, then its own configuration takes precedence.

This would then also allow a 2.X version of zend-navigation to require that particular package in order to keep BC. v3 would remove it as a requirement altogether, and instead make it a suggestion. Similarly, a new 2.X version of zend-view could do the same to ensure we have the navigation helpers available, and v3 would make the package a suggestion instead of a requirement.

@weierophinney
Copy link
Member

@froschdesign If you want to create a new repo extracting the new functionality, I can review and fork it into the zendframework organization when it's ready, and add it to packagist at that time.

@froschdesign
Copy link
Member Author

@weierophinney

We can even split out zend-mvc-navigation early, and have it include the Page\Mvc class and all zend-view helpers

The view helpers in zend-mvc-navigation?!

@weierophinney
Copy link
Member

The view helpers in zend-mvc-navigation?!

Indeed! It's where they really belong. 😀

@froschdesign
Copy link
Member Author

Indeed! It's where they really belong.

And if I will use zend-expressive, then I must also install Page\Mvc?

@mano87
Copy link

mano87 commented Apr 19, 2017

How does it go on?

@weierophinney
Copy link
Member

@froschdesign — sorry for the late response:

And if I will use zend-expressive, then I must also install Page\Mvc?

For now, yes, to retain backwards compatibility. However, for a next major version of this component, we would not need to install the zend-mvc integration package.

@weierophinney
Copy link
Member

@froschdesign I recall you saying you had done the work of separating at least the Expressive support, but I cannot recall where; could you direct me there?

@froschdesign
Copy link
Member Author

@weierophinney
Maybe I misunderstood something, but I think these statements collide:

The view helpers in zend-mvc-navigation?!

Indeed! It's where they really belong.

vs.

However, for a next major version of this component, we would not need to install the zend-mvc integration package.

@froschdesign
Copy link
Member Author

ping @weierophinney

Can we clarify the problem / question from my last comment? Thanks!

@weierophinney
Copy link
Member

@froschdesign

My idea is this:

  • Create a new package, zend-mvc-navigation that depends on zend-navigation, and contains the Zend\Navigation\Page\Mvc class and Zend\Navigation\View subnamespace. Mark it as conflicting with the zend-navigation v2 series (via the composer.json conflicts configuration section).
  • Create a new package, zend-expressive-navigation that depends on zend-navigation with the various integrations for working in zend-expressive. Mark this as working with either the v2 or v3 versions of zend-navigation ("zendframework/zend-navigation": "^2.9 || ^3.0").
  • Create a new minor version (2.9) of zend-navigation that marks the various zend-mvc integrations as deprecated.
  • Create a new major version (3.0) of zend-navigation that removes the zend-mvc integrations (and also bumps the PHP verson to 7.1, removes HHVM support, etc.). This package would suggest the other two packages.

Make sense?

@froschdesign
Copy link
Member Author

@weierophinney

Make sense?

Sorry, not really. If I understand correctly and we will create all these packages, for a zend-expressive application I must install zend-expressive-navigation and zend-mvc-navigation?! (zend-mvc-navigation contains the view helpers a.k.a. Zend\Navigation\View)

@weierophinney
Copy link
Member

Sorry, not really. If I understand correctly and we will create all these packages, for a zend-expressive application I must install zend-expressive-navigation and zend-mvc-navigation?! (zend-mvc-navigation contains the view helpers a.k.a. Zend\Navigation\View)

Okay, that means three packages, then:

  • zend-mvc-navigation for the Mvc page type
  • zend-view-navigation for the view helpers
  • zend-expressive-navigation for the Expressive page type(s)

Expressive users would install zend-navigation and zend-expressive-navigation, and, optionally, zend-view-navigation (depending on their template renderer). zend-mvc users would install zend-navigation, zend-mvc-navigation, and zend-view-navigation.

@mano87
Copy link

mano87 commented Dec 20, 2017

How does it go on here? We would like to use this feature ...

@froschdesign
Copy link
Member Author

froschdesign commented Dec 20, 2017

@mano87

How does it go on here?

Still work in progress. (I have to solve another problem before that.)

We would like to use this feature ...

You can already use this branch: https://github.com/froschdesign/zend-navigation/tree/feature/expressive-support

@ALL
Thanks for your patience!

@throny
Copy link

throny commented Feb 28, 2018

@froschdesign
Thank you for your commitment so far!
Is a new zend-navigation release with expressive (3) support planned yet?

@froschdesign
Copy link
Member Author

@throny

Is a new zend-navigation release with expressive (3) support planned yet?

I hope, but at the moment the priority for the documentation is higher. (see: zendframework/zf-mkdoc-theme#34 – this will help all components!)

@weierophinney weierophinney added this to In progress in Version 3 Apr 25, 2018
@lowtower
Copy link

lowtower commented Aug 2, 2018

Hello,

a long time has gone without any (visible) progress!
Is there any chance to get this working and released anytime?

Cheers

@froschdesign
Copy link
Member Author

@lowtower

a long time has gone without any (visible) progress!

This PR will not be the solution. We will create a separate package / repository for the expressive support and another one for zend-view.
Please have a look at: https://github.com/froschdesign/zend-expressive-navigation

Is there any chance to get this working and released anytime?

The current plan includes an alpha version of zend-navigation-zendview, which can be used with zend-expressive-navigation to output all kind of navigations.
When? At the moment I'm still on vacation.

But you can test the current version of zend-expressive-navigation and leave some comments in the issue tracker. Thanks!

@RalfEggert
Copy link
Contributor

Added a quick-and-dirty quick start to the new component:

froschdesign/zend-expressive-navigation#2

<?php
/**
* @see https://github.com/zendframework/zend-navigation for the canonical source repository
* @copyright Copyright (c) 2017 Zend Technologies USA Inc. (http://www.zend.com)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be 2018?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. 😉

See my comment above:

This PR will not be the solution. We will create a separate package / repository for the expressive support and another one for zend-view.
Please have a look at: https://github.com/froschdesign/zend-expressive-navigation

$containers = [];
foreach ($containerNames as $containerName) {
$containers[] = $container->get($containerName);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May it use array_map?

$containers = array_map([$container, 'get'], $containerNames);

@froschdesign froschdesign removed this from In progress in Version 3 Oct 9, 2018
@froschdesign
Copy link
Member Author

Closing in favour of froschdesign/zend-expressive-navigation (WIP)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants