This repository has been archived by the owner on Jan 8, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4145 from Ocramius/feature/eager-services
Delegate factories
- Loading branch information
Showing
5 changed files
with
226 additions
and
5 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,28 @@ | |||
<?php | |||
/** | |||
* Zend Framework (http://framework.zend.com/) | |||
* | |||
* @link http://github.com/zendframework/zf2 for the canonical source repository | |||
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) | |||
* @license http://framework.zend.com/license/new-bsd New BSD License | |||
*/ | |||
|
|||
namespace Zend\ServiceManager; | |||
|
|||
/** | |||
* Interface for factories that can create delegators for services | |||
*/ | |||
interface DelegatorFactoryInterface | |||
{ | |||
/** | |||
* A factory that creates delegators of a given service | |||
* | |||
* @param ServiceLocatorInterface $serviceLocator the service locator which requested the service | |||
* @param string $name the normalized service name | |||
* @param string $requestedName the requested service name | |||
* @param callable $callback the callback that is responsible for creating the service | |||
* | |||
* @return mixed | |||
*/ | |||
public function createDelegatorWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName, $callback); | |||
} |
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
35 changes: 35 additions & 0 deletions
35
tests/ZendTest/ServiceManager/TestAsset/MockSelfReturningDelegatorFactory.php
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,35 @@ | |||
<?php | |||
/** | |||
* Zend Framework (http://framework.zend.com/) | |||
* | |||
* @link http://github.com/zendframework/zf2 for the canonical source repository | |||
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) | |||
* @license http://framework.zend.com/license/new-bsd New BSD License | |||
* @package Zend_ServiceManager | |||
*/ | |||
|
|||
namespace ZendTest\ServiceManager\TestAsset; | |||
|
|||
use Zend\ServiceManager\DelegatorFactoryInterface; | |||
use Zend\ServiceManager\ServiceLocatorInterface; | |||
|
|||
/** | |||
* Mock factory that logs delegated service instances and returns itself instead of the original service | |||
*/ | |||
class MockSelfReturningDelegatorFactory implements DelegatorFactoryInterface | |||
{ | |||
/** | |||
* @var mixed[] | |||
*/ | |||
public $instances = array(); | |||
|
|||
/** | |||
* {@inheritDoc} | |||
*/ | |||
public function createDelegatorWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName, $callback) | |||
{ | |||
$this->instances[] = call_user_func($callback); | |||
|
|||
return $this; | |||
} | |||
} |