X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=framework%2Fmain%2Fclasses%2Ftemplate%2Fimage%2Fclass_ImageTemplateEngine.php;h=e24d8cac936f2011ed2a76aa0900f99fc4222431;hb=f861d6bc00f8a3ecf6b057f2aa93129572643896;hp=19fc4848546bb3c2ac7476c9edbc84b3e20e4e55;hpb=3e5fae60e3629d3b12cef0bb786f1db7994044ab;p=core.git
diff --git a/framework/main/classes/template/image/class_ImageTemplateEngine.php b/framework/main/classes/template/image/class_ImageTemplateEngine.php
index 19fc4848..e24d8cac 100644
--- a/framework/main/classes/template/image/class_ImageTemplateEngine.php
+++ b/framework/main/classes/template/image/class_ImageTemplateEngine.php
@@ -1,17 +1,23 @@
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2023 Core Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.shipsimu.org
*
@@ -71,12 +77,17 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl
*/
private $currMainNode = '';
+ /**
+ * Instance of the image
+ */
+ private $imageInstance = NULL;
+
/**
* Protected constructor
*
* @return void
*/
- protected function __construct () {
+ private function __construct () {
// Call parent constructor
parent::__construct(__CLASS__);
}
@@ -96,18 +107,15 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl
$templateInstance = new ImageTemplateEngine();
// Get the application instance from registry
- $applicationInstance = Registry::getRegistry()->getInstance('app');
+ $applicationInstance = ApplicationHelper::getSelfInstance();
// 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)) {
// Base path is empty
throw new UnexpectedValueException(sprintf('[%s:%d] Variable templateBasePath is empty.', $templateInstance->__toString(), __LINE__), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
- } elseif (!is_string($templateBasePath)) {
- // Is not a string
- throw new UnexpectedValueException(sprintf('[%s:%d] %s is not a string with a base path.', $templateInstance->__toString(), __LINE__, $templateBasePath), self::EXCEPTION_INVALID_STRING);
} elseif (!is_dir($templateBasePath)) {
// Is not a path
throw new InvalidDirectoryException(array($templateInstance, $templateBasePath), self::EXCEPTION_INVALID_PATH_NAME);
@@ -120,13 +128,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
@@ -160,6 +168,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
*
@@ -169,7 +196,7 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl
* @return void
* @throws InvalidXmlNodeException If an unknown/invalid XML node name was found
*/
- public function startElement ($resource, $element, array $attributes) {
+ public function startElement ($resource, string $element, array $attributes) {
// Initial method name which will never be called...
$methodName = 'initImage';
@@ -180,13 +207,13 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl
//* DEBUG: */ echo "START: >".$element."<
\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([$this, $element, $attributes], Parseable::EXCEPTION_XML_NODE_UNKNOWN);
}
// Call method
@@ -202,25 +229,22 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl
* @return void
* @throws XmlNodeMismatchException If current main node mismatches the closing one
*/
- public function finishElement ($resource, $nodeName) {
- // Make all lower-case
- $nodeName = strtolower($nodeName);
-
+ public function finishElement ($resource, string $nodeName) {
// Does this match with current main node?
//* DEBUG: */ echo "END: >".$nodeName."<
\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), []);
}
/**
@@ -231,7 +255,7 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl
* @return void
* @todo Find something usefull with this!
*/
- public function characterHandler ($resource, $characters) {
+ public function characterHandler ($resource, string $characters) {
// Trim all spaces away
$characters = trim($characters);
@@ -239,10 +263,10 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl
if (empty($characters)) {
// Then skip it silently
return;
- } // END - if
+ }
// Unfinished work!
- $this->partialStub('Handling extra characters is not yet supported!');
+ DebugMiddleware::getSelfInstance()->partialStub('Handling extra characters is not yet supported!');
}
/**
@@ -261,7 +285,7 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl
* @param $imageType Code fragment or direct value holding the image type
* @return void
*/
- private function setImageType ($imageType) {
+ private function setImageType (string $imageType) {
// Set group to general
$this->setVariableGroup('general');
@@ -269,10 +293,10 @@ 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)));
+ $this->setImageInstance(ObjectFactory::createObjectByName($className, [$this]));
// Set current main node to type
$this->currMainNode = 'type';
@@ -341,7 +365,7 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl
* @return void
* @see ImageTemplateEngine::setImageResolution
*/
- private function setImageImageString ($groupable = 'single') {
+ private function setImageImageString (string $groupable = 'single') {
// Call the image class
$this->getImageInstance()->initImageString($groupable);
@@ -355,7 +379,7 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl
* @param $imageName Name of the image
* @return void
*/
- private function setImagePropertyName ($imageName) {
+ private function setImagePropertyName (string $imageName) {
// Call the image class
$this->getImageInstance()->setImageName($imageName);
}
@@ -366,7 +390,7 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl
* @param $width Width of the image or variable
* @return void
*/
- private function setImagePropertyWidth ($width) {
+ private function setImagePropertyWidth (int $width) {
// Call the image class
$this->getImageInstance()->setWidth($width);
}
@@ -377,7 +401,7 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl
* @param $height Height of the image or variable
* @return void
*/
- private function setImagePropertyHeight ($height) {
+ private function setImagePropertyHeight (int $height) {
// Call the image class
$this->getImageInstance()->setHeight($height);
}
@@ -421,7 +445,7 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl
* @param $stringName String name (identifier)
* @return void
*/
- private function setImagePropertyStringName ($stringName) {
+ private function setImagePropertyStringName (string $stringName) {
// Call the image class
$this->getImageInstance()->setStringName($stringName);
}
@@ -432,7 +456,7 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl
* @param $fontSize Size of the font
* @return void
*/
- private function setImagePropertyFontSize ($fontSize) {
+ private function setImagePropertyFontSize (int $fontSize) {
// Call the image class
$this->getImageInstance()->setFontSize($fontSize);
}
@@ -443,7 +467,7 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl
* @param $imageString Image string to set
* @return void
*/
- private function setImagePropertyText ($imageString) {
+ private function setImagePropertyText (string $imageString) {
// Call the image class
$this->getImageInstance()->setString($imageString);
}
@@ -454,7 +478,7 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl
* @param $x X coordinate
* @return void
*/
- private function setImagePropertyX ($x) {
+ private function setImagePropertyX (int $x) {
// Call the image class
$this->getImageInstance()->setX($x);
}
@@ -465,30 +489,30 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl
* @param $y Y coordinate
* @return void
*/
- private function setImagePropertyY ($y) {
+ private function setImagePropertyY (int $y) {
// Call the image class
$this->getImageInstance()->setY($y);
}
/**
- * Getter for image cache file (FQFN)
+ * Getter for image cache file instance
*
- * @return $fqfn Full-qualified file name of the image cache
+ * @return $fileInstance An instance of a SplFileInfo class
*/
- public function getImageCacheFqfn () {
- // Get the FQFN ready
- $fqfn = sprintf('%s%s%s/%s.%s',
- $this->getConfigInstance()->getConfigEntry('framework_base_path'),
+ public function getImageCacheFile () {
+ // Get the instance ready
+ $fileInstance = new SplFileInfo(sprintf('%s%s%s/%s.%s',
+ FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('root_base_path'),
$this->getGenericBasePath(),
'images/_cache',
md5(
$this->getImageInstance()->getImageName() . ':' . $this->__toString() . ':' . $this->getImageInstance()->__toString()
),
$this->getImageInstance()->getImageType()
- );
+ ));
// Return it
- return $fqfn;
+ return $fileInstance;
}
/**
@@ -496,6 +520,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
@@ -509,9 +534,9 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl
* located in 'image' by default
* @return void
*/
- public function loadImageTemplate ($template) {
+ public function loadImageTemplate (string $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);