1: <?php
2: /*************************************************************************************/
3: /* */
4: /* Thelia */
5: /* */
6: /* Copyright (c) OpenStudio */
7: /* email : info@thelia.net */
8: /* web : http://www.thelia.net */
9: /* */
10: /* This program is free software; you can redistribute it and/or modify */
11: /* it under the terms of the GNU General Public License as published by */
12: /* the Free Software Foundation; either version 3 of the License */
13: /* */
14: /* This program is distributed in the hope that it will be useful, */
15: /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
16: /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
17: /* GNU General Public License for more details. */
18: /* */
19: /* You should have received a copy of the GNU General Public License */
20: /* along with this program. If not, see <http://www.gnu.org/licenses/>. */
21: /* */
22: /*************************************************************************************/
23: namespace Thelia\Core\Template;
24:
25: use Symfony\Component\HttpFoundation\Response;
26: use Thelia\Core\Template\ParserInterface;
27: use Symfony\Component\DependencyInjection\ContainerInterface;
28: use Symfony\Component\HttpFoundation\Request;
29: use Symfony\Component\Routing\Exception\ResourceNotFoundException;
30:
31: /**
32: *
33: * Master class of Thelia's parser. The loop mechanism depends of this parser
34: *
35: * From this class all the parser is lunch
36: *
37: *
38: * @author Manuel Raynaud <mraynaud@openstudio.fr>
39: */
40:
41:
42: class Parser implements ParserInterface
43: {
44: const PREFIXE = 'prx';
45:
46: const SHOW_TIME = true;
47: const ALLOW_DEBUG = true;
48: const USE_CACHE = true;
49:
50:
51: /**
52: *
53: * @var Symfony\Component\DependencyInjection\ContainerInterface
54: */
55: protected $container;
56:
57: protected $content;
58: protected $status = 200;
59:
60: protected $template = "default";
61:
62: /**
63: *
64: * @param type $container
65: *
66: * public function __construct(ContainerBuilder $container)
67: */
68: public function __construct(ContainerInterface $container)
69: {
70: $this->container = $container;
71: }
72:
73: /**
74: *
75: * @return Symfony\Component\HttpFoundation\Request
76: */
77: public function getRequest()
78: {
79: return $this->container->get('request');
80: }
81:
82: /**
83: *
84: * @return Symfony\Component\EventDispatcher\EventDispatcher
85: */
86: public function getDispatcher()
87: {
88: return $this->container->get('dispatcher');
89: }
90:
91: /**
92: *
93: * This method must return a Symfony\Component\HttpFoudation\Response instance or the content of the response
94: *
95: */
96: public function getContent()
97: {
98: $this->loadParser();
99:
100: echo \Thelia\Model\ConfigQuery::read("alfred", "dupont");
101:
102: return $this->content;
103: }
104:
105: /**
106: *
107: * set $content with the body of the response or the Response object directly
108: *
109: * @param string|Symfony\Component\HttpFoundation\Response $content
110: */
111: public function setContent($content)
112: {
113: $this->content = $content;
114: }
115:
116: /**
117: *
118: * @return type the status of the response
119: */
120: public function getStatus()
121: {
122: return $this->status;
123: }
124:
125: /**
126: *
127: * status HTTP of the response
128: *
129: * @param int $status
130: */
131: public function setStatus($status)
132: {
133: $this->status = $status;
134: }
135:
136: /**
137: * Main parser function, load the parser
138: */
139: public function loadParser()
140: {
141: $content = $this->openFile($this->getRequest());
142: }
143:
144: public function openFile(Request $request)
145: {
146: $file = $request->attributes->get('_view');
147: $fileName = THELIA_TEMPLATE_DIR . rtrim($this->template, "/") . "/" . $file . ".html";
148: if (file_exists($fileName)) {
149: $content = file_get_contents($fileName);
150: } else {
151: throw new ResourceNotFoundException(sprintf("%s file not found in %s template", $file, $this->template));
152: }
153:
154: return $content;
155: }
156:
157:
158:
159: }
160: