Skip to content

Commit

Permalink
Merge pull request #108 from gsteel/no-servicemanager-v2
Browse files Browse the repository at this point in the history
Remove Service Manager v2 Compatibility
  • Loading branch information
Ocramius authored Jan 11, 2022
2 parents 186a731 + 640303e commit 706ec94
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 214 deletions.
70 changes: 9 additions & 61 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -848,10 +848,9 @@
<code>$view</code>
<code>$view</code>
</RedundantCondition>
<RedundantConditionGivenDocblockType occurrences="5">
<RedundantConditionGivenDocblockType occurrences="4">
<code>$helper</code>
<code>$helper</code>
<code>$this-&gt;getServiceLocator()</code>
<code>$this-&gt;plugins</code>
<code>$view &amp;&amp; $this-&gt;plugins</code>
</RedundantConditionGivenDocblockType>
Expand All @@ -861,16 +860,9 @@
</UndefinedInterfaceMethod>
</file>
<file src="src/Helper/Navigation/AbstractHelper.php">
<DeprecatedMethod occurrences="2">
<code>getServiceLocator</code>
<code>getServiceLocator</code>
</DeprecatedMethod>
<DocblockTypeContradiction occurrences="6">
<code>! $services</code>
<DocblockTypeContradiction occurrences="3">
<code>! is_int($this-&gt;minDepth)</code>
<code>! is_string($message)</code>
<code>$services</code>
<code>$this-&gt;role === null</code>
<code>null === $this-&gt;container</code>
</DocblockTypeContradiction>
<ImplementedReturnTypeMismatch occurrences="2">
Expand All @@ -880,7 +872,7 @@
<InvalidThrow occurrences="1">
<code>Navigation\Exception\ExceptionInterface</code>
</InvalidThrow>
<MissingConstructor occurrences="29">
<MissingConstructor occurrences="19">
<code>$container</code>
<code>$container</code>
<code>$container</code>
Expand All @@ -900,28 +892,16 @@
<code>$minDepth</code>
<code>$minDepth</code>
<code>$minDepth</code>
<code>$role</code>
<code>$role</code>
<code>$role</code>
<code>$role</code>
<code>$role</code>
<code>$serviceLocator</code>
<code>$serviceLocator</code>
<code>$serviceLocator</code>
<code>$serviceLocator</code>
<code>$serviceLocator</code>
</MissingConstructor>
<MixedArgument occurrences="2">
<code>$page-&gt;getTextDomain()</code>
<code>$page-&gt;getTextDomain()</code>
</MixedArgument>
<MixedAssignment occurrences="7">
<MixedAssignment occurrences="5">
<code>$container</code>
<code>$container</code>
<code>$container</code>
<code>$label</code>
<code>$serviceLocator</code>
<code>$this-&gt;serviceLocator</code>
<code>$value</code>
</MixedAssignment>
<MixedInferredReturnType occurrences="1">
Expand All @@ -948,10 +928,9 @@
<PossiblyNullArgument occurrences="1">
<code>$page-&gt;getTitle()</code>
</PossiblyNullArgument>
<PossiblyNullPropertyAssignmentValue occurrences="3">
<PossiblyNullPropertyAssignmentValue occurrences="2">
<code>$maxDepth</code>
<code>$minDepth</code>
<code>$role</code>
</PossiblyNullPropertyAssignmentValue>
<PossiblyNullReference occurrences="4">
<code>attach</code>
Expand All @@ -964,17 +943,12 @@
<code>(bool) $useAcl</code>
<code>(string) $indent</code>
</RedundantCastGivenDocblockType>
<RedundantConditionGivenDocblockType occurrences="11">
<code>$serviceLocator-&gt;getServiceLocator()</code>
<RedundantConditionGivenDocblockType occurrences="5">
<code>$this-&gt;acl === null &amp;&amp; static::$defaultAcl !== null</code>
<code>$this-&gt;role === null &amp;&amp; static::$defaultRole !== null</code>
<code>is_int($maxDepth)</code>
<code>is_int($minDepth)</code>
<code>is_string($this-&gt;role)</code>
<code>is_string(static::$defaultRole)</code>
<code>null !== $this-&gt;container</code>
<code>static::$defaultAcl !== null</code>
<code>static::$defaultRole !== null</code>
</RedundantConditionGivenDocblockType>
<UndefinedInterfaceMethod occurrences="1">
<code>plugin</code>
Expand Down Expand Up @@ -1650,20 +1624,13 @@
<MixedArrayAccess occurrences="1">
<code>$config['view_helper_config']</code>
</MixedArrayAccess>
<MixedAssignment occurrences="3">
<MixedAssignment occurrences="2">
<code>$config</code>
<code>$configHelper</code>
<code>$container</code>
</MixedAssignment>
<MixedMethodCall occurrences="1">
<code>get</code>
</MixedMethodCall>
<PossiblyNullArgument occurrences="1">
<code>$cName</code>
</PossiblyNullArgument>
<UndefinedInterfaceMethod occurrences="1">
<code>getServiceLocator</code>
</UndefinedInterfaceMethod>
</file>
<file src="src/Helper/Service/DoctypeFactory.php">
<MixedArgument occurrences="1">
Expand Down Expand Up @@ -1697,14 +1664,13 @@
<code>$configHelper['message_separator_string']</code>
<code>$config['view_helper_config']</code>
</MixedArrayAccess>
<MixedAssignment occurrences="5">
<MixedAssignment occurrences="4">
<code>$config</code>
<code>$configHelper</code>
<code>$container</code>
<code>$controllerPluginManager</code>
<code>$flashMessenger</code>
</MixedAssignment>
<MixedMethodCall occurrences="3">
<MixedMethodCall occurrences="1">
<code>get</code>
<code>get</code>
<code>get</code>
Expand All @@ -1715,20 +1681,11 @@
<PossiblyNullArgument occurrences="1">
<code>$requestedName</code>
</PossiblyNullArgument>
<UndefinedInterfaceMethod occurrences="1">
<code>getServiceLocator</code>
</UndefinedInterfaceMethod>
</file>
<file src="src/Helper/Service/IdentityFactory.php">
<DeprecatedInterface occurrences="1">
<code>IdentityFactory</code>
</DeprecatedInterface>
<MixedArgument occurrences="1">
<code>$container</code>
</MixedArgument>
<MixedAssignment occurrences="1">
<code>$container</code>
</MixedAssignment>
<MixedInferredReturnType occurrences="1">
<code>null|AuthenticationServiceInterface</code>
</MixedInferredReturnType>
Expand All @@ -1739,9 +1696,6 @@
<PossiblyNullArgument occurrences="1">
<code>$cName</code>
</PossiblyNullArgument>
<UndefinedInterfaceMethod occurrences="1">
<code>getServiceLocator</code>
</UndefinedInterfaceMethod>
</file>
<file src="src/Helper/TranslatorAwareTrait.php">
<DeprecatedClass occurrences="3">
Expand Down Expand Up @@ -3212,12 +3166,6 @@
<code>$code</code>
</UnusedClosureParam>
</file>
<file src="test/Helper/Navigation/PluginManagerCompatibilityTest.php">
<ArgumentTypeCoercion occurrences="2">
<code>$this-&gt;getServiceNotFoundException()</code>
<code>$this-&gt;getServiceNotFoundException()</code>
</ArgumentTypeCoercion>
</file>
<file src="test/Helper/Navigation/SitemapTest.php">
<MixedArgument occurrences="2">
<code>$acl['acl']</code>
Expand Down
33 changes: 4 additions & 29 deletions src/Helper/Navigation/AbstractHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@
use Laminas\Navigation\Page\AbstractPage;
use Laminas\Permissions\Acl;
use Laminas\Permissions\Acl\AclInterface;
use Laminas\ServiceManager\AbstractPluginManager;
use Laminas\View;
use Laminas\View\Exception;
use Laminas\View\Helper\Navigation\Listener\AclListener;
use Laminas\View\Helper\TranslatorAwareTrait;
use RecursiveIteratorIterator;
use ReflectionClass;
use ReflectionProperty;

