From: Roland Häder Date: Thu, 16 Dec 2021 11:52:42 +0000 (+0100) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=d831713579377eaedd277b577dcd9c73040d0767;p=core.git Continued: - Better check against SplFileObject instead of is_object(). First one is a keyword (instanceof), later is a function call - More debug logging - Added missing "import" lines - Replaced more array() with [] Signed-off-by: Roland Häder --- diff --git a/framework/loader/class_ClassLoader.php b/framework/loader/class_ClassLoader.php index 8ce8488a..b19d5dc5 100644 --- a/framework/loader/class_ClassLoader.php +++ b/framework/loader/class_ClassLoader.php @@ -441,8 +441,8 @@ final class ClassLoader { return; } - // Keep it in class for later usage - $this->ignoreList = $ignoreList; + // Keep it in class for later usage, but flip index<->value + $this->ignoreList = array_flip($ignoreList); /* * Set base directory which holds all our classes, an absolute path @@ -474,7 +474,7 @@ final class ClassLoader { $fileName = $currentEntry->getFilename(); // Current entry must be a file, not smaller than 100 bytes and not on ignore list - if ((!$currentEntry->isFile()) || (in_array($fileName, $this->ignoreList)) || ($currentEntry->getSize() < 100)) { + if (!$currentEntry->isFile() || isset($this->ignoreList[$fileName]) || $currentEntry->getSize() < 100) { // Advance to next entry $iteratorInstance->next(); diff --git a/framework/main/classes/class_BaseFrameworkSystem.php b/framework/main/classes/class_BaseFrameworkSystem.php index 38a45f3d..96f05cdc 100644 --- a/framework/main/classes/class_BaseFrameworkSystem.php +++ b/framework/main/classes/class_BaseFrameworkSystem.php @@ -6,6 +6,7 @@ namespace Org\Mxchange\CoreFramework\Object; use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap; use Org\Mxchange\CoreFramework\EntryPoint\ApplicationEntryPoint; use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory; +use Org\Mxchange\CoreFramework\Filesystem\FileIoException; use Org\Mxchange\CoreFramework\Filesystem\PathWriteProtectedException; use Org\Mxchange\CoreFramework\Generic\FrameworkInterface; use Org\Mxchange\CoreFramework\Generic\NullPointerException; @@ -55,6 +56,15 @@ abstract class BaseFrameworkSystem extends stdClass implements FrameworkInterfac */ private static $selfInstance = NULL; + /** + * Stub methods + */ + private static $stubMethods = [ + 'partialStub' => true, + '__call' => true, + '__callStatic' => true, + ]; + /** * The real class name */ @@ -672,7 +682,7 @@ Loaded includes: $backtrace = debug_backtrace(!DEBUG_BACKTRACE_PROVIDE_OBJECT); // Is function partialStub/__callStatic ? - if (in_array($backtrace[1]['function'], array('partialStub', '__call', '__callStatic'))) { + if (isset(self::$stubMethods[$backtrace[1]['function']])) { // Prepend class::function:line from 3rd element $message = sprintf('[%s::%s:%d]: %s', $backtrace[2]['class'], diff --git a/framework/main/classes/database/backend/lfdb_legacy/class_CachedLocalFileDatabase.php b/framework/main/classes/database/backend/lfdb_legacy/class_CachedLocalFileDatabase.php index 1c652b90..400243d0 100644 --- a/framework/main/classes/database/backend/lfdb_legacy/class_CachedLocalFileDatabase.php +++ b/framework/main/classes/database/backend/lfdb_legacy/class_CachedLocalFileDatabase.php @@ -9,6 +9,7 @@ use Org\Mxchange\CoreFramework\Criteria\Local\LocalSearchCriteria; use Org\Mxchange\CoreFramework\Criteria\Storing\StoreableCriteria; use Org\Mxchange\CoreFramework\Database\Backend\BaseDatabaseBackend; use Org\Mxchange\CoreFramework\Database\Backend\DatabaseBackend; +use Org\Mxchange\CoreFramework\Database\Sql\SqlException; use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory; use Org\Mxchange\CoreFramework\Filesystem\FileNotFoundException; use Org\Mxchange\CoreFramework\Generic\FrameworkException; @@ -507,11 +508,15 @@ class CachedLocalFileDatabase extends BaseDatabaseBackend implements DatabaseBac $this->setLastException($e); // Throw an SQL exception - throw new SqlException(array( + throw new SqlException([ $this, - sprintf('Cannot write data to table '%s', is the table created?', $dataSetInstance->getTableName()), + sprintf('Cannot write data to table '%s', is the table created? e=%s,e->message=%s', + $dataSetInstance->getTableName(), + $e->__toString(), + $e->getMessage() + ), self::DB_CODE_TABLE_UNWRITEABLE - ), + ], self::EXCEPTION_SQL_QUERY ); } diff --git a/framework/main/classes/file_directories/input/raw/class_FrameworkRawFileInputPointer.php b/framework/main/classes/file_directories/input/raw/class_FrameworkRawFileInputPointer.php index 61fc5f12..c76d4fb9 100644 --- a/framework/main/classes/file_directories/input/raw/class_FrameworkRawFileInputPointer.php +++ b/framework/main/classes/file_directories/input/raw/class_FrameworkRawFileInputPointer.php @@ -5,6 +5,7 @@ namespace Org\Mxchange\CoreFramework\Filesystem\Pointer\Input; // Import framework stuff use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap; use Org\Mxchange\CoreFramework\Filesystem\BaseFileIo; +use Org\Mxchange\CoreFramework\Filesystem\FileIoException; use Org\Mxchange\CoreFramework\Filesystem\FileNotFoundException; use Org\Mxchange\CoreFramework\Filesystem\FileReadProtectedException; use Org\Mxchange\CoreFramework\Filesystem\Pointer\InputPointer; @@ -14,6 +15,7 @@ use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem; // Import SPL stuff use \SplFileInfo; +use \SplFileObject; /** * A class for reading files @@ -52,30 +54,34 @@ class FrameworkRawFileInputPointer extends BaseFileIo implements InputPointer { * Create a file pointer based on the given file. The file will also * be verified here. * - * @param $infoInstance An instance of a SplFileInfo class + * @param $fileInstance An instance of a SplFileInfo class * @throws FileIoException If the file is not reachable * @throws FileReadProtectedException If the file is not found or cannot be read * @throws FileNotFoundException If the file does not exist * @return void */ - public static final function createFrameworkRawFileInputPointer (SplFileInfo $infoInstance) { + public static final function createFrameworkRawFileInputPointer (SplFileInfo $fileInstance) { // Some pre-sanity checks... - if (!FrameworkBootstrap::isReachableFilePath($infoInstance)) { + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RAW-FILE-INPUT-POINTER: fileInstance[%s]=%s - CALLED!', get_class($fileInstance), $fileInstance->__toString())); + if (!FrameworkBootstrap::isReachableFilePath($fileInstance)) { // File cannot be accessed (due to open_basedir restriction) - throw new FileIoException($infoInstance, self::EXCEPTION_FILE_NOT_REACHABLE); - } elseif ((!FrameworkBootstrap::isReadableFile($infoInstance)) && (!$infoInstance->isFile())) { + throw new FileIoException($fileInstance, self::EXCEPTION_FILE_NOT_REACHABLE); + } elseif ((!FrameworkBootstrap::isReadableFile($fileInstance)) && (!$fileInstance->isFile())) { // File does not exist - throw new FileNotFoundException($infoInstance, self::EXCEPTION_FILE_NOT_FOUND); - } elseif ((!FrameworkBootstrap::isReadableFile($infoInstance)) && ($infoInstance->isFile())) { + throw new FileNotFoundException($fileInstance, self::EXCEPTION_FILE_NOT_FOUND); + } elseif ((!FrameworkBootstrap::isReadableFile($fileInstance)) && ($fileInstance->isFile())) { // File exists but cannot be read from - throw new FileReadProtectedException($infoInstance, self::EXCEPTION_FILE_CANNOT_BE_READ); + throw new FileReadProtectedException($fileInstance, self::EXCEPTION_FILE_CANNOT_BE_READ); } // Try to open a handler - $fileObject = $infoInstance->openFile('rb'); - if ((is_null($fileObject)) || ($fileObject === false)) { + $fileObject = $fileInstance->openFile('rb'); + + // Is it valid? + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RAW-FILE-INPUT-POINTER: fileObject[]=%s', gettype($fileObject))); + if (!($fileObject instanceof SplFileObject)) { // Something bad happend - throw new FileIoException($infoInstance, self::EXCEPTION_FILE_POINTER_INVALID); + throw new FileIoException($fileInstance, self::EXCEPTION_FILE_POINTER_INVALID); } // Create new instance @@ -85,6 +91,7 @@ class FrameworkRawFileInputPointer extends BaseFileIo implements InputPointer { $pointerInstance->setFileObject($fileObject); // Return the instance + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RAW-FILE-INPUT-POINTER: pointerInstance=%s - EXIT!', $pointerInstance->__toString())); return $pointerInstance; } diff --git a/framework/main/classes/file_directories/input/text/class_FrameworkTextFileInputPointer.php b/framework/main/classes/file_directories/input/text/class_FrameworkTextFileInputPointer.php index 27565cef..1a005043 100644 --- a/framework/main/classes/file_directories/input/text/class_FrameworkTextFileInputPointer.php +++ b/framework/main/classes/file_directories/input/text/class_FrameworkTextFileInputPointer.php @@ -5,6 +5,7 @@ namespace Org\Mxchange\CoreFramework\Filesystem\Pointer\Input; // Import framework stuff use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap; use Org\Mxchange\CoreFramework\Filesystem\BaseFileIo; +use Org\Mxchange\CoreFramework\Filesystem\FileIoException; use Org\Mxchange\CoreFramework\Filesystem\FileNotFoundException; use Org\Mxchange\CoreFramework\Filesystem\FileReadProtectedException; use Org\Mxchange\CoreFramework\Filesystem\Pointer\InputPointer; @@ -14,6 +15,7 @@ use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem; // Import SPL stuff use \SplFileInfo; +use \SplFileObject; /** * A class for reading text files @@ -57,29 +59,28 @@ class FrameworkTextFileInputPointer extends BaseFileIo implements InputPointer { * @throws FileReadProtectedException If the file cannot be read from * @return void */ - public static final function createFrameworkTextFileInputPointer (SplFileInfo $infoInstance) { + public static final function createFrameworkTextFileInputPointer (SplFileInfo $fileInstance) { // Check parameter - if (!FrameworkBootstrap::isReachableFilePath($infoInstance)) { + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RAW-FILE-INPUT-POINTER: fileInstance[%s]=%s - CALLED!', get_class($fileInstance), $fileInstance->__toString())); + if (!FrameworkBootstrap::isReachableFilePath($fileInstance)) { // File cannot be reached - throw new FileIoException($infoInstance, self::EXCEPTION_FILE_NOT_REACHABLE); - } elseif ((!FrameworkBootstrap::isReadableFile($infoInstance)) && (!$infoInstance->isFile())) { + throw new FileIoException($fileInstance, self::EXCEPTION_FILE_NOT_REACHABLE); + } elseif ((!FrameworkBootstrap::isReadableFile($fileInstance)) && (!$fileInstance->isFile())) { // File does not exist! - throw new FileNotFoundException($infoInstance, self::EXCEPTION_FILE_CANNOT_BE_READ); - } elseif ((!FrameworkBootstrap::isReadableFile($infoInstance)) && ($infoInstance->isFile())) { + throw new FileNotFoundException($fileInstance, self::EXCEPTION_FILE_CANNOT_BE_READ); + } elseif ((!FrameworkBootstrap::isReadableFile($fileInstance)) && ($fileInstance->isFile())) { // File cannot be read from (but exists) - throw new FileReadProtectedException($infoInstance, self::EXCEPTION_FILE_CANNOT_BE_READ); + throw new FileReadProtectedException($fileInstance, self::EXCEPTION_FILE_CANNOT_BE_READ); } // Try to open a handler - $fileObject = $infoInstance->openFile('r'); - - // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TEXT-FILE-INPUT: fileObject[]=' . gettype($fileObject)); + $fileObject = $fileInstance->openFile('r'); // Is it valid? - if ((is_null($fileObject)) || ($fileObject === false)) { + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TEXT-FILE-INPUT-POINTER: fileObject[]=%s', gettype($fileObject))); + if (!($fileObject instanceof SplFileObject)) { // Something bad happend - throw new FileIoException($infoInstance, self::EXCEPTION_FILE_POINTER_INVALID); + throw new FileIoException($fileInstance, self::EXCEPTION_FILE_POINTER_INVALID); } // Create new instance @@ -89,6 +90,7 @@ class FrameworkTextFileInputPointer extends BaseFileIo implements InputPointer { $pointerInstance->setFileObject($fileObject); // Return the instance + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TEXT-FILE-INPUT-POINTER: pointerInstance=%s - EXIT!', $pointerInstance->__toString())); return $pointerInstance; } diff --git a/framework/main/classes/file_directories/io/class_FrameworkFileInputOutputPointer.php b/framework/main/classes/file_directories/io/class_FrameworkFileInputOutputPointer.php index 5e77247a..6e0c5f30 100644 --- a/framework/main/classes/file_directories/io/class_FrameworkFileInputOutputPointer.php +++ b/framework/main/classes/file_directories/io/class_FrameworkFileInputOutputPointer.php @@ -5,6 +5,7 @@ namespace Org\Mxchange\CoreFramework\Filesystem\Pointer; // Import framework stuff use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap; use Org\Mxchange\CoreFramework\Filesystem\BaseFileIo; +use Org\Mxchange\CoreFramework\Filesystem\FileIoException; use Org\Mxchange\CoreFramework\Filesystem\FileReadProtectedException; use Org\Mxchange\CoreFramework\Filesystem\FileWriteProtectedException; use Org\Mxchange\CoreFramework\Filesystem\PathWriteProtectedException; @@ -15,6 +16,7 @@ use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem; // Import SPL stuff use \InvalidArgumentException; use \SplFileInfo; +use \SplFileObject; use \OutOfBoundsException; use \UnexpectedValueException; @@ -84,7 +86,7 @@ class FrameworkFileInputOutputPointer extends BaseFileIo implements InputOutputP // Is it valid? //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-INPUT-OUTPUT-POINTER: fileObject[]=%s', gettype($fileObject))); - if ((is_null($fileObject)) || ($fileObject === false)) { + if (!($fileObject instanceof SplFileObject)) { // Something bad happend throw new FileIoException($fileInstance->getPathname(), self::EXCEPTION_FILE_POINTER_INVALID); } diff --git a/framework/main/classes/file_directories/output/raw/class_FrameworkRawFileOutputPointer.php b/framework/main/classes/file_directories/output/raw/class_FrameworkRawFileOutputPointer.php index 2436b0f4..5432d96c 100644 --- a/framework/main/classes/file_directories/output/raw/class_FrameworkRawFileOutputPointer.php +++ b/framework/main/classes/file_directories/output/raw/class_FrameworkRawFileOutputPointer.php @@ -4,12 +4,14 @@ namespace Org\Mxchange\CoreFramework\Filesystem\Pointer\Output; // Import framework stuff use Org\Mxchange\CoreFramework\Filesystem\BaseFileIo; +use Org\Mxchange\CoreFramework\Filesystem\FileIoException; use Org\Mxchange\CoreFramework\Filesystem\Pointer\OutputPointer; use Org\Mxchange\CoreFramework\Generic\NullPointerException; // Import SPL stuff use \InvalidArgumentException; use \SplFileInfo; +use \SplFileObject; /** * A class for writing files @@ -48,33 +50,40 @@ class FrameworkRawFileOutputPointer extends BaseFileIo implements OutputPointer * Create a file pointer based on the given file. The file will also * be verified here. * - * @param $infoInstance An instance of a SplFileInfo class + * @param $fileInstance An instance of a SplFileInfo class * @param $mode The output mode ('w', 'a' are valid) + * @return void * @throws InvalidArgumentException If parameter mode is empty * @throws FileIoException If fopen() returns not a file resource - * @return void */ - public static final function createFrameworkRawFileOutputPointer (SplFileInfo $infoInstance, $mode) { - // Some pre-sanity checks... - if (is_null($mode)) { - // No infoInstance given + public static final function createFrameworkRawFileOutputPointer (SplFileInfo $fileInstance, string $mode) { + // Is the parameter valid? + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RAW-FILE-OUTPUT-POINTER: fileInstance=%s,mode=%s - CALLED!', $fileInstance->__toString(), $mode)); + if (empty($mode)) { + // No fileInstance given throw new InvalidArgumentException('Parameter "mode" is empty'); } // Try to open a handler - $fileObject = $infoInstance->openFile($mode); - if ((is_null($fileObject)) || ($fileObject === false)) { + $fileObject = $fileInstance->openFile($mode); + + // Is it valid? + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RAW-FILE-OUTPUT-POINTER: fileObject[]=%s', gettype($fileObject))); + if (!($fileObject instanceof SplFileObject)) { // Something bad happend - throw new FileIoException($infoInstance, self::EXCEPTION_FILE_POINTER_INVALID); + throw new FileIoException($fileInstance, self::EXCEPTION_FILE_POINTER_INVALID); } // Create new instance + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('RAW-FILE-OUTPUT-POINTER: Creating pointer instance ...'); $pointerInstance = new FrameworkRawFileOutputPointer(); // Set file pointer and file name + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RAW-FILE-OUTPUT-POINTER: pointerInstance=%s,fileObject=%s', $pointerInstance->__toString(), $fileObject->__toString())); $pointerInstance->setFileObject($fileObject); // Return the instance + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RAW-FILE-OUTPUT-POINTER: pointerInstance=%s - EXIT!', $pointerInstance->__toString())); return $pointerInstance; } @@ -83,11 +92,16 @@ class FrameworkRawFileOutputPointer extends BaseFileIo implements OutputPointer * * @param $dataStream The data stream we shall write to the file * @return mixed Number of writes bytes or false on error + * @throws InvalidArgumentException If a parameter is invalid * @throws NullPointerException If the file pointer instance is not set by setFileObject() * @throws LogicException If there is no object being set */ public function writeToFile (string $dataStream) { - if (is_null($this->getFileObject())) { + // Validate parameter and class own attributes + if (empty($dataStream)) { + // Empty data stream + throw new InvalidArgumentException('Parameter "dataStream" is empty'); + } elseif (is_null($this->getFileObject())) { // Pointer not initialized throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); } elseif (!is_object($this->getFileObject())) { diff --git a/framework/main/classes/file_directories/output/text/class_FrameworkTextFileOutputPointer.php b/framework/main/classes/file_directories/output/text/class_FrameworkTextFileOutputPointer.php index 33aa707c..5ba31449 100644 --- a/framework/main/classes/file_directories/output/text/class_FrameworkTextFileOutputPointer.php +++ b/framework/main/classes/file_directories/output/text/class_FrameworkTextFileOutputPointer.php @@ -4,6 +4,7 @@ namespace Org\Mxchange\CoreFramework\Filesystem\Pointer\Text; // Import framework stuff use Org\Mxchange\CoreFramework\Filesystem\BaseFileIo; +use Org\Mxchange\CoreFramework\Filesystem\FileIoException; use Org\Mxchange\CoreFramework\Filesystem\Pointer\OutputPointer; use Org\Mxchange\CoreFramework\Generic\NullPointerException; use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException; @@ -11,6 +12,7 @@ use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException; // Import SPL stuff use \InvalidArgumentException; use \SplFileInfo; +use \SplFileObject; /** * A class for writing files @@ -55,8 +57,9 @@ class FrameworkTextFileOutputPointer extends BaseFileIo implements OutputPointer * @throws FileIoException If fopen() returns not a file resource * @return void */ - public static final function createFrameworkTextFileOutputPointer (SplFileInfo $fileInstance, $mode) { + public static final function createFrameworkTextFileOutputPointer (SplFileInfo $fileInstance, string $mode) { // Some pre-sanity checks... + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TEXT-FILE-OUTPUT-POINTER: fileInstance[%s]=%s,mode=%s - CALLED!', get_class($fileInstance), $fileInstance->__toString(), $mode)); if (empty($mode)) { // No filename given throw new InvalidArgumentException('Parameter "mode" is empty'); @@ -66,7 +69,8 @@ class FrameworkTextFileOutputPointer extends BaseFileIo implements OutputPointer $fileObject = $fileInstance->openFile($mode); // Is it valid? - if ((is_null($fileObject)) || ($fileObject === false)) { + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TEXT-FILE-OUTPUT-POINTER: fileObject[]=%s', gettype($fileObject))); + if (!($fileObject instanceof SplFileObject)) { // Something bad happend throw new FileIoException($fileInstance, self::EXCEPTION_FILE_POINTER_INVALID); } @@ -78,6 +82,7 @@ class FrameworkTextFileOutputPointer extends BaseFileIo implements OutputPointer $pointerInstance->setFileObject($fileObject); // Return the instance + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TEXT-FILE-OUTPUT-POINTER: pointerInstance=%s - EXIT!', $pointerInstance->__toString())); return $pointerInstance; } @@ -90,7 +95,12 @@ class FrameworkTextFileOutputPointer extends BaseFileIo implements OutputPointer * @throws LogicException If there is no object being set */ public function writeToFile (string $dataStream) { - if (is_null($this->getFileObject())) { + // Validate parameter + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TEXT-FILE-OUTPUT-POINTER: dataStream=%s - CALLED!', $dataStream)); + if (empty($dataStream)) { + // Invalid parameter + throw new InvalidArgumentException('Parameter "dataStream" is empty'); + } elseif (is_null($this->getFileObject())) { // Pointer not initialized throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); } elseif (!is_object($this->getFileObject())) { diff --git a/framework/main/classes/lists/class_BaseList.php b/framework/main/classes/lists/class_BaseList.php index c1ac982e..edca181d 100644 --- a/framework/main/classes/lists/class_BaseList.php +++ b/framework/main/classes/lists/class_BaseList.php @@ -61,6 +61,14 @@ abstract class BaseList extends BaseFrameworkSystem implements IteratorAggregate */ private $listIndex = []; + /** + * Cached values from "expensive" method calls + */ + private $cache = [ + // Cached isValidHash() calls + 'is_valid' => [], + ]; + /** * Protected constructor * @@ -403,13 +411,13 @@ abstract class BaseList extends BaseFrameworkSystem implements IteratorAggregate if (empty($hash)) { // Throw IAE throw new InvalidArgumentException('Parameter "hash" is empty'); + } elseif (!isset($this->cache['is_valid'][$hash])) { + // Check it + $this->cache['is_valid'][$hash] = ((in_array($hash, $this->listIndex)) && (isset($this->listEntries[$hash]))); } - // Check it - $isValid = ((in_array($hash, $this->listIndex)) && (isset($this->listEntries[$hash]))); - // Return the result - return $isValid; + return $this->cache['is_valid'][$hash]; } /** diff --git a/framework/main/classes/template/image/class_ImageTemplateEngine.php b/framework/main/classes/template/image/class_ImageTemplateEngine.php index 80a81446..43ffa77e 100644 --- a/framework/main/classes/template/image/class_ImageTemplateEngine.php +++ b/framework/main/classes/template/image/class_ImageTemplateEngine.php @@ -212,7 +212,7 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl $methodName = 'setImageProperty' . StringUtils::convertToClassName($element); } elseif ($element != 'image') { // Invalid node name found - throw new InvalidXmlNodeException(array($this, $element, $attributes), Parseable::EXCEPTION_XML_NODE_UNKNOWN); + throw new InvalidXmlNodeException([$this, $element, $attributes], Parseable::EXCEPTION_XML_NODE_UNKNOWN); } // Call method diff --git a/framework/main/classes/template/mail/class_MailTemplateEngine.php b/framework/main/classes/template/mail/class_MailTemplateEngine.php index 44dfeb05..401dfca8 100644 --- a/framework/main/classes/template/mail/class_MailTemplateEngine.php +++ b/framework/main/classes/template/mail/class_MailTemplateEngine.php @@ -183,7 +183,7 @@ class MailTemplateEngine extends BaseTemplateEngine implements CompileableTempla $methodName = 'setEmailProperty' . StringUtils::convertToClassName($element); } elseif ($element != 'text-mail') { // Invalid node name found - throw new InvalidXmlNodeException(array($this, $element, $attributes), Parseable::EXCEPTION_XML_NODE_UNKNOWN); + throw new InvalidXmlNodeException([$this, $element, $attributes], Parseable::EXCEPTION_XML_NODE_UNKNOWN); } // Call method diff --git a/framework/main/classes/template/menu/class_MenuTemplateEngine.php b/framework/main/classes/template/menu/class_MenuTemplateEngine.php index a16b9de5..b6b1f7f2 100644 --- a/framework/main/classes/template/menu/class_MenuTemplateEngine.php +++ b/framework/main/classes/template/menu/class_MenuTemplateEngine.php @@ -301,7 +301,7 @@ class MenuTemplateEngine extends BaseTemplateEngine implements CompileableTempla $methodName = 'start' . StringUtils::convertToClassName($element); } elseif ($element != 'menu') { // Invalid node name found - throw new InvalidXmlNodeException(array($this, $element, $attributes), Parseable::EXCEPTION_XML_NODE_UNKNOWN); + throw new InvalidXmlNodeException([$this, $element, $attributes], Parseable::EXCEPTION_XML_NODE_UNKNOWN); } // Call method diff --git a/framework/main/classes/template/xml/class_BaseXmlTemplateEngine.php b/framework/main/classes/template/xml/class_BaseXmlTemplateEngine.php index cbbf4a73..6175b9c7 100644 --- a/framework/main/classes/template/xml/class_BaseXmlTemplateEngine.php +++ b/framework/main/classes/template/xml/class_BaseXmlTemplateEngine.php @@ -328,7 +328,7 @@ abstract class BaseXmlTemplateEngine extends BaseTemplateEngine implements Compi $methodName = 'start' . StringUtils::convertToClassName($element); } else { // Invalid node name found - throw new InvalidXmlNodeException(array($this, $element, $attributes), XmlParser::EXCEPTION_XML_NODE_UNKNOWN); + throw new InvalidXmlNodeException([$this, $element, $attributes], XmlParser::EXCEPTION_XML_NODE_UNKNOWN); } // Call method