Overview

Namespaces

  • Minion
    • Service
    • Twig

Classes

  • Minion\Application
  • Minion\Console
  • Minion\Controller
  • Minion\Service\ServiceConfig
  • Minion\Service\ServiceProvider
  • Minion\Twig\AssetExtension
  • Minion\Twig\MiscExtension
  • Minion\Twig\TwigExtensionTagServiceProvider
  • Minion\Twig\UrlExtension
  • Minion\Utils

Interfaces

  • Minion\ControllerInterface
  • Minion\Service\ServiceConfigInterface
  • Minion\Service\ServiceProviderInterface
  • Overview
  • Namespace
  • Class
 1: <?php
 2: 
 3: /**
 4:  * This file is part of the Minion package.
 5:  * For the full copyright and license information, please view the LICENSE
 6:  * file that was distributed with this source code.
 7:  *
 8:  * @license MIT License
 9:  */
10: 
11: namespace Minion;
12: 
13: use Symfony\Component\HttpFoundation\Response;
14: use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
15: use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
16: use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
17: 
18: /**
19:  * Class Controller.
20:  *
21:  * @package Minion
22:  * @author Damian SzczerbiƄski <dszczer@gmail.com>
23:  */
24: abstract class Controller implements ControllerInterface
25: {
26:     /** @var Application Framework */
27:     protected $container;
28: 
29:     /**
30:      * {@inheritdoc}
31:      */
32:     public function setContainer(Application $container) {
33:         $this->container = $container;
34:     }
35: 
36:     /**
37:      * {@inheritdoc}
38:      */
39:     public function render($path, array $arguments = []) {
40:         return new Response($this->renderText($path, $arguments));
41:     }
42: 
43:     /**
44:      * {@inheritdoc}
45:      */
46:     public function renderText($path, array $arguments = []) {
47:         if($this->container['minion.useTwig'])
48:             return $this->container['twig']->render($path, $arguments);
49:         else
50:             return Utils::renderPhpTemplate(Utils::fixPath($this->container->getRootDir() . '/src/' . $path), $arguments);
51:     }
52: 
53:     /**
54:      * {@inheritdoc}
55:      */
56:     public function createNotFoundException($message, \Exception $lastException = null) {
57:         $exception = new NotFoundHttpException($message, $lastException);
58: 
59:         return $this->container->minionError($exception, 404);
60:     }
61: 
62:     /**
63:      * {@inheritdoc}
64:      */
65:     public function createNotAllowedException($message, \Exception $lastException = null) {
66:         $exception = new AccessDeniedHttpException($message, $lastException);
67: 
68:         return $this->container->minionError($exception, 403);
69:     }
70: 
71:     /**
72:      * {@inheritdoc}
73:      */
74:     public function generateUrl($route, array $params = [], $flag = UrlGeneratorInterface::ABSOLUTE_URL) {
75:         return $this->container['url_generator']->generate($route, $params, $flag);
76:     }
77: 
78:     /**
79:      * {@inheritdoc}
80:      */
81:     public function getParameter($name, $default = null) {
82:         return $this->container['parameters']->get($name, $default);
83:     }
84: }
API documentation generated by ApiGen