Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove $self = $this; use ($self) in 5.4 #6

Merged
merged 2 commits into from
Jan 14, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 2 additions & 3 deletions library/Zend/Cache/Pattern/CaptureCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ public function start($pageId = null)
$pageId = $this->detectPageId();
}

$that = $this;
ob_start(function ($content) use ($that, $pageId) {
$that->set($content, $pageId);
ob_start(function ($content) use ($pageId) {
$this->set($content, $pageId);

// http://php.net/manual/function.ob-start.php
// -> If output_callback returns FALSE original input is sent to the browser.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,11 @@ public function getCountForSql($sql)
*/
public function getRowCountClosure($context)
{
$oracleRowCounter = $this;
return function () use ($oracleRowCounter, $context) {
return function () use ($context) {
/** @var $oracleRowCounter OracleRowCounter */
return ($context instanceof Pdo\Statement)
? $oracleRowCounter->getCountForStatement($context)
: $oracleRowCounter->getCountForSql($context);
? $this->getCountForStatement($context)
: $this->getCountForSql($context);
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,11 @@ public function getCountForSql($sql)
*/
public function getRowCountClosure($context)
{
$sqliteRowCounter = $this;
return function () use ($sqliteRowCounter, $context) {
return function () use ($context) {
/** @var $sqliteRowCounter SqliteRowCounter */
return ($context instanceof Pdo\Statement)
? $sqliteRowCounter->getCountForStatement($context)
: $sqliteRowCounter->getCountForSql($context);
? $this->getCountForStatement($context)
: $this->getCountForSql($context);
};
}
}
5 changes: 2 additions & 3 deletions library/Zend/ServiceManager/AbstractPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,9 @@ abstract class AbstractPluginManager extends ServiceManager implements ServiceLo
public function __construct(ConfigInterface $configuration = null)
{
parent::__construct($configuration);
$self = $this;
$this->addInitializer(function ($instance) use ($self) {
$this->addInitializer(function ($instance) {
if ($instance instanceof ServiceLocatorAwareInterface) {
$instance->setServiceLocator($self);
$instance->setServiceLocator($this);
Copy link
Author

Choose a reason for hiding this comment

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

it makes test error,

1) ZendTest\ServiceManager\AbstractPluginManagerTest::testValidatePluginIsCalledWithDelegatorFactoryIfItsAService

Undefined variable: serviceManager

maybe rollback it ?

Copy link
Author

Choose a reason for hiding this comment

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

oh, its strange, seems not related with it...

}
});
}
Expand Down
13 changes: 5 additions & 8 deletions library/Zend/ServiceManager/ServiceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -605,12 +605,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) {
Copy link
Owner

Choose a reason for hiding this comment

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

Careful with the delegators: they're messy ;-)

Copy link
Author

Choose a reason for hiding this comment

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

I made a rollback change on samsonasik@68a626a , and in my local the test is pass now.

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 Down Expand Up @@ -1144,10 +1142,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);
Copy link
Author

Choose a reason for hiding this comment

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

it seems it cause the error ..., i will try to rollback it.

};

for ($i = 0; $i < $delegatorsCount; $i += 1) {
Expand Down
14 changes: 4 additions & 10 deletions library/Zend/Session/AbstractContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -518,12 +518,9 @@ public function setExpirationSeconds($ttl, $vars = null)
$this->expireKeys(); // first we need to expire global key, since it can already be expired
$data = array('EXPIRE' => $ts);
} elseif (is_array($vars)) {
// Cannot pass "$this" to a lambda
$container = $this;

// Filter out any items not in our container
$expires = array_filter($vars, function ($value) use ($container) {
return $container->offsetExists($value);
$expires = array_filter($vars, function ($value) {
return $this->offsetExists($value);
});

// Map item keys => timestamp
Expand Down Expand Up @@ -569,12 +566,9 @@ public function setExpirationHops($hops, $vars = null)
$this->expireKeys(); // first we need to expire global key, since it can already be expired
$data = array('EXPIRE_HOPS' => array('hops' => $hops, 'ts' => $ts));
} elseif (is_array($vars)) {
// Cannot pass "$this" to a lambda
$container = $this;

// FilterInterface out any items not in our container
$expires = array_filter($vars, function ($value) use ($container) {
return $container->offsetExists($value);
$expires = array_filter($vars, function ($value) {
return $this->offsetExists($value);
});

// Map item keys => timestamp
Expand Down
5 changes: 2 additions & 3 deletions tests/ZendTest/Db/Sql/DeleteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,8 @@ public function testWhere()
$this->delete->where($where);
$this->assertSame($where, $this->delete->where);

$test = $this;
$this->delete->where(function ($what) use ($test, $where) {
$test->assertSame($where, $what);
$this->delete->where(function ($what) use ($where) {
$this->assertSame($where, $what);
});
}

Expand Down
5 changes: 2 additions & 3 deletions tests/ZendTest/Db/Sql/Predicate/PredicateSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,8 @@ public function testAddPredicates()
$this->assertEquals('AND', $predicates[6][0]);
$this->assertInstanceOf('Zend\Db\Sql\Predicate\IsNotNull', $predicates[6][1]);

$test = $this;
$predicateSet->addPredicates(function ($what) use ($test, $predicateSet) {
$test->assertSame($predicateSet, $what);
$predicateSet->addPredicates(function ($what) use ($predicateSet) {
$this->assertSame($predicateSet, $what);
});

$this->setExpectedException('Zend\Db\Sql\Exception\InvalidArgumentException', 'Predicate cannot be null');
Expand Down
5 changes: 2 additions & 3 deletions tests/ZendTest/Db/Sql/SelectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,8 @@ public function testWhereArgument1IsClosure()
$select = new Select;
$where = $select->getRawState('where');

$test = $this;
$select->where(function ($what) use ($test, $where) {
$test->assertSame($where, $what);
$select->where(function ($what) use ($where) {
$this->assertSame($where, $what);
});
}

Expand Down
5 changes: 2 additions & 3 deletions tests/ZendTest/Db/Sql/UpdateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,8 @@ public function testWhere()
$this->update->where($where);
$this->assertSame($where, $this->update->where);

$test = $this;
$this->update->where(function ($what) use ($test, $where) {
$test->assertSame($where, $what);
$this->update->where(function ($what) use ($where) {
$this->assertSame($where, $what);
});

$this->setExpectedException('Zend\Db\Sql\Exception\InvalidArgumentException', 'Predicate cannot be null');
Expand Down
5 changes: 2 additions & 3 deletions tests/ZendTest/EventManager/AbstractListenerAggregateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,12 @@ public function testDetach()
$eventManager = $this->getMock('Zend\\EventManager\\EventManagerInterface');
$unrelatedEventManager = $this->getMock('Zend\\EventManager\\EventManagerInterface');
$callbackHandlers = array();
$test = $this;

$eventManager
->expects($this->exactly(2))
->method('attach')
->will($this->returnCallback(function () use (&$callbackHandlers, $test) {
return $callbackHandlers[] = $test->getMock('Zend\\Stdlib\\CallbackHandler', array(), array(), '', false);
->will($this->returnCallback(function () use (&$callbackHandlers) {
return $callbackHandlers[] = $this->getMock('Zend\\Stdlib\\CallbackHandler', array(), array(), '', false);
}));

$this->listener->attach($eventManager);
Expand Down
5 changes: 2 additions & 3 deletions tests/ZendTest/EventManager/ListenerAggregateTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ public function testDetach()
$eventManager = $this->getMock('Zend\\EventManager\\EventManagerInterface');
$unrelatedEventManager = $this->getMock('Zend\\EventManager\\EventManagerInterface');
$callbackHandlers = array();
$test = $this;

$eventManager
->expects($this->exactly(2))
->method('attach')
->will($this->returnCallback(function () use (&$callbackHandlers, $test) {
return $callbackHandlers[] = $test->getMock('Zend\\Stdlib\\CallbackHandler', array(), array(), '', false);
->will($this->returnCallback(function () use (&$callbackHandlers) {
return $callbackHandlers[] = $this->getMock('Zend\\Stdlib\\CallbackHandler', array(), array(), '', false);
}));

$listener->attach($eventManager);
Expand Down
10 changes: 4 additions & 6 deletions tests/ZendTest/Log/LoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,8 @@ public function testRegisterFatalShutdownFunction()
// check for single error handler instance
$this->assertFalse(Logger::registerFatalErrorShutdownFunction($this->logger));

$self = $this;
register_shutdown_function(function () use ($writer, $self) {
$self->assertEquals(
register_shutdown_function(function () use ($writer) {
$this->assertEquals(
'Call to undefined method ZendTest\Log\LoggerTest::callToNonExistingMethod()',
$writer->events[0]['message']
);
Expand All @@ -481,9 +480,8 @@ public function testRegisterFatalErrorShutdownFunctionHandlesCompileTimeErrors()
// check for single error handler instance
$this->assertFalse(Logger::registerFatalErrorShutdownFunction($this->logger));

$self = $this;
register_shutdown_function(function () use ($writer, $self) {
$self->assertStringMatchesFormat(
register_shutdown_function(function () use ($writer) {
$this->assertStringMatchesFormat(
'syntax error%A',
$writer->events[0]['message']
);
Expand Down
13 changes: 6 additions & 7 deletions tests/ZendTest/Mail/Transport/SendmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,12 @@ class SendmailTest extends \PHPUnit_Framework_TestCase
public function setUp()
{
$this->transport = new Sendmail();
$self = $this;
$this->transport->setCallable(function ($to, $subject, $message, $additional_headers, $additional_parameters = null) use ($self) {
$self->to = $to;
$self->subject = $subject;
$self->message = $message;
$self->additional_headers = $additional_headers;
$self->additional_parameters = $additional_parameters;
$this->transport->setCallable(function ($to, $subject, $message, $additional_headers, $additional_parameters = null) {
$this->to = $to;
$this->subject = $subject;
$this->message = $message;
$this->additional_headers = $additional_headers;
$this->additional_parameters = $additional_parameters;
});
$this->operating_system = strtoupper(substr(PHP_OS, 0, 3));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,8 @@ public function testModuleClassIsRegisteredWithDiAndInjectedWithSharedInstances(

$locatorRegistrationListener = new LocatorRegistrationListener;
$this->moduleManager->getEventManager()->attachAggregate($locatorRegistrationListener);
$test = $this;
$this->moduleManager->getEventManager()->attach(ModuleEvent::EVENT_LOAD_MODULE, function ($e) use ($test) {
$test->module = $e->getModule();
$this->moduleManager->getEventManager()->attach(ModuleEvent::EVENT_LOAD_MODULE, function ($e) {
$this->module = $e->getModule();
}, -1000);
$this->moduleManager->loadModules();

Expand Down
10 changes: 4 additions & 6 deletions tests/ZendTest/Mvc/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -581,10 +581,9 @@ public function testReturnsResponseFromListenerWhenRouteEventShortCircuits()
return $testResponse;
}, 100);

$self = $this;
$triggered = false;
$events->attach(MvcEvent::EVENT_FINISH, function ($e) use ($self, $testResponse, &$triggered) {
$self->assertSame($testResponse, $e->getResponse());
$events->attach(MvcEvent::EVENT_FINISH, function ($e) use ($testResponse, &$triggered) {
$this->assertSame($testResponse, $e->getResponse());
$triggered = true;
});

Expand All @@ -607,10 +606,9 @@ public function testReturnsResponseFromListenerWhenDispatchEventShortCircuits()
return $testResponse;
}, 100);

$self = $this;
$triggered = false;
$events->attach(MvcEvent::EVENT_FINISH, function ($e) use ($self, $testResponse, &$triggered) {
$self->assertSame($testResponse, $e->getResponse());
$events->attach(MvcEvent::EVENT_FINISH, function ($e) use ($testResponse, &$triggered) {
$this->assertSame($testResponse, $e->getResponse());
$triggered = true;
});

Expand Down
5 changes: 2 additions & 3 deletions tests/ZendTest/Mvc/Service/ServiceManagerConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,10 @@ public function testDefinesServiceManagerService()
*/
public function testCanOverrideServiceManager()
{
$test = $this;
$serviceManager = new ServiceManager(new ServiceManagerConfig(array(
'factories' => array(
'ServiceManager' => function () use ($test) {
return $test;
'ServiceManager' => function () {
return $this;
}
),
)));
Expand Down
12 changes: 5 additions & 7 deletions tests/ZendTest/ServiceManager/ServiceManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -715,15 +715,13 @@ public function testGetGlobIteratorServiceWorksProperly()

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

return array(
array(
'setFactory',
function ($services) use ($self) {
return $self;
function ($services) {
return $this;
},
$self,
$this,
'assertSame',
),
array(
Expand All @@ -734,8 +732,8 @@ function ($services) use ($self) {
),
array(
'setService',
$self,
$self,
$this,
$this,
'assertSame',
),
);
Expand Down
5 changes: 2 additions & 3 deletions tests/ZendTest/Soap/Client/DotNetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,9 @@ public function testCurlClientRequestIsDoneWhenUsingNtlmAuthentication()
*/
public function testDefaultSoapClientRequestIsDoneWhenNotUsingNtlmAuthentication()
{
$unitTest = $this;
$soapClient = new Common(
function (Common $client, $request, $location, $action, $version, $oneWay = null) use ($unitTest) {
$unitTest->assertEquals('http://unit/test#TestMethod', $action);
function (Common $client, $request, $location, $action, $version, $oneWay = null) {
$this->assertEquals('http://unit/test#TestMethod', $action);
$result = '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">'
. '<s:Body>';

Expand Down