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

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
blanchonvincent committed Dec 18, 2012
3 parents c36f6c0 + 3ead99d + d4be36e commit 335a3c1
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 4 deletions.
5 changes: 1 addition & 4 deletions src/AbstractPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ abstract class AbstractPluginManager extends ServiceManager implements ServiceLo
*
* @var bool
*/
protected $allowOverride = true;
protected $allowOverride = true;

/**
* Whether or not to auto-add a class as an invokable class if it exists
Expand Down Expand Up @@ -69,9 +69,6 @@ public function __construct(ConfigInterface $configuration = null)
if ($instance instanceof ServiceLocatorAwareInterface) {
$instance->setServiceLocator($self);
}
if ($instance instanceof ServiceManagerAwareInterface) {
$instance->setServiceManager($self);
}
});
}

Expand Down
48 changes: 48 additions & 0 deletions src/ServiceLocatorAwareTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_ServiceManager
*/

namespace Zend\ServiceManager;

use Zend\ServiceManager\ServiceLocatorInterface;

/**
* @category Zend
* @package Zend_ServiceManager
*/
trait ServiceLocatorAwareTrait
{
/**
* @var ServiceLocator
*/
protected $serviceLocator = null;

/**
* Set service locator
*
* @param ServiceLocatorInterface $serviceLocator
* @return mixed
*/
public function setServiceLocator(ServiceLocatorInterface $serviceLocator)
{
$this->serviceLocator = $serviceLocator;

return $this;
}

/**
* Get service locator
*
* @return ServiceLocator
*/
public function getServiceLocator()
{
return $this->serviceLocator;
}
}
46 changes: 46 additions & 0 deletions test/ServiceLocatorAwareTraitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 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;

use \PHPUnit_Framework_TestCase as TestCase;
use \Zend\ServiceManager\ServiceManager;

/**
* @requires PHP 5.4
*/
class ServiceLocatorAwareTraitTest extends TestCase
{
public function testSetServiceLocator()
{
$object = $this->getObjectForTrait('\Zend\ServiceManager\ServiceLocatorAwareTrait');

$this->assertAttributeEquals(null, 'serviceLocator', $object);

$serviceLocator = new ServiceManager;

$object->setServiceLocator($serviceLocator);

$this->assertAttributeEquals($serviceLocator, 'serviceLocator', $object);
}

public function testGetServiceLocator()
{
$object = $this->getObjectForTrait('\Zend\ServiceManager\ServiceLocatorAwareTrait');

$this->assertNull($object->getServiceLocator());

$serviceLocator = new ServiceManager;

$object->setServiceLocator($serviceLocator);

$this->assertEquals($serviceLocator, $object->getServiceLocator());
}
}

0 comments on commit 335a3c1

Please sign in to comment.