1: <?php
2:
3: 4: 5: 6: 7: 8:
9:
10: namespace XSLTBenchmarking\TestsGenerator;
11:
12: require_once LIBS . '/PhpPath/PhpPath.min.php';
13: require_once ROOT . '/Exceptions.php';
14:
15: use PhpPath\P;
16:
17: 18: 19: 20: 21:
22: class Test
23: {
24:
25: 26: 27: 28: 29:
30: private $name;
31:
32: 33: 34: 35: 36:
37: private $templatePath;
38:
39: 40: 41: 42: 43:
44: private $templatingType;
45:
46: 47: 48: 49: 50:
51: private $path;
52:
53: 54: 55: 56: 57:
58: private $settings = array();
59:
60: 61: 62: 63: 64: 65:
66: private $filesPaths = array();
67:
68:
69: 70: 71: 72: 73:
74: private $paramsFilePath;
75:
76:
77: 78: 79: 80: 81:
82: public function __construct($name)
83: {
84: $this->name = $name;
85: }
86:
87:
88: 89: 90: 91: 92:
93: public function getName()
94: {
95: return $this->name;
96: }
97:
98:
99: 100: 101: 102: 103: 104: 105:
106: public function setTemplatePath($templatePath)
107: {
108: $templatePath = P::mcf($templatePath);
109:
110: $basename = basename($templatePath);
111: $parts = explode('.', $basename);
112: $partsCount = count($parts);
113: if ($partsCount < 3 ||
114: ($parts[$partsCount - 2] != 'tpl') ||
115: ($parts[$partsCount - 1] != 'xsl' && $parts[$partsCount - 1] != 'xslt'))
116: {
117: throw new \XSLTBenchmarking\InvalidArgumentException('Template path does not have extension ".tpl.xsl" or ".tpl.xslt". It has value "' . $templatePath . '"');
118: }
119:
120: $this->templatePath = $templatePath;
121: }
122:
123:
124: 125: 126: 127: 128:
129: public function getTemplatePath()
130: {
131: return $this->templatePath;
132: }
133:
134:
135: 136: 137: 138: 139: 140: 141:
142: public function setTemplatingType($templatingType)
143: {
144: $this->templatingType = $templatingType;
145: }
146:
147:
148: 149: 150: 151: 152:
153: public function getTemplatingType()
154: {
155: return $this->templatingType;
156: }
157:
158:
159: 160: 161: 162: 163: 164: 165:
166: public function setPath($rootPath)
167: {
168: $name = $this->name;
169: $name = strtolower(trim($name));
170: $name = preg_replace('/[^a-z0-9-_]/', '-', $name);
171: $name = preg_replace('/-+/', '-', $name);
172:
173: $this->path = P::m($rootPath, $name);
174: }
175:
176:
177: 178: 179: 180: 181:
182: public function getPath()
183: {
184: return $this->path;
185: }
186:
187:
188: 189: 190: 191: 192:
193: public function getXsltName()
194: {
195:
196: $basename = basename($this->getTemplatePath());
197: $parts = explode('.', $basename);
198: unset($parts[count($parts) - 2]);
199: $xsltName = implode('.', $parts);
200:
201: return $xsltName;
202: }
203:
204:
205: 206: 207: 208: 209:
210: public function getXsltPath()
211: {
212: return P::m($this->getPath(), $this->getXsltName());
213: }
214:
215:
216: 217: 218: 219: 220: 221: 222:
223: public function addSettings(array $settings)
224: {
225: $this->settings = array_merge($this->settings, $settings);
226: }
227:
228:
229: 230: 231: 232: 233:
234: public function getSettings()
235: {
236: return $this->settings;
237: }
238:
239:
240: 241: 242: 243: 244: 245: 246: 247:
248: public function addFilesPaths(array $filesPaths)
249: {
250: foreach ($filesPaths as $input => $output)
251: {
252: $inputExtension = pathinfo($input, PATHINFO_EXTENSION);
253: if ($inputExtension != 'xml')
254: {
255: throw new \XSLTBenchmarking\InvalidArgumentException('XSLT template path does not have extension ".xml". It has value "' . $input . '"');
256: }
257: $this->filesPaths[P::mcf($input)] = P::mcf($output);
258: }
259: }
260:
261:
262: 263: 264: 265: 266: 267:
268: public function getFilesPaths()
269: {
270: return $this->filesPaths;
271: }
272:
273:
274: 275: 276: 277: 278: 279: 280:
281: public function setParamsFilePath($fileName)
282: {
283: $this->paramsFilePath = P::m($this->getPath(), $fileName);
284: }
285:
286:
287: 288: 289: 290: 291:
292: public function getParamsFilePath()
293: {
294: return $this->paramsFilePath;
295: }
296:
297:
298: }
299: