Skip to content

Commit

Permalink
Merge pull request #173 from samsonasik/update-to-latest-php81-syntax
Browse files Browse the repository at this point in the history
Update to latest PHP 8.1 syntax
  • Loading branch information
gsteel authored Nov 14, 2024
2 parents 7899bb5 + 20d922a commit a9410d4
Show file tree
Hide file tree
Showing 14 changed files with 77 additions and 76 deletions.
2 changes: 1 addition & 1 deletion src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public function setEventManager(EventManagerInterface $eventManager)
{
$eventManager->setIdentifiers([
self::class,
$this::class,
static::class,
]);
$this->events = $eventManager;
return $this;
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function getResponse()
*/
public function setEventManager(EventManagerInterface $events)
{
$className = $this::class;
$className = static::class;

$identifiers = [
self::class,
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/MiddlewareController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Plugin/AcceptableViewModelSelector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions src/Controller/Plugin/Forward.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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))
));
}

Expand Down
2 changes: 1 addition & 1 deletion src/DispatchListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
*/
class DispatchListener extends AbstractListenerAggregate
{
public function __construct(private ControllerManager $controllerManager)
public function __construct(private readonly ControllerManager $controllerManager)
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/SendResponseListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function setEventManager(EventManagerInterface $eventManager)
{
$eventManager->setIdentifiers([
self::class,
$this::class,
static::class,
]);
$this->eventManager = $eventManager;
$this->attachDefaultListeners();
Expand Down
10 changes: 5 additions & 5 deletions src/Service/ModuleManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);

Expand Down
85 changes: 43 additions & 42 deletions src/Service/ServiceListenerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
];

Expand Down
2 changes: 1 addition & 1 deletion src/View/Http/InjectTemplateListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
12 changes: 6 additions & 6 deletions src/View/Http/ViewManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/Application/InitializationIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
18 changes: 9 additions & 9 deletions test/Controller/Plugin/ForwardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

class ForwardTest extends TestCase
{
private PluginManager $plugins;
private readonly PluginManager $plugins;

/**
* @var ControllerManager
Expand Down Expand Up @@ -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]]));
Expand All @@ -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');
Expand All @@ -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]]));
Expand All @@ -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');
Expand Down
Loading

0 comments on commit a9410d4

Please sign in to comment.