use function call_user_func_array;
use function get_class;
Expand All @@ -30,7 +28,6 @@
use function is_int;
use function is_object;
use function is_string;
use function method_exists;
use function sprintf;
use function str_repeat;
use function strlen;
Expand Down Expand Up @@ -101,11 +98,11 @@ abstract class AbstractHelper extends View\Helper\AbstractHtmlElement implements
/**
* ACL role to use when iterating pages
*
* @var string|Acl\Role\RoleInterface
* @var string|Acl\Role\RoleInterface|null
*/
protected $role;

/** @var ContainerInterface */
/** @var ContainerInterface|null */
protected $serviceLocator;

/**
Expand All @@ -127,7 +124,7 @@ abstract class AbstractHelper extends View\Helper\AbstractHtmlElement implements
* Default ACL role to use when iterating pages if not explicitly set in the
* instance by calling {@link setRole()}
*
* @var string|Acl\Role\RoleInterface
* @var string|Acl\Role\RoleInterface|null
*/
protected static $defaultRole;

Expand Down Expand Up @@ -767,28 +764,6 @@ public function hasRole()
*/
public function setServiceLocator(ContainerInterface $serviceLocator)
{
// If we are provided a plugin manager, we should pull the parent
// context from it.
// @todo We should update tests and code to ensure that this situation
// doesn't happen in the future.
if (
$serviceLocator instanceof AbstractPluginManager
&& ! method_exists($serviceLocator, 'configure')
&& $serviceLocator->getServiceLocator()
) {
$serviceLocator = $serviceLocator->getServiceLocator();
}

// v3 variant; likely won't be needed.
if (
$serviceLocator instanceof AbstractPluginManager
&& method_exists($serviceLocator, 'configure')
) {
$r = new ReflectionProperty($serviceLocator, 'creationContext');
$r->setAccessible(true);
$serviceLocator = $r->getValue($serviceLocator);
}

$this->serviceLocator = $serviceLocator;
return $this;
}
Expand All @@ -798,7 +773,7 @@ public function setServiceLocator(ContainerInterface $serviceLocator)
*
* Used internally to pull named navigation containers to render.
*
* @return ContainerInterface
* @return ContainerInterface|null
*/
public function getServiceLocator()
{
Expand Down
10 changes: 4 additions & 6 deletions src/Helper/Navigation/PluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Laminas\View\Helper\Navigation;

use Interop\Container\ContainerInterface;
use Laminas\ServiceManager\ConfigInterface;
use Laminas\ServiceManager\Factory\InvokableFactory;
use Laminas\ServiceManager\ServiceManager;
use Laminas\View\HelperPluginManager;
Expand Down Expand Up @@ -67,20 +66,19 @@ class PluginManager extends HelperPluginManager
];

