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
$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();
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;
*/
private static $selfInstance = NULL;
+ /**
+ * Stub methods
+ */
+ private static $stubMethods = [
+ 'partialStub' => true,
+ '__call' => true,
+ '__callStatic' => true,
+ ];
+
/**
* The real class name
*/
$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'],
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;
$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
);
}
// 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;
// Import SPL stuff
use \SplFileInfo;
+use \SplFileObject;
/**
* A class for reading files
* 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
$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;
}
// 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;
// Import SPL stuff
use \SplFileInfo;
+use \SplFileObject;
/**
* A class for reading text files
* @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
$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;
}
// 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;
// Import SPL stuff
use \InvalidArgumentException;
use \SplFileInfo;
+use \SplFileObject;
use \OutOfBoundsException;
use \UnexpectedValueException;
// 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);
}
// 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
* 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;
}
*
* @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())) {
// 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;
// Import SPL stuff
use \InvalidArgumentException;
use \SplFileInfo;
+use \SplFileObject;
/**
* A class for writing files
* @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');
$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);
}
$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;
}
* @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())) {
*/
private $listIndex = [];
+ /**
+ * Cached values from "expensive" method calls
+ */
+ private $cache = [
+ // Cached isValidHash() calls
+ 'is_valid' => [],
+ ];
+
/**
* Protected constructor
*
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];
}
/**
$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
$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
$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
$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