]> git.mxchange.org Git - core.git/blobdiff - framework/main/classes/template/image/class_ImageTemplateEngine.php
Continued:
[core.git] / framework / main / classes / template / image / class_ImageTemplateEngine.php
index 637faad68173136e023e0c86eec7e8deb9f0120b..d01ec650e400b105b3eb6925f07949a575d3f103 100644 (file)
@@ -3,13 +3,16 @@
 namespace Org\Mxchange\CoreFramework\Template\Engine;
 
 // Import framework stuff
+use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
 use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
 use Org\Mxchange\CoreFramework\Filesystem\InvalidDirectoryException;
-use Org\Mxchange\CoreFramework\Parser\Xml\XmlParser;
-use Org\Mxchange\CoreFramework\Registry\Registry;
+use Org\Mxchange\CoreFramework\Image\BaseImage;
+use Org\Mxchange\CoreFramework\Parser\Parseable;
+use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
 use Org\Mxchange\CoreFramework\Response\Responseable;
 use Org\Mxchange\CoreFramework\Template\CompileableTemplate;
 use Org\Mxchange\CoreFramework\Template\Engine\BaseTemplateEngine;
+use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
 
 // Import SPL stuff
 use \SplFileInfo;
@@ -20,7 +23,7 @@ use \UnexpectedValueException;
  *
  * @author             Roland Haeder <webmaster@shipsimu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.shipsimu.org
  *
@@ -72,6 +75,11 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl
         */
        private $currMainNode = '';
 
+       /**
+        * Instance of the image
+        */
+       private $imageInstance = NULL;
+
        /**
         * Protected constructor
         *
@@ -97,10 +105,10 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl
                $templateInstance = new ImageTemplateEngine();
 
                // Get the application instance from registry
-               $applicationInstance = Registry::getRegistry()->getInstance('app');
+               $applicationInstance = GenericRegistry::getRegistry()->getInstance('application');
 
                // Determine base path
-               $templateBasePath = $templateInstance->getConfigInstance()->getConfigEntry('application_base_path') . $applicationInstance->getAppShortName(). '/';
+               $templateBasePath = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('application_base_path') . $applicationInstance->getAppShortName(). '/';
 
                // Is the base path valid?
                if (empty($templateBasePath)) {
@@ -121,13 +129,13 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl
                $templateInstance->setTemplateBasePath($templateBasePath);
 
                // Set template extensions
-               $templateInstance->setRawTemplateExtension($templateInstance->getConfigInstance()->getConfigEntry('raw_template_extension'));
-               $templateInstance->setCodeTemplateExtension($templateInstance->getConfigInstance()->getConfigEntry('code_template_extension'));
+               $templateInstance->setRawTemplateExtension(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('raw_template_extension'));
+               $templateInstance->setCodeTemplateExtension(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('code_template_extension'));
 
                // Absolute output path for compiled templates
                $templateInstance->setCompileOutputPath(sprintf('%s%s/',
                        $templateBasePath,
-                       $templateInstance->getConfigInstance()->getConfigEntry('compile_output_path')
+                       FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('compile_output_path')
                ));
 
                // Return the prepared instance
@@ -161,6 +169,25 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl
                return $this->subNodes;
        }
 
+       /**
+        * Setter for image instance
+        *
+        * @param       $imageInstance  An instance of an image
+        * @return      void
+        */
+       public final function setImageInstance (BaseImage $imageInstance) {
+               $this->imageInstance = $imageInstance;
+       }
+
+       /**
+        * Getter for image instance
+        *
+        * @return      $imageInstance  An instance of an image
+        */
+       public final function getImageInstance () {
+               return $this->imageInstance;
+       }
+
        /**
         * Handles the start element of an XML resource
         *
@@ -181,13 +208,13 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl
                //* DEBUG: */ echo "START: &gt;".$element."&lt;<br />\n";
                if (in_array($element, $this->mainNodes)) {
                        // Okay, main node found!
-                       $methodName = 'setImage' . self::convertToClassName($element);
+                       $methodName = 'setImage' . StringUtils::convertToClassName($element);
                } elseif (in_array($element, $this->subNodes)) {
                        // Sub node found
-                       $methodName = 'setImageProperty' . self::convertToClassName($element);
+                       $methodName = 'setImageProperty' . StringUtils::convertToClassName($element);
                } elseif ($element != 'image') {
                        // Invalid node name found
-                       throw new InvalidXmlNodeException(array($this, $element, $attributes), XmlParser::EXCEPTION_XML_NODE_UNKNOWN);
+                       throw new InvalidXmlNodeException(array($this, $element, $attributes), Parseable::EXCEPTION_XML_NODE_UNKNOWN);
                }
 
                // Call method
@@ -211,17 +238,17 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl
                //* DEBUG: */ echo "END: &gt;".$nodeName."&lt;<br />\n";
                if (($nodeName != $this->getCurrMainNode()) && (in_array($nodeName, $this->getMainNodes()))) {
                        // Did not match!
-                       throw new XmlNodeMismatchException (array($this, $nodeName, $this->getCurrMainNode()), XmlParser::EXCEPTION_XML_NODE_MISMATCH);
+                       throw new XmlNodeMismatchException (array($this, $nodeName, $this->getCurrMainNode()), Parseable::EXCEPTION_XML_NODE_MISMATCH);
                } elseif (in_array($nodeName, $this->getSubNodes())) {
                        // Silently ignore sub nodes
                        return;
                }
 
                // Construct method name
-               $methodName = 'finish' . self::convertToClassName($nodeName);
+               $methodName = sprintf('finish%s', StringUtils::convertToClassName($nodeName));
 
                // Call the corresponding method
-               call_user_func_array(array($this->getImageInstance(), $methodName), array());
+               call_user_func_array(array($this->getImageInstance(), $methodName), []);
        }
 
        /**
@@ -270,7 +297,7 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl
                $imageType = $this->compileRawCode($imageType);
 
                // Now make a class name of it
-               $className = self::convertToClassName($imageType.'_image');
+               $className = StringUtils::convertToClassName($imageType.'_image');
 
                // And try to initiate it
                $this->setImageInstance(ObjectFactory::createObjectByName($className, array($this)));
@@ -479,7 +506,7 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl
        public function getImageCacheFile () {
                // Get the instance ready
                $fileInstance = new SplFileInfo(sprintf('%s%s%s/%s.%s',
-                       $this->getConfigInstance()->getConfigEntry('framework_base_path'),
+                       FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('root_base_path'),
                        $this->getGenericBasePath(),
                        'images/_cache',
                        md5(
@@ -497,6 +524,7 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl
         *
         * @param       $responseInstance       An instance of a Responseable class
         * @return      void
+        * @todo        Nothing to really "transfer" here?
         */
        public function transferToResponse (Responseable $responseInstance) {
                // Set the image instance
@@ -512,7 +540,7 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl
         */
        public function loadImageTemplate ($template) {
                // Set template type
-               $this->setTemplateType($this->getConfigInstance()->getConfigEntry('image_template_type'));
+               $this->setTemplateType(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('image_template_type'));
 
                // Load the special template
                $this->loadTemplate($template);