class_ImageTemplateEngine.php
Go to the documentation of this file.00001 <?php
00024 class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTemplate {
00028 private $mainNodes = array("base", "type", "resolution", "background-color", "foreground-color", "image-string");
00029
00033 private $subNodes = array("name", "string-name", "x", "y", "font-size", "width", "height", "red", "green", "blue", "text");
00034
00038 private $imageInstance = null;
00039
00043 private $currMainNode = "";
00044
00050 protected function __construct () {
00051
00052 parent::__construct(__CLASS__);
00053 }
00054
00069 public final static function createImageTemplateEngine ($basePath, ManageableLanguage $langInstance, FileIoHandler $ioInstance) {
00070
00071 $tplInstance = new ImageTemplateEngine();
00072
00073
00074 if (empty($basePath)) {
00075
00076 throw new BasePathIsEmptyException($tplInstance, self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
00077 } elseif (!is_string($basePath)) {
00078
00079 throw new InvalidBasePathStringException(array($tplInstance, $basePath), self::EXCEPTION_INVALID_STRING);
00080 } elseif (!is_dir($basePath)) {
00081
00082 throw new BasePathIsNoDirectoryException(array($tplInstance, $basePath), self::EXCEPTION_INVALID_PATH_NAME);
00083 } elseif (!is_readable($basePath)) {
00084
00085 throw new BasePathReadProtectedException(array($tplInstance, $basePath), self::EXCEPTION_READ_PROTECED_PATH);
00086 }
00087
00088
00089 $cfgInstance = FrameworkConfiguration::getInstance();
00090
00091
00092 $tplInstance->setBasePath($basePath);
00093
00094
00095 $tplInstance->setLanguageInstance($langInstance);
00096 $tplInstance->setFileIoInstance($ioInstance);
00097
00098
00099 $tplInstance->setRawTemplateExtension($cfgInstance->readConfig('raw_template_extension'));
00100 $tplInstance->setCodeTemplateExtension($cfgInstance->readConfig('code_template_extension'));
00101
00102
00103 $tplInstance->setCompileOutputPath($cfgInstance->readConfig('base_path') . $cfgInstance->readConfig('compile_output_path'));
00104
00105
00106 return $tplInstance;
00107 }
00108
00114 public final function getCurrMainNode () {
00115 return $this->currMainNode;
00116 }
00117
00123 public final function getMainNodes () {
00124 return $this->mainNodes;
00125 }
00126
00132 public final function getSubNodes () {
00133 return $this->subNodes;
00134 }
00135
00145 public function startElement ($resource, $element, array $attributes) {
00146
00147 $methodName = 'initImage';
00148
00149
00150 $element = strtolower($element);
00151
00152
00153
00154 if (in_array($element, $this->mainNodes)) {
00155
00156 $methodName = 'setImage' . $this->convertToClassName($element);
00157 } elseif (in_array($element, $this->subNodes)) {
00158
00159 $methodName = 'setImageProperty' . $this->convertToClassName($element);
00160 } elseif ($element != 'image') {
00161
00162 throw new InvalidXmlNodeException(array($this, $element, $attributes), BaseHelper::EXCEPTION_XML_NODE_UNKNOWN);
00163 }
00164
00165
00166
00167 call_user_func_array(array($this, $methodName), $attributes);
00168 }
00169
00178 protected function endElement ($resource, $nodeName) {
00179
00180 $nodeName = strtolower($nodeName);
00181
00182
00183
00184 if (($nodeName != $this->getCurrMainNode()) && (in_array($nodeName, $this->getMainNodes()))) {
00185
00186 throw new XmlNodeMismatchException (array($this, $nodeName, $this->getCurrMainNode()), BaseHelper::EXCEPTION_XML_NODE_MISMATCH);
00187 } elseif (in_array($nodeName, $this->getSubNodes())) {
00188
00189 return;
00190 }
00191
00192
00193 $methodName = 'finish' . $this->convertToClassName($nodeName);
00194
00195
00196 call_user_func_array(array($this->imageInstance, $methodName), array());
00197 }
00198
00207 protected function characterHandler ($resource, $characters) {
00208
00209 $characters = trim($characters);
00210
00211
00212 if (empty($characters)) {
00213
00214 return false;
00215 }
00216
00217
00218 $this->partialStub("Handling extra characters is not yet supported!");
00219 }
00220
00227 private function initImage () {
00228
00229 }
00230
00237 private function setImageType ($imageType) {
00238
00239 $this->setVariableGroup('general');
00240
00241
00242 $imageType = $this->compileRawCode($imageType);
00243
00244
00245 $className = $this->convertToClassName($imageType.'_image');
00246
00247
00248 $this->imageInstance = ObjectFactory::createObjectByName($className, array($this));
00249
00250
00251 $this->currMainNode = 'type';
00252 }
00253
00260 private function setImageResolution () {
00261
00262 $this->imageInstance->initResolution();
00263
00264
00265 $this->currMainNode = 'resolution';
00266 }
00267
00274 private function setImageBase () {
00275
00276 $this->imageInstance->initBase();
00277
00278
00279 $this->currMainNode = 'base';
00280 }
00281
00288 private function setImageBackgroundColor () {
00289
00290 $this->imageInstance->initBackgroundColor();
00291
00292
00293 $this->currMainNode = 'background-color';
00294 }
00295
00302 private function setImageForegroundColor () {
00303
00304 $this->imageInstance->initForegroundColor();
00305
00306
00307 $this->currMainNode = 'foreground-color';
00308 }
00309
00317 private function setImageImageString ($groupable = 'single') {
00318
00319 $this->imageInstance->initImageString($groupable);
00320
00321
00322 $this->currMainNode = 'image-string';
00323 }
00324
00331 private function setImagePropertyName ($imageName) {
00332
00333 $this->imageInstance->setImageName($imageName);
00334 }
00335
00342 private function setImagePropertyWidth ($width) {
00343
00344 $this->imageInstance->setWidth($width);
00345 }
00346
00353 private function setImagePropertyHeight ($height) {
00354
00355 $this->imageInstance->setHeight($height);
00356 }
00357
00364 private function setImagePropertyRed ($red) {
00365
00366 $this->imageInstance->setRed($red);
00367 }
00368
00375 private function setImagePropertyGreen ($green) {
00376
00377 $this->imageInstance->setGreen($green);
00378 }
00379
00386 private function setImagePropertyBlue ($blue) {
00387
00388 $this->imageInstance->setBlue($blue);
00389 }
00390
00397 private function setImagePropertyStringName ($stringName) {
00398
00399 $this->imageInstance->setStringName($stringName);
00400 }
00401
00408 private function setImagePropertyFontSize ($fontSize) {
00409
00410 $this->imageInstance->setFontSize($fontSize);
00411 }
00412
00419 private function setImagePropertyText ($imageString) {
00420
00421 $this->imageInstance->setString($imageString);
00422 }
00423
00430 private function setImagePropertyX ($x) {
00431
00432 $this->imageInstance->setX($x);
00433 }
00434
00441 private function setImagePropertyY ($y) {
00442
00443 $this->imageInstance->setY($y);
00444 }
00445
00451 public function getImageCacheFqfn () {
00452
00453 $fqfn = $this->getBasePath().'_cache/' . md5($this->imageInstance->getImageName().":".$this->__toString().":".$this->imageInstance->__toString()) . "." . $this->imageInstance->getImageType();
00454
00455
00456 return $fqfn;
00457 }
00458
00465 public function transferToResponse (Responseable $responseInstance) {
00466
00467 $responseInstance->setImageInstance($this->imageInstance);
00468 }
00469 }
00470
00471
00472 ?>