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:
24: namespace Thelia\Tpex;
25:
26: use Symfony\Component\HttpFoundation\Request;
27: use Symfony\Component\EventDispatcher\EventDispatcherInterface;
28: use Psr\Log\LoggerInterface;
29:
30: use Thelia\Tpex\Loop\LoopInterface;
31:
32: class Tpex
33: {
34: /**
35: *
36: * $content contains string to parse
37: *
38: * @var string
39: */
40: protected $content;
41:
42: /**
43: *
44: * the base directory for searching all files for inclusion
45: *
46: * @var string
47: */
48: protected $basedir;
49:
50: /**
51: *
52: * @var Symfony\Component\HttpFoundation\Request
53: */
54: protected $request;
55:
56: /**
57: *
58: * @var Psr\Log\LoggerInterface
59: */
60: protected $logger;
61:
62: /**
63: *
64: * @var Symfony\Component\EventDispatcher\EventDispatcherInterface
65: */
66: protected $dispatcher;
67:
68: /**
69: * associative array containing information for loop execution
70: *
71: * key is loop name
72: * value is the class implementing/extending base loop classes
73: *
74: * ex :
75: *
76: * $loop = array(
77: * "product" => "Thelia\Loop\Product",
78: * "category" => "Thelia\Loop\Category",
79: * "myLoop" => "My\Own\Loop"
80: * );
81: *
82: * @var Array
83: */
84: protected $loop;
85:
86: /**
87: * associative array containing information for filter execution
88: *
89: * key is filter name
90: * value is the class implementing/extending base loop classes
91: *
92: * ex :
93: *
94: * $filter = array(
95: * "upperCase" => "Thelia\Filter\UpperCase",
96: * "lowerCase" => "Thelia\Filter\LowerCase",
97: * "myFilter" => "My\Own\Filter"
98: * );
99: *
100: * @var Array
101: */
102: protected $filter;
103: protected $substitution;
104:
105: protected $init;
106:
107: /**
108: *
109: * @param \Symfony\Component\HttpFoundation\Request $request
110: * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher
111: * @param string $content
112: * @param string $basedir
113: */
114: public function init(Request $request, EventDispatcherInterface $dispatcher, $content, $basedir)
115: {
116: $this->request = $request;
117: $this->dispatcher = $dispatcher;
118: $this->content = $content;
119: $this->basedir = $basedir;
120:
121: $this->init = true;
122: }
123:
124: public function setLogger(LoggerInterface $logger)
125: {
126: $this->logger = $logger;
127: }
128:
129: /**
130: *
131: * @param string $name loop name. Must be unique
132: * @param type $className class name that implementing/extending loop classes
133: * @throws \InvalidArgumentException
134: */
135: public function addLoop($name, $className)
136: {
137: //verify instance of className
138:
139: if (!isset($this->loop[$name])) {
140: $this->loop[$name] = $className;
141: } else {
142: throw new \InvalidArgumentException(sprintf("%s loop name already exists", $name));
143: }
144: }
145:
146:
147: public function execute()
148: {
149: if (true !== $this->init) {
150: throw new \RuntimeException("Tpex must be initialize before executing. See Thelia\Tpex\Tpex::init() for more information");
151: }
152: }
153: }
154: