Skip to content

Commit

Permalink
Merge pull request #140 from samsonasik/apply-php80
Browse files Browse the repository at this point in the history
Apply PHP 8.0 Syntax and constructor promotion
  • Loading branch information
Ocramius authored Oct 21, 2022
2 parents 4ccca21 + 8b3c9c5 commit 111e08a
Show file tree
Hide file tree
Showing 90 changed files with 706 additions and 822 deletions.
40 changes: 17 additions & 23 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Laminas\Mvc;

use Laminas\Mvc\Service\ServiceManagerConfig;
use Laminas\EventManager\EventManagerAwareInterface;
use Laminas\EventManager\EventManagerInterface;
use Laminas\ServiceManager\ServiceManager;
Expand Down Expand Up @@ -42,12 +43,12 @@ class Application implements
ApplicationInterface,
EventManagerAwareInterface
{
const ERROR_CONTROLLER_CANNOT_DISPATCH = 'error-controller-cannot-dispatch';
const ERROR_CONTROLLER_NOT_FOUND = 'error-controller-not-found';
const ERROR_CONTROLLER_INVALID = 'error-controller-invalid';
const ERROR_EXCEPTION = 'error-exception';
const ERROR_ROUTER_NO_MATCH = 'error-router-no-match';
const ERROR_MIDDLEWARE_CANNOT_DISPATCH = 'error-middleware-cannot-dispatch';
public const ERROR_CONTROLLER_CANNOT_DISPATCH = 'error-controller-cannot-dispatch';
public const ERROR_CONTROLLER_NOT_FOUND = 'error-controller-not-found';
public const ERROR_CONTROLLER_INVALID = 'error-controller-invalid';
public const ERROR_EXCEPTION = 'error-exception';
public const ERROR_ROUTER_NO_MATCH = 'error-router-no-match';
public const ERROR_MIDDLEWARE_CANNOT_DISPATCH = 'error-middleware-cannot-dispatch';

/**
* Default application event listeners
Expand Down Expand Up @@ -75,7 +76,7 @@ class Application implements
protected $events;

/**
* @var \Laminas\Stdlib\RequestInterface
* @var RequestInterface
*/
protected $request;

Expand All @@ -84,26 +85,19 @@ class Application implements
*/
protected $response;

/**
* @var ServiceManager
*/
protected $serviceManager;

/**
* Constructor
*
* @param ServiceManager $serviceManager
* @param null|EventManagerInterface $events
* @param null|RequestInterface $request
* @param null|ResponseInterface $response
*/
public function __construct(
ServiceManager $serviceManager,
protected ServiceManager $serviceManager,
EventManagerInterface $events = null,
RequestInterface $request = null,
ResponseInterface $response = null
) {
$this->serviceManager = $serviceManager;
$this->setEventManager($events ?: $serviceManager->get('EventManager'));
$this->request = $request ?: $serviceManager->get('Request');
$this->response = $response ?: $serviceManager->get('Response');
Expand Down Expand Up @@ -169,7 +163,7 @@ public function getServiceManager()
/**
* Get the request object
*
* @return \Laminas\Stdlib\RequestInterface
* @return RequestInterface
*/
public function getRequest()
{
Expand Down Expand Up @@ -205,8 +199,8 @@ public function getMvcEvent()
public function setEventManager(EventManagerInterface $eventManager)
{
$eventManager->setIdentifiers([
__CLASS__,
get_class($this),
self::class,
$this::class,
]);
$this->events = $eventManager;
return $this;
Expand Down Expand Up @@ -246,8 +240,8 @@ public function getEventManager()
public static function init($configuration = [])
{
// Prepare the service manager
$smConfig = isset($configuration['service_manager']) ? $configuration['service_manager'] : [];
$smConfig = new Service\ServiceManagerConfig($smConfig);
$smConfig = $configuration['service_manager'] ?? [];
$smConfig = new ServiceManagerConfig($smConfig);

$serviceManager = new ServiceManager();
$smConfig->configureServiceManager($serviceManager);
Expand All @@ -257,9 +251,9 @@ public static function init($configuration = [])
$serviceManager->get('ModuleManager')->loadModules();

// Prepare list of listeners to bootstrap
$listenersFromAppConfig = isset($configuration['listeners']) ? $configuration['listeners'] : [];
$listenersFromAppConfig = $configuration['listeners'] ?? [];
$config = $serviceManager->get('config');
$listenersFromConfigService = isset($config['listeners']) ? $config['listeners'] : [];
$listenersFromConfigService = $config['listeners'] ?? [];

$listeners = array_unique(array_merge($listenersFromConfigService, $listenersFromAppConfig));

Expand Down Expand Up @@ -288,7 +282,7 @@ public function run()
$event = $this->event;

// Define callback used to determine whether or not to short-circuit
$shortCircuit = function ($r) use ($event) {
$shortCircuit = static function ($r) use ($event) : bool {
if ($r instanceof ResponseInterface) {
return true;
}
Expand Down
9 changes: 6 additions & 3 deletions src/ApplicationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,31 @@

namespace Laminas\Mvc;

use Laminas\ServiceManager\ServiceLocatorInterface;
use Laminas\Stdlib\RequestInterface;
use Laminas\Stdlib\ResponseInterface;
use Laminas\EventManager\EventsCapableInterface;

interface ApplicationInterface extends EventsCapableInterface
{
/**
* Get the locator object
*
* @return \Laminas\ServiceManager\ServiceLocatorInterface
* @return ServiceLocatorInterface
*/
public function getServiceManager();

/**
* Get the request object
*
* @return \Laminas\Stdlib\RequestInterface
* @return RequestInterface
*/
public function getRequest();

/**
* Get the response object
*
* @return \Laminas\Stdlib\ResponseInterface
* @return ResponseInterface
*/
public function getResponse();

Expand Down
5 changes: 3 additions & 2 deletions src/Controller/AbstractActionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Laminas\Mvc\Controller;

use Laminas\Mvc\Exception\DomainException;
use Laminas\Mvc\Exception;
use Laminas\Mvc\MvcEvent;
use Laminas\View\Model\ViewModel;
Expand All @@ -14,7 +15,7 @@ abstract class AbstractActionController extends AbstractController
/**
* {@inheritDoc}
*/
protected $eventIdentifier = __CLASS__;
protected $eventIdentifier = self::class;

/**
* Default action if none provided
Expand Down Expand Up @@ -58,7 +59,7 @@ public function onDispatch(MvcEvent $e)
* @todo Determine requirements for when route match is missing.
* Potentially allow pulling directly from request metadata?
*/
throw new Exception\DomainException('Missing route matches; unsure how to retrieve action');
throw new DomainException('Missing route matches; unsure how to retrieve action');
}

$action = $routeMatch->getParam('action', 'not-found');
Expand Down
31 changes: 18 additions & 13 deletions src/Controller/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

namespace Laminas\Mvc\Controller;

use Laminas\View\Model\ModelInterface;
use Laminas\Http\Header\Accept\FieldValuePart\AbstractFieldValuePart;
use Laminas\Mvc\Controller\Plugin\Forward;
use Laminas\Mvc\Controller\Plugin\Layout;
use Laminas\Mvc\Controller\Plugin\Params;
use Laminas\Mvc\Controller\Plugin\Redirect;
use Laminas\Mvc\Controller\Plugin\Url;
use Laminas\View\Model\ViewModel;
use Laminas\EventManager\EventInterface as Event;
use Laminas\EventManager\EventManager;
use Laminas\EventManager\EventManagerAwareInterface;
Expand All @@ -20,14 +28,14 @@
*
* Convenience methods for pre-built plugins (@see __call):
* @codingStandardsIgnoreStart
* @method \Laminas\View\Model\ModelInterface acceptableViewModelSelector(array $matchAgainst = null, bool $returnDefault = true, \Laminas\Http\Header\Accept\FieldValuePart\AbstractFieldValuePart $resultReference = null)
* @method ModelInterface acceptableViewModelSelector(array $matchAgainst = null, bool $returnDefault = true, AbstractFieldValuePart $resultReference = null)
* @codingStandardsIgnoreEnd
* @method \Laminas\Mvc\Controller\Plugin\Forward forward()
* @method \Laminas\Mvc\Controller\Plugin\Layout|\Laminas\View\Model\ModelInterface layout(string $template = null)
* @method \Laminas\Mvc\Controller\Plugin\Params|mixed params(string $param = null, mixed $default = null)
* @method \Laminas\Mvc\Controller\Plugin\Redirect redirect()
* @method \Laminas\Mvc\Controller\Plugin\Url url()
* @method \Laminas\View\Model\ViewModel createHttpNotFoundModel(Response $response)
* @method Forward forward()
* @method Layout|ModelInterface layout(string $template = null)
* @method Params|mixed params(string $param = null, mixed $default = null)
* @method Redirect redirect()
* @method Url url()
* @method ViewModel createHttpNotFoundModel(Response $response)
*/
abstract class AbstractController implements
Dispatchable,
Expand Down Expand Up @@ -94,9 +102,7 @@ public function dispatch(Request $request, Response $response = null)
$e->setResponse($response);
$e->setTarget($this);

$result = $this->getEventManager()->triggerEventUntil(function ($test) {
return ($test instanceof Response);
}, $e);
$result = $this->getEventManager()->triggerEventUntil(static fn($test): bool => $test instanceof Response, $e);

if ($result->stopped()) {
return $result->last();
Expand Down Expand Up @@ -141,10 +147,10 @@ public function getResponse()
*/
public function setEventManager(EventManagerInterface $events)
{
$className = get_class($this);
$className = $this::class;

$identifiers = [
__CLASS__,
self::class,
$className,
];

Expand Down Expand Up @@ -235,7 +241,6 @@ public function getPluginManager()
/**
* Set plugin manager
*
* @param PluginManager $plugins
* @return AbstractController
*/
public function setPluginManager(PluginManager $plugins)
Expand Down
Loading

0 comments on commit 111e08a

Please sign in to comment.