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

use PHP 5.5, remove $self = $this #3

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/AbstractPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ public function __construct(ConfigInterface $configuration = null)
{
parent::__construct($configuration);
$self = $this;

Choose a reason for hiding this comment

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

Why you don't remove the line $self = $this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done ;)

$this->addInitializer(function ($instance) use ($self) {
$this->addInitializer(function ($instance) {
if ($instance instanceof ServiceLocatorAwareInterface) {
$instance->setServiceLocator($self);
$instance->setServiceLocator($this);
}
});
}
Expand Down
18 changes: 7 additions & 11 deletions src/ServiceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -610,12 +610,10 @@ public function create($name)
*/
private function createDelegatorCallback($delegatorFactory, $rName, $cName, $creationCallback)
{
$serviceManager = $this;

return function () use ($serviceManager, $delegatorFactory, $rName, $cName, $creationCallback) {
return function () use ($delegatorFactory, $rName, $cName, $creationCallback) {
return $delegatorFactory instanceof DelegatorFactoryInterface
? $delegatorFactory->createDelegatorWithName($serviceManager, $cName, $rName, $creationCallback)
: $delegatorFactory($serviceManager, $cName, $rName, $creationCallback);
? $delegatorFactory->createDelegatorWithName($this, $cName, $rName, $creationCallback)
: $delegatorFactory($this, $cName, $rName, $creationCallback);
};
}

Expand All @@ -628,9 +626,8 @@ private function createDelegatorCallback($delegatorFactory, $rName, $cName, $cre
* @return bool|mixed|null|object
* @throws Exception\ServiceNotFoundException
*
* @internal this method is internal because of PHP 5.3 compatibility - do not explicitly use it
*/
public function doCreate($rName, $cName)
protected function doCreate($rName, $cName)
{
$instance = null;

Expand Down Expand Up @@ -1188,10 +1185,9 @@ protected function checkNestedContextStop($force = false)
*/
protected function createDelegatorFromFactory($canonicalName, $requestedName)
{
$serviceManager = $this;
$delegatorsCount = count($this->delegators[$canonicalName]);
$creationCallback = function () use ($serviceManager, $requestedName, $canonicalName) {
return $serviceManager->doCreate($requestedName, $canonicalName);
$creationCallback = function () use ($requestedName, $canonicalName) {
return $this->doCreate($requestedName, $canonicalName);
};

for ($i = 0; $i < $delegatorsCount; $i += 1) {
Expand Down Expand Up @@ -1220,7 +1216,7 @@ protected function createDelegatorFromFactory($canonicalName, $requestedName)
);
}

return $creationCallback($serviceManager, $canonicalName, $requestedName, $creationCallback);
return $creationCallback($this, $canonicalName, $requestedName, $creationCallback);
}

/**
Expand Down
3 changes: 0 additions & 3 deletions test/MutableCreationOptionsTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@

use PHPUnit_Framework_TestCase as TestCase;

/**
* @requires PHP 5.4.0
*/
class MutableCreationOptionsTraitTest extends TestCase
{
protected $stub;
Expand Down
1 change: 0 additions & 1 deletion test/ServiceLocatorAwareTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Zend\ServiceManager\ServiceManager;

/**
* @requires PHP 5.4
* @group Zend_ServiceManager
*/
class ServiceLocatorAwareTraitTest extends TestCase
Expand Down
12 changes: 5 additions & 7 deletions test/ServiceManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -714,15 +714,13 @@ public function testGetGlobIteratorServiceWorksProperly()

public function duplicateService()
{
$self = $this;

return [
[
'setFactory',
function ($services) use ($self) {
return $self;
function ($services) {
return $this;
},
$self,
$this,
'assertSame',
],
[
Expand All @@ -733,8 +731,8 @@ function ($services) use ($self) {
],
[
'setService',
$self,
$self,
$this,
$this,
'assertSame',
],
];
Expand Down