Overview

Namespaces

  • Thelia
    • Action
    • Controller
    • Core
      • Bundle
      • Event
      • EventListener
      • Template
    • Exception
    • Log
      • Destination
    • Model
      • map
      • om
    • Routing
      • Matcher
    • Tools
    • Tpex
      • Loop

Classes

  • Parser

Interfaces

  • ParserInterface
  • Overview
  • Namespace
  • Class
  • Tree
  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: use Symfony\Component\Config\ConfigCache;
 31: 
 32: use Thelia\Tpex\Tpex;
 33: use Thelia\Log\Tlog;
 34: 
 35: /**
 36:  *
 37:  * Master class of Thelia's parser. The loop mechanism depends of this parser
 38:  *
 39:  * From this class all the parser is lunch
 40:  *
 41:  *
 42:  * @author Manuel Raynaud <mraynaud@openstudio.fr>
 43:  */
 44: 
 45: 
 46: class Parser implements ParserInterface
 47: {
 48:     const PREFIXE = 'prx';
 49: 
 50:     const SHOW_TIME = true;
 51:     const ALLOW_DEBUG = true;
 52:     const USE_CACHE = true;
 53:     
 54: 
 55:     /**
 56:      *
 57:      * @var Symfony\Component\DependencyInjection\ContainerInterface
 58:      */
 59:     protected $container;
 60:     
 61:     protected $content;
 62:     protected $status = 200;
 63:     
 64:     /**
 65:      *
 66:      * @var Thelia\Tpex\Tpex
 67:      */
 68:     protected $tpex;
 69:     
 70:     protected $template = "default";
 71:     
 72:     protected $init = false;
 73: 
 74:     /**
 75:      *
 76:      * @param type $container
 77:      *
 78:      * public function __construct(ContainerBuilder $container)
 79:      */
 80:     public function __construct(ContainerInterface $container, Tpex $tpex)
 81:     {
 82:         $this->container = $container;
 83:         $this->tpex = $tpex;
 84:     }
 85:     
 86:     protected function initialize()
 87:     {
 88:         if ($this->init === true) {
 89:             return;
 90:         }
 91:         
 92:         /** /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\
 93:          * @TODO
 94:          * 
 95:          * Avant le lancement du parser, enregistrer les boucles, filtres.
 96:          * Pour ne pas le faire à chaque lancement, on va créer une class qui contient toutes les classes nécessaires
 97:          * 
 98:          * Créer : 
 99:          * un dumper
100:          * une méthode qui récupère les différents éléments : boucles, filtres, substitutions, etc
101:          * 
102:          * 
103:          * /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ 
104:          */
105:     }
106:     
107:     /**
108:      * 
109:      * @return Symfony\Component\HttpFoundation\Request
110:      */
111:     public function getRequest()
112:     {
113:         return $this->container->get('request');
114:     }
115:     
116:     /**
117:      * 
118:      * @return Symfony\Component\EventDispatcher\EventDispatcher
119:      */
120:     public function getDispatcher()
121:     {
122:         return $this->container->get('dispatcher');
123:     }
124: 
125:     /**
126:      *
127:      * This method must return a Symfony\Component\HttpFoudation\Response instance or the content of the response
128:      *
129:      */
130:     public function getContent()
131:     {
132:        $this->loadParser();
133:        
134:        echo \Thelia\Model\ConfigQuery::read("alfred", "dupont");
135:        
136:        return $this->content;
137:     }
138: 
139:     /**
140:      *
141:      * set $content with the body of the response or the Response object directly
142:      *
143:      * @param string|Symfony\Component\HttpFoundation\Response $content
144:      */
145:     public function setContent($content)
146:     {
147:         $this->content = $content;
148:     }
149: 
150:     /**
151:      *
152:      * @return type the status of the response
153:      */
154:     public function getStatus()
155:     {
156:         return $this->status;
157:     }
158: 
159:     /**
160:      *
161:      * status HTTP of the response
162:      *
163:      * @param int $status
164:      */
165:     public function setStatus($status)
166:     {
167:         $this->status = $status;
168:     }
169: 
170:     /**
171:      * Main parser function, load the parser
172:      */
173:     public function loadParser()
174:     {
175:         $content = $this->openFile($this->getRequest());
176:         
177:         $this->tpex->init($this->container->get("request"), $this->container->get("dispatcher"), $content, THELIA_TEMPLATE_DIR . rtrim($this->template, "/") . "/");
178:         $this->tpex->setLogger(Tlog::getInstance());
179:         $this->tpex->execute();
180:     }
181:     
182:     protected function openFile(Request $request)
183:     {
184:         $file = $request->attributes->get('_view');
185:         $fileName = THELIA_TEMPLATE_DIR . rtrim($this->template, "/") . "/" . $file . ".html";
186:         if (file_exists($fileName)) {
187:             $content = file_get_contents($fileName);
188:         } else {
189:             throw new ResourceNotFoundException(sprintf("%s file not found in %s template", $file, $this->template));
190:         }
191:         
192:         return $content;
193:     }
194:     
195:     protected function parseInclude($content)
196:     {
197:         
198:     }
199: 
200: 
201: }
202: 
thelia API documentation generated by ApiGen 2.8.0