This repository has been archived by the owner on Jan 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Implement RouteResultObserverInterface #9
Merged
weierophinney
merged 2 commits into
zendframework:master
from
weierophinney:hotfix/routeresult-observer
Dec 2, 2015
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @see https://github.com/zendframework/zend-expressive for the canonical source repository | ||
* @copyright Copyright (c) 2015 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license https://github.com/zendframework/zend-expressive/blob/master/LICENSE.md New BSD License | ||
*/ | ||
|
||
namespace Zend\Expressive\ZendView; | ||
|
||
use Zend\ServiceManager\DelegatorFactoryInterface; | ||
use Zend\ServiceManager\ServiceLocatorInterface; | ||
|
||
class ApplicationUrlDelegatorFactory implements DelegatorFactoryInterface | ||
{ | ||
/** | ||
* Inject the UrlHelper in an Application instance, when available. | ||
* | ||
* @param ServiceLocatorInterface $container | ||
* @param string $name | ||
* @param string $requestedName | ||
* @param callable $callback Callback that returns the Application instance | ||
*/ | ||
public function createDelegatorWithName(ServiceLocatorInterface $container, $name, $requestedName, $callback) | ||
{ | ||
$application = $callback(); | ||
if ($container->has(UrlHelper::class)) { | ||
$application->attachRouteResultObserver($container->get(UrlHelper::class)); | ||
} | ||
return $application; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @see https://github.com/zendframework/zend-expressive for the canonical source repository | ||
* @copyright Copyright (c) 2015 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license https://github.com/zendframework/zend-expressive/blob/master/LICENSE.md New BSD License | ||
*/ | ||
|
||
namespace Zend\Expressive\ZendView; | ||
|
||
use Interop\Container\ContainerInterface; | ||
use Zend\Expressive\Router\RouterInterface; | ||
|
||
class UrlHelperFactory | ||
{ | ||
/** | ||
* Create a UrlHelper instance. | ||
* | ||
* @param ContainerInterface $container | ||
* @return UrlHelper | ||
*/ | ||
public function __invoke(ContainerInterface $container) | ||
{ | ||
return new UrlHelper($container->get(RouterInterface::class)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @see https://github.com/zendframework/zend-expressive for the canonical source repository | ||
* @copyright Copyright (c) 2015 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license https://github.com/zendframework/zend-expressive/blob/master/LICENSE.md New BSD License | ||
*/ | ||
|
||
namespace ZendTest\Expressive\ZendView; | ||
|
||
use PHPUnit_Framework_TestCase as TestCase; | ||
use Zend\Expressive\Application; | ||
use Zend\Expressive\ZendView\ApplicationUrlDelegatorFactory; | ||
use Zend\Expressive\ZendView\UrlHelper; | ||
use Zend\ServiceManager\ServiceLocatorInterface; | ||
|
||
class ApplicationUrlDelegatorFactoryTest extends TestCase | ||
{ | ||
public function testDelegatorRegistersUrlHelperAsRouteResultObserverWithApplication() | ||
{ | ||
$urlHelper = $this->prophesize(UrlHelper::class); | ||
$application = $this->prophesize(Application::class); | ||
$application->attachRouteResultObserver($urlHelper->reveal())->shouldBeCalled(); | ||
$applicationCallback = function () use ($application) { | ||
return $application->reveal(); | ||
}; | ||
|
||
$container = $this->prophesize(ServiceLocatorInterface::class); | ||
$container->has(UrlHelper::class)->willReturn(true); | ||
$container->get(UrlHelper::class)->willReturn($urlHelper->reveal()); | ||
|
||
$delegator = new ApplicationUrlDelegatorFactory(); | ||
$test = $delegator->createDelegatorWithName( | ||
$container->reveal(), | ||
Application::class, | ||
Application::class, | ||
$applicationCallback | ||
); | ||
$this->assertSame($application->reveal(), $test); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my assumption is this may be problematic when zend-expressive need to download zendviewrenderer. But I am not exactly sure if this will work without minimum-stability flag in expressive. How about you add minimum-stability dev to the composer.json and keep the rest in tact ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will essentially grab dev-master always. I think instead I'm going to tag the zend-expressive repo, and then update this one to the latest tag.
I understand why everyone wanted to separate out the implementations, but while we're not stable, this is a nightmare to maintain the dependencies!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes only for this repo. But you can change later :) .
and I can understand the pain. There should be some sort of scripts to do automatic releases and tagging when we have many repos.