Skip to content

Commit

Permalink
fix: use ::class notation for controller
Browse files Browse the repository at this point in the history
Updates the listener and module to look for `PageController` as a class
name when matching the controller in the event.

The legacy `PhlySimplePage\Controller\Page` string continues to be
matched as well for BC purposes, but the documentation now references
only the `::class` notation.
  • Loading branch information
weierophinney committed Feb 4, 2020
1 parent ea35209 commit c99431e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 21 deletions.
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# PhlySimplePage

A ZF2 module for "static" pages.
A Laminas MVC module for "static" pages.

## Overview

In most ZF2 applications, you'll have at least a few pages that are basically
static -- the controller contains no logic for the given endpoint, and it
simply renders a template.
In most Laminas MVC applications, you'll have at least a few pages that are
basically static the controller contains no logic for the given endpoint, and
it simply renders a template.

By default, this requires the following steps:

Expand All @@ -27,8 +27,7 @@ $ composer require phly/phly-simple-page

## Enable the module

If you are using [zend-component-installer](https://docs.zendframework.com/zend-component-installer)
or [laminas-component-installer](https://docs.laminas.dev/laminas-component-installer),
If you are using [laminas-component-installer](https://docs.laminas.dev/laminas-component-installer),
you will get prompted to add the module to your `config/application.config.php`
file.

Expand All @@ -48,10 +47,12 @@ return [
## Usage

Create configuration in your application, mapping a route to the controller
`PhlySimplePage\Controller\Page`, and specifying a `template` key in the route
`PhlySimplePage\PageController`, and specifying a `template` key in the route
defaults.

```php
use PhlySimplePage\PageController;

return [
'router' => [
'routes' => [
Expand All @@ -60,7 +61,7 @@ return [
'options' => [
'route' => '/about',
'defaults' => [
'controller' => 'PhlySimplePage\Controller\Page',
'controller' => PageController::class,
'template' => 'application/pages/about',
// optionally set a specific layout for this page
'layout' => 'layout/some-layout',
Expand Down Expand Up @@ -130,7 +131,7 @@ As an example:
'options' => [
'route' => '/about',
'defaults' => [
'controller' => 'PhlySimplePage\Controller\Page',
'controller' => \PhlySimplePage\PageController::class,
'template' => 'application/pages/about',
'do_not_cache' => true,
],
Expand Down
25 changes: 15 additions & 10 deletions config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@

namespace PhlySimplePage;

return array(
'controllers' => array(
'invokables' => array(
use Laminas\ServiceManager\Factory\InvokableFactory;

return [
'controllers' => [
'aliases' => [
'PhlySimplePage\Controller\Page' => PageController::class,
),
),
'service_manager' => array(
'factories' => array(
],
'factories' => [
PageController::class => InvokableFactory::class,
],
],
'service_manager' => [
'factories' => [
ClearCacheCommand::class => ClearCacheCommandFactory::class,
PageCacheListener::class => PageCacheListenerFactory::class,
),
),
);
],
],
];
1 change: 1 addition & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<arg value="p" />

<!-- Paths to check -->
<file>config</file>
<file>src</file>
<file>test</file>

Expand Down
2 changes: 1 addition & 1 deletion src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function onRoutePost(MvcEvent $e): void
}

$controller = $matches->getParam('controller');
if ($controller !== 'PhlySimplePage\Controller\Page') {
if (! in_array($controller, ['PhlySimplePage\Controller\Page', PageController::class], true)) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/PageCacheListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function onRoutePost(MvcEvent $e): ?ResponseInterface
}

$controller = $matches->getParam('controller');
if ($controller !== 'PhlySimplePage\Controller\Page') {
if (! in_array($controller, ['PhlySimplePage\Controller\Page', PageController::class], true)) {
return null;
}

Expand Down

0 comments on commit c99431e

Please sign in to comment.