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

Commit 5405c7d

Browse files
committed
Move getServiceLocator() to service manager
Since the container passed to factories is always the creation context container in v3, `getServiceLocator()` will always be the service manager itself, not a plugin manager. By pushing the method into the service manager, we achieve backwards compatibility with v2; by marking it deprecated, we can remove it in the future.
1 parent c866971 commit 5405c7d

File tree

4 files changed

+31
-31
lines changed

4 files changed

+31
-31
lines changed

src/AbstractPluginManager.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -140,24 +140,6 @@ public function validate($instance)
140140
));
141141
}
142142

143-
/**
144-
* Implemented for backwards compatibility only.
145-
*
146-
* Returns the creation context.
147-
*
148-
* @deprecated since 3.0.0. Factories using 3.0 should use the container
149-
* instance passed to the factory instead.
150-
* @return ContainerInterface
151-
*/
152-
public function getServiceLocator()
153-
{
154-
trigger_error(sprintf(
155-
'Usage of %s is deprecated since v3.0.0; please use the container passed to the factory instead',
156-
__METHOD__
157-
), E_USER_DEPRECATED);
158-
return $this->creationContext;
159-
}
160-
161143
/**
162144
* Implemented for backwards compatibility only.
163145
*

src/ServiceManager.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,24 @@ public function __construct(array $config = [])
140140
$this->configure($config);
141141
}
142142

143+
/**
144+
* Implemented for backwards compatibility with previous plugin managers only.
145+
*
146+
* Returns the creation context.
147+
*
148+
* @deprecated since 3.0.0. Factories using 3.0 should use the container
149+
* instance passed to the factory instead.
150+
* @return ContainerInterface
151+
*/
152+
public function getServiceLocator()
153+
{
154+
trigger_error(sprintf(
155+
'Usage of %s is deprecated since v3.0.0; please use the container passed to the factory instead',
156+
__METHOD__
157+
), E_USER_DEPRECATED);
158+
return $this->creationContext;
159+
}
160+
143161
/**
144162
* {@inheritDoc}
145163
*/

test/AbstractPluginManagerTest.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -180,19 +180,6 @@ public function testGetRaisesExceptionWhenNoFactoryIsResolved()
180180
$pluginManager->get('Some\Unknown\Service');
181181
}
182182

183-
/**
184-
* @group migration
185-
*/
186-
public function testCanRetrieveParentContainerViaGetServiceLocatorWithDeprecationNotice()
187-
{
188-
$container = $this->createContainer();
189-
set_error_handler(function ($errno, $errstr) {
190-
$this->assertEquals(E_USER_DEPRECATED, $errno);
191-
}, E_USER_DEPRECATED);
192-
$this->assertSame($this->creationContext, $container->getServiceLocator());
193-
restore_error_handler();
194-
}
195-
196183
/**
197184
* @group migration
198185
*/

test/CommonServiceLocatorBehaviorsTrait.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,4 +770,17 @@ public function testAllowOverrideFlagIsMutable($container)
770770
$container->setAllowOverride(true);
771771
$this->assertTrue($container->getAllowOverride());
772772
}
773+
774+
/**
775+
* @group migration
776+
*/
777+
public function testCanRetrieveParentContainerViaGetServiceLocatorWithDeprecationNotice()
778+
{
779+
$container = $this->createContainer();
780+
set_error_handler(function ($errno, $errstr) {
781+
$this->assertEquals(E_USER_DEPRECATED, $errno);
782+
}, E_USER_DEPRECATED);
783+
$this->assertSame($this->creationContext, $container->getServiceLocator());
784+
restore_error_handler();
785+
}
773786
}

0 commit comments

Comments
 (0)