1: <?php
 2: 
 3:  4:  5:  6:  7:  8:  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: 20: 21: 22: 23: 
24: abstract class Controller implements ControllerInterface
25: {
26:     
27:     protected $container;
28: 
29:     30: 31: 
32:     public function setContainer(Application $container) {
33:         $this->container = $container;
34:     }
35: 
36:     37: 38: 
39:     public function render($path, array $arguments = []) {
40:         return new Response($this->renderText($path, $arguments));
41:     }
42: 
43:     44: 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: 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: 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: 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: 80: 
81:     public function getParameter($name, $default = null) {
82:         return $this->container['parameters']->get($name, $default);
83:     }
84: }