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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'hotfix/routeresult-observer'
Close #9
- Loading branch information
Showing
9 changed files
with
168 additions
and
2 deletions.
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
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