Skip to content
Snippets Groups Projects
Select Git revision
  • 3e77480931058a8ebdb89e7699628a2ef58691e8
  • master default protected
  • php84
  • ll-api-test
  • 6.x
  • release_6.2.0
  • modif_maintenance_phtml
  • 6.0.x
  • detached2
  • detached
  • php82
  • feature_SearchAndSelectFilter
  • 5.x
  • 4.x
  • 7.2.1
  • 7.2.0
  • 6.2.0
  • 7.1.0
  • 7.0.0
  • 1.1.1
  • 6.1.7
  • 6.1.6
  • 6.1.5
  • 6.0.16
  • 6.0.15
  • 6.1.4
  • 6.0.14
  • 6.1.3
  • 6.0.13
  • 6.1.2
  • 6.0.12
  • 6.1.1
  • 6.1.0
  • 6.0.11
34 results

Module.php

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    AbstractConsoleController.php 1.97 KiB
    <?php
    
    /**
     * @see       https://github.com/laminas/laminas-mvc-console for the canonical source repository
     * @copyright https://github.com/laminas/laminas-mvc-console/blob/master/COPYRIGHT.md
     * @license   https://github.com/laminas/laminas-mvc-console/blob/master/LICENSE.md New BSD License
     */
    
    namespace Unicaen\Console\Controller;
    
    use Unicaen\Console\Adapter\AdapterInterface as ConsoleAdapter;
    use Unicaen\Console\Request as ConsoleRequest;
    use Unicaen\Console\Exception\InvalidArgumentException;
    use Unicaen\Console\View\ViewModel;
    use Laminas\Mvc\Controller\AbstractActionController;
    use Laminas\Stdlib\RequestInterface;
    use Laminas\Stdlib\ResponseInterface;
    
    /**
      * @method \Unicaen\Console\View\ViewModel createConsoleNotFoundModel()
     */
    abstract class AbstractConsoleController extends AbstractActionController
    {
        /**
         * @var ConsoleAdapter
         */
        protected $console;
    
        /**
         * @param ConsoleAdapter $console
         */
        public function setConsole(ConsoleAdapter $console)
        {
            $this->console = $console;
            return $this;
        }
    
        /**
         * @return ConsoleAdapter
         */
        public function getConsole()
        {
            return $this->console;
        }
    
        /**
         * {@inheritdoc}
         */
        public function dispatch(RequestInterface $request, ResponseInterface $response = null)
        {
            if (! $request instanceof ConsoleRequest) {
                throw new InvalidArgumentException(sprintf(
                    '%s can only dispatch requests in a console environment',
                    get_called_class()
                ));
            }
            return parent::dispatch($request, $response);
        }
    
        /**
         * Action called if matched action does not exist.
         *
         * @return ViewModel
         */
        public function notFoundAction()
        {
            $event = $this->getEvent();
            $routeMatch = $event->getRouteMatch();
            $routeMatch->setParam('action', 'not-found');
    
            $helper = $this->plugin('createConsoleNotFoundModel');
            return $helper();
        }
    }