diff --git a/src/Application.php b/src/Application.php index 5d34785b..62c50953 100644 --- a/src/Application.php +++ b/src/Application.php @@ -200,7 +200,7 @@ public function setEventManager(EventManagerInterface $eventManager) { $eventManager->setIdentifiers([ self::class, - $this::class, + static::class, ]); $this->events = $eventManager; return $this; diff --git a/src/Controller/AbstractController.php b/src/Controller/AbstractController.php index d5c781a8..f38280c7 100644 --- a/src/Controller/AbstractController.php +++ b/src/Controller/AbstractController.php @@ -147,7 +147,7 @@ public function getResponse() */ public function setEventManager(EventManagerInterface $events) { - $className = $this::class; + $className = static::class; $identifiers = [ self::class, diff --git a/src/Controller/MiddlewareController.php b/src/Controller/MiddlewareController.php index b450b85a..d4d4d5fd 100644 --- a/src/Controller/MiddlewareController.php +++ b/src/Controller/MiddlewareController.php @@ -30,8 +30,8 @@ final class MiddlewareController extends AbstractController { public function __construct( - private MiddlewarePipe $pipe, - private ResponseInterface $responsePrototype, + private readonly MiddlewarePipe $pipe, + private readonly ResponseInterface $responsePrototype, EventManagerInterface $eventManager, MvcEvent $event ) { diff --git a/src/Controller/Plugin/AcceptableViewModelSelector.php b/src/Controller/Plugin/AcceptableViewModelSelector.php index 7be16152..82392f8b 100644 --- a/src/Controller/Plugin/AcceptableViewModelSelector.php +++ b/src/Controller/Plugin/AcceptableViewModelSelector.php @@ -45,7 +45,7 @@ class AcceptableViewModelSelector extends AbstractPlugin * * @var string Default ViewModel */ - protected $defaultViewModelName = 'Laminas\View\Model\ViewModel'; + protected $defaultViewModelName = \Laminas\View\Model\ViewModel::class; /** * Detects an appropriate viewmodel for request. diff --git a/src/Controller/Plugin/Forward.php b/src/Controller/Plugin/Forward.php index 0f43273d..b6b91f66 100644 --- a/src/Controller/Plugin/Forward.php +++ b/src/Controller/Plugin/Forward.php @@ -70,9 +70,9 @@ public function getListenersToDetach() // from getting attached to the ViewModel twice when a calling action // returns the output generated by a forwarded action. $this->listenersToDetach = [[ - 'id' => 'Laminas\Stdlib\DispatchableInterface', + 'id' => \Laminas\Stdlib\DispatchableInterface::class, 'event' => MvcEvent::EVENT_DISPATCH, - 'class' => 'Laminas\Mvc\View\Http\InjectViewModelListener', + 'class' => \Laminas\Mvc\View\Http\InjectViewModelListener::class, ]]; } return $this->listenersToDetach; @@ -231,7 +231,7 @@ protected function getEvent() if (! $controller instanceof InjectApplicationEventInterface) { throw new DomainException(sprintf( 'Forward plugin requires a controller that implements InjectApplicationEventInterface; received %s', - (is_object($controller) ? $controller::class : var_export($controller, 1)) + (get_debug_type($controller)) )); } diff --git a/src/DispatchListener.php b/src/DispatchListener.php index 0bf471df..e4c74b1c 100644 --- a/src/DispatchListener.php +++ b/src/DispatchListener.php @@ -37,7 +37,7 @@ */ class DispatchListener extends AbstractListenerAggregate { - public function __construct(private ControllerManager $controllerManager) + public function __construct(private readonly ControllerManager $controllerManager) { } diff --git a/src/SendResponseListener.php b/src/SendResponseListener.php index 644fe745..d0c8c461 100644 --- a/src/SendResponseListener.php +++ b/src/SendResponseListener.php @@ -35,7 +35,7 @@ public function setEventManager(EventManagerInterface $eventManager) { $eventManager->setIdentifiers([ self::class, - $this::class, + static::class, ]); $this->eventManager = $eventManager; $this->attachDefaultListeners(); diff --git a/src/Service/ModuleManagerFactory.php b/src/Service/ModuleManagerFactory.php index 762b3284..a78263a9 100644 --- a/src/Service/ModuleManagerFactory.php +++ b/src/Service/ModuleManagerFactory.php @@ -37,32 +37,32 @@ public function __invoke(ContainerInterface $container, $name, ?array $options = $serviceListener->addServiceManager( $container, 'service_manager', - 'Laminas\ModuleManager\Feature\ServiceProviderInterface', + \Laminas\ModuleManager\Feature\ServiceProviderInterface::class, 'getServiceConfig' ); $serviceListener->addServiceManager( 'ControllerManager', 'controllers', - 'Laminas\ModuleManager\Feature\ControllerProviderInterface', + \Laminas\ModuleManager\Feature\ControllerProviderInterface::class, 'getControllerConfig' ); $serviceListener->addServiceManager( 'ControllerPluginManager', 'controller_plugins', - 'Laminas\ModuleManager\Feature\ControllerPluginProviderInterface', + \Laminas\ModuleManager\Feature\ControllerPluginProviderInterface::class, 'getControllerPluginConfig' ); $serviceListener->addServiceManager( 'ViewHelperManager', 'view_helpers', - 'Laminas\ModuleManager\Feature\ViewHelperProviderInterface', + \Laminas\ModuleManager\Feature\ViewHelperProviderInterface::class, 'getViewHelperConfig' ); $serviceListener->addServiceManager( 'RoutePluginManager', 'route_manager', - 'Laminas\ModuleManager\Feature\RouteProviderInterface', + \Laminas\ModuleManager\Feature\RouteProviderInterface::class, 'getRouteConfig' ); diff --git a/src/Service/ServiceListenerFactory.php b/src/Service/ServiceListenerFactory.php index fb71041f..e527d395 100644 --- a/src/Service/ServiceListenerFactory.php +++ b/src/Service/ServiceListenerFactory.php @@ -36,58 +36,59 @@ class ServiceListenerFactory implements FactoryInterface 'configuration' => 'config', 'Configuration' => 'config', 'HttpDefaultRenderingStrategy' => DefaultRenderingStrategy::class, - 'MiddlewareListener' => 'Laminas\Mvc\MiddlewareListener', + 'MiddlewareListener' => \Laminas\Mvc\MiddlewareListener::class, 'request' => 'Request', 'response' => 'Response', - 'RouteListener' => 'Laminas\Mvc\RouteListener', - 'SendResponseListener' => 'Laminas\Mvc\SendResponseListener', - 'View' => 'Laminas\View\View', - 'ViewFeedRenderer' => 'Laminas\View\Renderer\FeedRenderer', - 'ViewJsonRenderer' => 'Laminas\View\Renderer\JsonRenderer', - 'ViewPhpRendererStrategy' => 'Laminas\View\Strategy\PhpRendererStrategy', - 'ViewPhpRenderer' => 'Laminas\View\Renderer\PhpRenderer', - 'ViewRenderer' => 'Laminas\View\Renderer\PhpRenderer', - 'Laminas\Mvc\Controller\PluginManager' => 'ControllerPluginManager', - 'Laminas\Mvc\View\Http\InjectTemplateListener' => 'InjectTemplateListener', - 'Laminas\View\Renderer\RendererInterface' => 'Laminas\View\Renderer\PhpRenderer', - 'Laminas\View\Resolver\TemplateMapResolver' => 'ViewTemplateMapResolver', - 'Laminas\View\Resolver\TemplatePathStack' => 'ViewTemplatePathStack', - 'Laminas\View\Resolver\AggregateResolver' => 'ViewResolver', - 'Laminas\View\Resolver\ResolverInterface' => 'ViewResolver', + 'RouteListener' => \Laminas\Mvc\RouteListener::class, + 'SendResponseListener' => \Laminas\Mvc\SendResponseListener::class, + 'View' => \Laminas\View\View::class, + 'ViewFeedRenderer' => \Laminas\View\Renderer\FeedRenderer::class, + 'ViewJsonRenderer' => \Laminas\View\Renderer\JsonRenderer::class, + 'ViewPhpRendererStrategy' => \Laminas\View\Strategy\PhpRendererStrategy::class, + 'ViewPhpRenderer' => \Laminas\View\Renderer\PhpRenderer::class, + 'ViewRenderer' => \Laminas\View\Renderer\PhpRenderer::class, + \Laminas\Mvc\Controller\PluginManager::class => 'ControllerPluginManager', + \Laminas\Mvc\View\Http\InjectTemplateListener::class => 'InjectTemplateListener', + \Laminas\View\Renderer\RendererInterface::class => \Laminas\View\Renderer\PhpRenderer::class, + \Laminas\View\Resolver\TemplateMapResolver::class => 'ViewTemplateMapResolver', + \Laminas\View\Resolver\TemplatePathStack::class => 'ViewTemplatePathStack', + \Laminas\View\Resolver\AggregateResolver::class => 'ViewResolver', + \Laminas\View\Resolver\ResolverInterface::class => 'ViewResolver', ControllerManager::class => 'ControllerManager', ], 'invokables' => [], 'factories' => [ 'Application' => ApplicationFactory::class, - 'config' => 'Laminas\Mvc\Service\ConfigFactory', - 'ControllerManager' => 'Laminas\Mvc\Service\ControllerManagerFactory', - 'ControllerPluginManager' => 'Laminas\Mvc\Service\ControllerPluginManagerFactory', - 'DispatchListener' => 'Laminas\Mvc\Service\DispatchListenerFactory', + 'config' => \Laminas\Mvc\Service\ConfigFactory::class, + 'ControllerManager' => \Laminas\Mvc\Service\ControllerManagerFactory::class, + 'ControllerPluginManager' => \Laminas\Mvc\Service\ControllerPluginManagerFactory::class, + 'DispatchListener' => \Laminas\Mvc\Service\DispatchListenerFactory::class, 'HttpExceptionStrategy' => HttpExceptionStrategyFactory::class, - 'HttpMethodListener' => 'Laminas\Mvc\Service\HttpMethodListenerFactory', + 'HttpMethodListener' => \Laminas\Mvc\Service\HttpMethodListenerFactory::class, 'HttpRouteNotFoundStrategy' => HttpRouteNotFoundStrategyFactory::class, - 'HttpViewManager' => 'Laminas\Mvc\Service\HttpViewManagerFactory', - 'InjectTemplateListener' => 'Laminas\Mvc\Service\InjectTemplateListenerFactory', - 'PaginatorPluginManager' => 'Laminas\Mvc\Service\PaginatorPluginManagerFactory', - 'Request' => 'Laminas\Mvc\Service\RequestFactory', - 'Response' => 'Laminas\Mvc\Service\ResponseFactory', - 'ViewHelperManager' => 'Laminas\Mvc\Service\ViewHelperManagerFactory', + 'HttpViewManager' => \Laminas\Mvc\Service\HttpViewManagerFactory::class, + 'InjectTemplateListener' => \Laminas\Mvc\Service\InjectTemplateListenerFactory::class, + 'PaginatorPluginManager' => \Laminas\Mvc\Service\PaginatorPluginManagerFactory::class, + 'Request' => \Laminas\Mvc\Service\RequestFactory::class, + 'Response' => \Laminas\Mvc\Service\ResponseFactory::class, + 'ViewHelperManager' => \Laminas\Mvc\Service\ViewHelperManagerFactory::class, DefaultRenderingStrategy::class => HttpDefaultRenderingStrategyFactory::class, - 'ViewFeedStrategy' => 'Laminas\Mvc\Service\ViewFeedStrategyFactory', - 'ViewJsonStrategy' => 'Laminas\Mvc\Service\ViewJsonStrategyFactory', - 'ViewManager' => 'Laminas\Mvc\Service\ViewManagerFactory', - 'ViewResolver' => 'Laminas\Mvc\Service\ViewResolverFactory', - 'ViewTemplateMapResolver' => 'Laminas\Mvc\Service\ViewTemplateMapResolverFactory', - 'ViewTemplatePathStack' => 'Laminas\Mvc\Service\ViewTemplatePathStackFactory', - 'ViewPrefixPathStackResolver' => 'Laminas\Mvc\Service\ViewPrefixPathStackResolverFactory', - 'Laminas\Mvc\MiddlewareListener' => InvokableFactory::class, - 'Laminas\Mvc\RouteListener' => InvokableFactory::class, - 'Laminas\Mvc\SendResponseListener' => SendResponseListenerFactory::class, - 'Laminas\View\Renderer\FeedRenderer' => InvokableFactory::class, - 'Laminas\View\Renderer\JsonRenderer' => InvokableFactory::class, - 'Laminas\View\Renderer\PhpRenderer' => ViewPhpRendererFactory::class, - 'Laminas\View\Strategy\PhpRendererStrategy' => ViewPhpRendererStrategyFactory::class, - 'Laminas\View\View' => ViewFactory::class, + 'ViewFeedStrategy' => \Laminas\Mvc\Service\ViewFeedStrategyFactory::class, + 'ViewJsonStrategy' => \Laminas\Mvc\Service\ViewJsonStrategyFactory::class, + 'ViewManager' => \Laminas\Mvc\Service\ViewManagerFactory::class, + 'ViewResolver' => \Laminas\Mvc\Service\ViewResolverFactory::class, + 'ViewTemplateMapResolver' => \Laminas\Mvc\Service\ViewTemplateMapResolverFactory::class, + 'ViewTemplatePathStack' => \Laminas\Mvc\Service\ViewTemplatePathStackFactory::class, + 'ViewPrefixPathStackResolver' + => \Laminas\Mvc\Service\ViewPrefixPathStackResolverFactory::class, + \Laminas\Mvc\MiddlewareListener::class => InvokableFactory::class, + \Laminas\Mvc\RouteListener::class => InvokableFactory::class, + \Laminas\Mvc\SendResponseListener::class => SendResponseListenerFactory::class, + \Laminas\View\Renderer\FeedRenderer::class => InvokableFactory::class, + \Laminas\View\Renderer\JsonRenderer::class => InvokableFactory::class, + \Laminas\View\Renderer\PhpRenderer::class => ViewPhpRendererFactory::class, + \Laminas\View\Strategy\PhpRendererStrategy::class => ViewPhpRendererStrategyFactory::class, + \Laminas\View\View::class => ViewFactory::class, ], ]; diff --git a/src/View/Http/InjectTemplateListener.php b/src/View/Http/InjectTemplateListener.php index d51f7577..01a6a7ce 100644 --- a/src/View/Http/InjectTemplateListener.php +++ b/src/View/Http/InjectTemplateListener.php @@ -167,7 +167,7 @@ protected function deriveControllerClass($controller) } if ((10 < strlen($controller)) - && ('Controller' == substr($controller, -10)) + && (str_ends_with($controller, 'Controller')) ) { $controller = substr($controller, 0, -10); } diff --git a/src/View/Http/ViewManager.php b/src/View/Http/ViewManager.php index 100b9e3f..9779a798 100644 --- a/src/View/Http/ViewManager.php +++ b/src/View/Http/ViewManager.php @@ -100,7 +100,7 @@ public function onBootstrap($event) $this->injectViewModelIntoPlugin(); - $injectTemplateListener = $services->get('Laminas\Mvc\View\Http\InjectTemplateListener'); + $injectTemplateListener = $services->get(\Laminas\Mvc\View\Http\InjectTemplateListener::class); $createViewModelListener = new CreateViewModelListener(); $injectViewModelListener = new InjectViewModelListener(); @@ -114,31 +114,31 @@ public function onBootstrap($event) $mvcRenderingStrategy->attach($events); $sharedEvents->attach( - 'Laminas\Stdlib\DispatchableInterface', + \Laminas\Stdlib\DispatchableInterface::class, MvcEvent::EVENT_DISPATCH, [$createViewModelListener, 'createViewModelFromArray'], -80 ); $sharedEvents->attach( - 'Laminas\Stdlib\DispatchableInterface', + \Laminas\Stdlib\DispatchableInterface::class, MvcEvent::EVENT_DISPATCH, [$routeNotFoundStrategy, 'prepareNotFoundViewModel'], -90 ); $sharedEvents->attach( - 'Laminas\Stdlib\DispatchableInterface', + \Laminas\Stdlib\DispatchableInterface::class, MvcEvent::EVENT_DISPATCH, [$createViewModelListener, 'createViewModelFromNull'], -80 ); $sharedEvents->attach( - 'Laminas\Stdlib\DispatchableInterface', + \Laminas\Stdlib\DispatchableInterface::class, MvcEvent::EVENT_DISPATCH, [$injectTemplateListener, 'injectTemplate'], -90 ); $sharedEvents->attach( - 'Laminas\Stdlib\DispatchableInterface', + \Laminas\Stdlib\DispatchableInterface::class, MvcEvent::EVENT_DISPATCH, [$injectViewModelListener, 'injectViewModel'], -100 diff --git a/test/Application/InitializationIntegrationTest.php b/test/Application/InitializationIntegrationTest.php index fd9cc17d..8cfe84a6 100644 --- a/test/Application/InitializationIntegrationTest.php +++ b/test/Application/InitializationIntegrationTest.php @@ -33,8 +33,8 @@ public function testDefaultInitializationWorkflow() $content = ob_get_clean(); $response = $application->getResponse(); - $this->assertStringContainsString('Application\\Controller\\PathController', $response->getContent()); - $this->assertStringContainsString('Application\\Controller\\PathController', $content); + $this->assertStringContainsString(\Application\Controller\PathController::class, $response->getContent()); + $this->assertStringContainsString(\Application\Controller\PathController::class, $content); $this->assertStringContainsString(MvcEvent::EVENT_DISPATCH, $response->toString()); } } diff --git a/test/Controller/Plugin/ForwardTest.php b/test/Controller/Plugin/ForwardTest.php index 5d1d4294..e551e59b 100644 --- a/test/Controller/Plugin/ForwardTest.php +++ b/test/Controller/Plugin/ForwardTest.php @@ -28,7 +28,7 @@ class ForwardTest extends TestCase { - private PluginManager $plugins; + private readonly PluginManager $plugins; /** * @var ControllerManager @@ -223,11 +223,11 @@ public function testProblemListenersAreDetachedAndReattachedWhenPluginDispatches $sharedEvents = $this->createMock(SharedEventManagerInterface::class); $sharedEvents->expects($this->once()) ->method('detach') - ->with($myCallback, 'Laminas\Stdlib\DispatchableInterface'); + ->with($myCallback, \Laminas\Stdlib\DispatchableInterface::class); $sharedEvents ->expects($this->once()) ->method('attach') - ->with('Laminas\Stdlib\DispatchableInterface', MvcEvent::EVENT_DISPATCH, $myCallback, -50); + ->with(\Laminas\Stdlib\DispatchableInterface::class, MvcEvent::EVENT_DISPATCH, $myCallback, -50); $sharedEvents->expects($this->any()) ->method('getListeners') ->will($this->returnValue([-50 => [$myCallback]])); @@ -239,9 +239,9 @@ public function testProblemListenersAreDetachedAndReattachedWhenPluginDispatches $event->setApplication($application); $this->plugin->setListenersToDetach([[ - 'id' => 'Laminas\Stdlib\DispatchableInterface', + 'id' => \Laminas\Stdlib\DispatchableInterface::class, 'event' => MvcEvent::EVENT_DISPATCH, - 'class' => 'LaminasTest\Mvc\Controller\Plugin\TestAsset\ListenerStub', + 'class' => \LaminasTest\Mvc\Controller\Plugin\TestAsset\ListenerStub::class, ]]); $result = $this->plugin->dispatch('forward'); @@ -256,11 +256,11 @@ public function testInvokableProblemListenersAreDetachedAndReattachedWhenPluginD $sharedEvents = $this->createMock(SharedEventManagerInterface::class); $sharedEvents->expects($this->once()) ->method('detach') - ->with($myCallback, 'Laminas\Stdlib\DispatchableInterface'); + ->with($myCallback, \Laminas\Stdlib\DispatchableInterface::class); $sharedEvents ->expects($this->once()) ->method('attach') - ->with('Laminas\Stdlib\DispatchableInterface', MvcEvent::EVENT_DISPATCH, $myCallback, -50); + ->with(\Laminas\Stdlib\DispatchableInterface::class, MvcEvent::EVENT_DISPATCH, $myCallback, -50); $sharedEvents->expects($this->any()) ->method('getListeners') ->will($this->returnValue([-50 => [$myCallback]])); @@ -272,9 +272,9 @@ public function testInvokableProblemListenersAreDetachedAndReattachedWhenPluginD $event->setApplication($application); $this->plugin->setListenersToDetach([[ - 'id' => 'Laminas\Stdlib\DispatchableInterface', + 'id' => \Laminas\Stdlib\DispatchableInterface::class, 'event' => MvcEvent::EVENT_DISPATCH, - 'class' => 'LaminasTest\Mvc\Controller\Plugin\TestAsset\ListenerStub', + 'class' => \LaminasTest\Mvc\Controller\Plugin\TestAsset\ListenerStub::class, ]]); $result = $this->plugin->dispatch('forward'); diff --git a/test/Service/ViewHelperManagerFactoryTest.php b/test/Service/ViewHelperManagerFactoryTest.php index af044f63..c47fdbcd 100644 --- a/test/Service/ViewHelperManagerFactoryTest.php +++ b/test/Service/ViewHelperManagerFactoryTest.php @@ -70,7 +70,7 @@ public function testUrlHelperFactoryCanBeInvokedViaShortNameOrFullClassName($nam { $this->markTestSkipped(sprintf( '%s::%s skipped until laminas-view and the url() view helper are updated to use laminas-router', - $this::class, + static::class, __FUNCTION__ ));