/**
* @param null|ConfigInterface|ContainerInterface $configOrContainerInstance
* @param array $v3config If $configOrContainerInstance is a container, this
* value will be passed to the parent constructor.
* @param ContainerInterface $configOrContainerInstance
* @param array $v3config
* @psalm-param ServiceManagerConfiguration $v3config
*/
public function __construct($configOrContainerInstance = null, array $v3config = [])
{
/** @psalm-suppress MissingClosureParamType */
/** @psalm-suppress UnusedClosureParam, MissingClosureParamType */
$this->initializers[] = function (ContainerInterface $container, $instance): void {
if (! $instance instanceof AbstractHelper) {
return;
}

$instance->setServiceLocator($container);
$instance->setServiceLocator($this->creationContext);
};

parent::__construct($configOrContainerInstance, $v3config);
Expand Down
5 changes: 0 additions & 5 deletions src/Helper/Service/AssetFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Laminas\View\Helper\Asset;

use function is_array;
use function method_exists;

class AssetFactory implements FactoryInterface
{
Expand All @@ -23,10 +22,6 @@ class AssetFactory implements FactoryInterface
*/
public function __invoke(ContainerInterface $container, $name, ?array $options = null)
{
// test if we are using Laminas\ServiceManager v2 or v3
if (! method_exists($container, 'configure')) {
$container = $container->getServiceLocator();
}
$helper = new Asset();

$config = $container->get('config');
Expand Down
6 changes: 0 additions & 6 deletions src/Helper/Service/FlashMessengerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
use Laminas\ServiceManager\ServiceLocatorInterface;
use Laminas\View\Helper\FlashMessenger;

use function method_exists;

class FlashMessengerFactory implements FactoryInterface
{
/**
Expand All @@ -22,10 +20,6 @@ class FlashMessengerFactory implements FactoryInterface
*/
public function __invoke(ContainerInterface $container, $name, ?array $options = null)
{
// test if we are using Laminas\ServiceManager v2 or v3
if (! method_exists($container, 'configure')) {
$container = $container->getServiceLocator();
}
$helper = new FlashMessenger();
$controllerPluginManager = $container->get('ControllerPluginManager');
$flashMessenger = $controllerPluginManager->get('flashmessenger');
Expand Down
7 changes: 0 additions & 7 deletions src/Helper/Service/IdentityFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
use Laminas\ServiceManager\ServiceLocatorInterface;
use Laminas\View\Helper\Identity;

use function method_exists;

class IdentityFactory implements FactoryInterface
{
/**
Expand All @@ -22,11 +20,6 @@ class IdentityFactory implements FactoryInterface
*/
public function __invoke(ContainerInterface $container, $name, ?array $options = null)
{
// test if we are using Laminas\ServiceManager v2 or v3
if (! method_exists($container, 'configure')) {
$container = $container->getServiceLocator();
}

$helper = new Identity();

if (null !== ($authenticationService = $this->discoverAuthenticationService($container))) {
Expand Down
4 changes: 1 addition & 3 deletions test/Helper/Navigation/BreadcrumbsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Laminas\Navigation\Navigation;
use Laminas\View\Exception\InvalidArgumentException;
use Laminas\View\Helper\Navigation\Breadcrumbs;
use Laminas\View\HelperPluginManager;

use function extension_loaded;
use function strlen;
Expand Down Expand Up @@ -69,8 +68,7 @@ public function testHelperEntryPointWithContainerParam(): void

public function testHelperEntryPointWithContainerStringParam(): void
{
$pm = new HelperPluginManager($this->serviceManager);
$this->_helper->setServiceLocator($pm);
$this->_helper->setServiceLocator($this->serviceManager);

$returned = $this->_helper->__invoke('nav1');
$this->assertEquals($this->_helper, $returned);
Expand Down
3 changes: 1 addition & 2 deletions test/Helper/Navigation/LinksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ protected function setUp(): void

public function testCanRenderFromServiceAlias(): void
{
$sm = $this->serviceManager;
$this->_helper->setServiceLocator($sm);
$this->_helper->setServiceLocator($this->serviceManager);

$returned = $this->_helper->render('Navigation');
$this->assertEquals($returned, $this->getExpectedFileContents('links/default.html'));
Expand Down
Loading

0 comments on commit 706ec94

Please sign in to comment.