Overview

Namespaces

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

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:     /**
 73:      *
 74:      * @param type $container
 75:      *
 76:      * public function __construct(ContainerBuilder $container)
 77:      */
 78:     public function __construct(ContainerInterface $container, Tpex $tpex)
 79:     {
 80:         $this->container = $container;
 81:         $this->tpex = $tpex;
 82:     }
 83:     
 84:     /**
 85:      * 
 86:      * @return Symfony\Component\HttpFoundation\Request
 87:      */
 88:     public function getRequest()
 89:     {
 90:         return $this->container->get('request');
 91:     }
 92:     
 93:     /**
 94:      * 
 95:      * @return Symfony\Component\EventDispatcher\EventDispatcher
 96:      */
 97:     public function getDispatcher()
 98:     {
 99:         return $this->container->get('dispatcher');
100:     }
101: 
102:     /**
103:      *
104:      * This method must return a Symfony\Component\HttpFoudation\Response instance or the content of the response
105:      *
106:      */
107:     public function getContent()
108:     {
109:        $this->loadParser();
110:        
111:        return $this->content;
112:     }
113: 
114:     /**
115:      *
116:      * set $content with the body of the response or the Response object directly
117:      *
118:      * @param string|Symfony\Component\HttpFoundation\Response $content
119:      */
120:     public function setContent($content)
121:     {
122:         $this->content = $content;
123:     }
124: 
125:     /**
126:      *
127:      * @return type the status of the response
128:      */
129:     public function getStatus()
130:     {
131:         return $this->status;
132:     }
133: 
134:     /**
135:      *
136:      * status HTTP of the response
137:      *
138:      * @param int $status
139:      */
140:     public function setStatus($status)
141:     {
142:         $this->status = $status;
143:     }
144: 
145:     /**
146:      * Main parser function, load the parser
147:      */
148:     public function loadParser()
149:     {
150:         $content = $this->openFile($this->getRequest());
151:         
152:         $this->tpex->init($this->container->get("request"), $this->container->get("dispatcher"), $content, THELIA_TEMPLATE_DIR . rtrim($this->template, "/") . "/");
153:         $this->tpex->setLogger(Tlog::getInstance());
154:         $this->tpex->configure(
155:                 array(),
156:                 array(),
157:                 array(
158:                     "secure" => "Thelia\Core\Template\BaseParam\Secure"
159:                     )
160:                 );
161:         $this->setContent($this->tpex->execute());
162:     }
163:     
164:     protected function openFile(Request $request)
165:     {
166:         $file = $request->attributes->get('_view');
167:         $fileName = THELIA_TEMPLATE_DIR . rtrim($this->template, "/") . "/" . $file . ".html";
168:         if (file_exists($fileName)) {
169:             $content = file_get_contents($fileName);
170:         } else {
171:             throw new ResourceNotFoundException(sprintf("%s file not found in %s template", $file, $this->template));
172:         }
173:         
174:         return $content;
175:     }
176: }
177: 
thelia API documentation generated by ApiGen 2.8.0