-# Use Linux/Uni* line-feed for new lines (prevents converting)
-* text=lf
+#
+### Distribute this file on all GIT projects!
+#
+# Autodetect text files
+* text=auto
+
+# Force the following filetypes to have unix eols, so Windows does not break them
+*.* text eol=lf
+
+# Force images/fonts to be handled as binaries
+*.jpg binary
+*.jpeg binary
+*.gif binary
+*.png binary
+*.t3x binary
+*.t3d binary
+*.exe binary
+*.data binary
+*.ttf binary
+*.eof binary
+*.eot binary
+*.swf binary
+*.mov binary
+*.mp4 binary
+*.mp3 binary
+*.ogg binary
+*.flv binary
+*.jar binary
+*.pdf binary
+*.woff* binary
+*.otf binary
+*.z binary
+*.docx binary
// Import SPL stuff
use \BadMethodCallException;
use \InvalidArgumentException;
+use \SplFileInfo;
/**
* A framework-bootstrap class which helps the frameworks to bootstrap ... ;-)
* gurantee that the file is actually readable and/or writeable. If you need
* such gurantee then please use isReadableFile() instead.
*
- * @param $filePathName Name of the file/path to be checked
+ * @param $fileInstance An instance of a SplFileInfo class
* @return $isReachable Whether it is within open_basedir()
*/
- public static function isReachableFilePath ($filePathName) {
+ public static function isReachableFilePath (SplFileInfo $fileInstance) {
// Is not reachable by default
$isReachable = false;
// Get open_basedir parameter
- $openBaseDir = ini_get('open_basedir');
+ $openBaseDir = trim(ini_get('open_basedir'));
// Is it set?
if (!empty($openBaseDir)) {
// Check all entries
foreach (explode(PATH_SEPARATOR, $openBaseDir) as $dir) {
// Check on existence
- if (substr($filePathName, 0, strlen($dir)) == $dir) {
+ if (substr($fileInstance->getPathname(), 0, strlen($dir)) == $dir) {
// Is reachable
$isReachable = true;
+
+ // Abort lookup as it has been found in open_basedir
+ break;
} // END - if
} // END - foreach
} else {
* Checks whether the give file is within open_basedir() (done by
* isReachableFilePath()), is actually a file and is readable.
*
- * @param $fileName Name of the file to be checked
+ * @param $fileInstance An instance of a SplFileInfo class
* @return $isReadable Whether the file is readable (and therefor exists)
*/
- public static function isReadableFile ($fileName) {
+ public static function isReadableFile (SplFileInfo $fileInstance) {
// Default is not readable
$isReadable = false;
- // Is within parameters, so check if it is a file and readable
+ // Check if it is a file and readable
$isReadable = (
(
- self::isReachableFilePath($fileName)
- ) && (
- file_exists($fileName)
+ self::isReachableFilePath($fileInstance)
) && (
- is_file($fileName)
+ $fileInstance->isFile()
) && (
- is_readable($fileName)
+ $fileInstance->isReadable()
)
);
/**
* Loads given include file
*
- * @param $fqfn Include's FQFN
+ * @param $fileInstance An instance of a SplFileInfo class
* @return void
- * @throws InvalidArgumentException If $fqfn was not found or not readable or deprecated
+ * @throws InvalidArgumentException If file was not found or not readable or deprecated
*/
- public static function loadInclude ($fqfn) {
+ public static function loadInclude (SplFileInfo $fileInstance) {
// Trace message
- //* NOISY-DEBUG: */ printf('[%s:%d]: fqfn=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $fqfn);
+ //* NOISY-DEBUG: */ printf('[%s:%d]: fileInstance=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $fileInstance);
// Should be there ...
- if (!self::isReadableFile($fqfn)) {
+ if (!self::isReadableFile($fileInstance)) {
// Abort here
- throw new InvalidArgumentException(sprintf('Cannot find fqfn=%s.', $fqfn));
+ throw new InvalidArgumentException(sprintf('Cannot find fileInstance.pathname=%s.', $fileInstance->getPathname()));
} // END - if
// Load it
- require $fqfn;
+ require $fileInstance->getPathname();
// Trace message
//* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__);
*/
public static function doBootstrap () {
// Load basic include files to continue bootstrapping
- self::loadInclude(sprintf('%smain%sinterfaces%sclass_FrameworkInterface.php', ApplicationEntryPoint::detectFrameworkPath(), DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR));
- self::loadInclude(sprintf('%smain%sinterfaces%sregistry%sclass_Registerable.php', ApplicationEntryPoint::detectFrameworkPath(), DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR));
- self::loadInclude(sprintf('%sconfig%sclass_FrameworkConfiguration.php', ApplicationEntryPoint::detectFrameworkPath(), DIRECTORY_SEPARATOR));
+ self::loadInclude(new SplFileInfo(sprintf('%smain%sinterfaces%sclass_FrameworkInterface.php', ApplicationEntryPoint::detectFrameworkPath(), DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR)));
+ self::loadInclude(new SplFileInfo(sprintf('%smain%sinterfaces%sregistry%sclass_Registerable.php', ApplicationEntryPoint::detectFrameworkPath(), DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR)));
+ self::loadInclude(new SplFileInfo(sprintf('%sconfig%sclass_FrameworkConfiguration.php', ApplicationEntryPoint::detectFrameworkPath(), DIRECTORY_SEPARATOR)));
// Load global configuration
- self::loadInclude(sprintf('%s%s', ApplicationEntryPoint::detectFrameworkPath(), 'config-global.php'));
+ self::loadInclude(new SplFileInfo(sprintf('%s%s', ApplicationEntryPoint::detectFrameworkPath(), 'config-global.php')));
}
/**
* warning at the user.
*/
foreach (self::$configAppIncludes as $fileName => $status) {
- // Construct FQFN
- $fqfn = sprintf('%s%s.php', $fullPath, $fileName);
+ // Construct file instance
+ $fileInstance = new SplFileInfo(sprintf('%s%s.php', $fullPath, $fileName));
// Determine if this file is wanted/readable/deprecated
- if (($status == 'required') && (!self::isReadableFile($fqfn))) {
+ if (($status == 'required') && (!self::isReadableFile($fileInstance))) {
// Nope, required file cannot be found/read from
- ApplicationEntryPoint::exitApplication(sprintf('Application "%s" does not have required file "%s.php". Please add it.', $application, $fileName));
- } elseif ((file_exists($fqfn)) && (!is_readable($fqfn))) {
+ ApplicationEntryPoint::exitApplication(sprintf('Application "%s" does not have required file "%s.php". Please add it.', $application, $fileInstance->getBasename()));
+ } elseif (($fileInstance->isFile()) && (!$fileInstance->isReadable())) {
// Found, not readable file
- ApplicationEntryPoint::exitApplication(sprintf('File "%s.php" from application "%s" cannot be read. Please fix CHMOD.', $fileName, $application));
- } elseif (($status != 'required') && (!self::isReadableFile($fqfn))) {
+ ApplicationEntryPoint::exitApplication(sprintf('File "%s.php" from application "%s" cannot be read. Please fix CHMOD.', $fileInstance->getBasename(), $application));
+ } elseif (($status != 'required') && (!self::isReadableFile($fileInstance))) {
// Not found but optional/deprecated file, skip it
continue;
}
} // END - if
// Load it
- self::loadInclude($fqfn);
+ self::loadInclude($fileInstance);
} // END - foreach
// Scan for application's classes, exceptions and interfaces
// Some sanity checks
if ((empty($applicationInstance)) || (is_null($applicationInstance))) {
// Something went wrong!
- ApplicationEntryPoint::exitApplication(sprintf("[Main:] The application <span class=\"app_name\">%s</span> could not be launched because the helper class <span class=\"class_name\">%s</span> is not loaded.",
+ ApplicationEntryPoint::exitApplication(sprintf('[Main:] The application <span class="app_name">%s</span> could not be launched because the helper class <span class="class_name">%s</span> is not loaded.',
$application,
'CoreFramework\Helper\Application\ApplicationHelper'
));
} elseif (!is_object($applicationInstance)) {
// No object!
- ApplicationEntryPoint::exitApplication(sprintf("[Main:] The application <span class=\"app_name\">%s</span> could not be launched because 'app' is not an object (%s).",
+ ApplicationEntryPoint::exitApplication(sprintf('[Main:] The application <span class="app_name">%s</span> could not be launched because 'app' is not an object (%s).',
$application,
gettype($applicationInstance)
));
} elseif (!($applicationInstance instanceof ManageableApplication)) {
// Missing interface
- ApplicationEntryPoint::exitApplication(sprintf("[Main:] The application <span class=\"app_name\">%s</span> could not be launched because 'app' is lacking required interface ManageableApplication.",
+ ApplicationEntryPoint::exitApplication(sprintf('[Main:] The application <span class="app_name">%s</span> could not be launched because 'app' is lacking required interface ManageableApplication.',
$application
));
}
// Call method
call_user_func(array($applicationInstance, $methodName));
- } // END - if
+ } // END - foreach
}
/**
return $success;
}
- /**
- * Detects the HTTPS flag
- *
- * @return $https The detected HTTPS flag or null if failed
- */
- public static function detectHttpSecured () {
- // Default is null
- $https = NULL;
-
- // Is HTTPS set?
- if (self::isHttpSecured()) {
- // Then use it
- $https = $_SERVER['HTTPS'];
- } // END - if
-
- // Return it
- return $https;
- }
-
/**
* Checks whether HTTPS is set in $_SERVER
*
} // END - if
// Construct the full URL and secure it against CSRF attacks
- $baseUrl = $protocol . '://' . self::detectDomain() . self::detectScriptPath();
+ $baseUrl = sprintf('%s://%s%s', $protocol, self::detectDomain(), self::detectScriptPath());
// Return the URL
return $baseUrl;
use \InvalidArgumentException;
use \RecursiveDirectoryIterator;
use \RecursiveIteratorIterator;
+use \SplFileInfo;
/**
* This class loads class include files with a specific prefix and suffix
private $classesCached = false;
/**
- * Filename for the list cache
+ * SplFileInfo for the list cache
*/
- private $listCacheFQFN = '';
+ private $listCacheFile = NULL;
/**
- * Cache for class content
+ * SplFileInfo for class content
*/
- private $classCacheFQFN = '';
+ private $classCacheFile = NULL;
/**
* Counter for loaded include files
if ($this->listCached === false) {
// Writes the cache file of our list away
$cacheContent = json_encode($this->foundClasses);
- file_put_contents($this->listCacheFQFN, $cacheContent);
+
+ // Open cache instance
+ $fileObject = $this->listCacheFile->openFile('w');
+
+ // And write whole list
+ $fileObject->fwrite($cacheContent);
} // END - if
// Skip here if already cached
if ($this->classesCached === false) {
// Generate a full-cache of all classes
$cacheContent = '';
- foreach (array_keys($this->loadedClasses) as $fqfn) {
+ foreach (array_keys($this->loadedClasses) as $fileInstance) {
+ // Open file
+ $fileObject = $fileInstance->openFile('r');
+
// Load the file
- $cacheContent .= file_get_contents($fqfn);
+ // @TODO Add some uglifying code (compress) here
+ $cacheContent .= $fileObject->fread($fileInstance->getSize());
} // END - foreach
+ // Open file
+ $fileObject = $this->classCacheFile->openFile('w');
+
// And write it away
- file_put_contents($this->classCacheFQFN, $cacheContent);
+ $fileObject->fwrite($cacheContent);
} // END - if
}
// Get filename from iterator which is the class' name (according naming-convention)
$fileName = $currentEntry->getFileName();
- // Get the "FQFN" (path and file name)
- $fqfn = $currentEntry->getRealPath();
-
// Current entry must be a file, not smaller than 100 bytes and not on ignore list
- if ((!$currentEntry->isFile()) || (in_array($fileName, $this->ignoreList)) || (filesize($fqfn) < 100)) {
+ if ((!$currentEntry->isFile()) || (in_array($fileName, $this->ignoreList)) || ($currentEntry->getSize() < 100)) {
// Advance to next entry
$iteratorInstance->next();
//* NOISY-DEBUG: */ printf('[%s:%d] FOUND: %s' . PHP_EOL, __METHOD__, __LINE__, $fileName);
if ((substr($fileName, 0, strlen($this->prefix)) == $this->prefix) && (substr($fileName, -strlen($this->suffix), strlen($this->suffix)) == $this->suffix)) {
// Add it to the list
- //* NOISY-DEBUG: */ printf('[%s:%d] ADD: %s,fqfn=%s' . PHP_EOL, __METHOD__, __LINE__, $fileName, $fqfn);
- $this->foundClasses[$fileName] = $fqfn;
+ //* NOISY-DEBUG: */ printf('[%s:%d] ADD: %s,currentEntry=%s' . PHP_EOL, __METHOD__, __LINE__, $fileName, $currentEntry);
+ $this->foundClasses[$fileName] = $currentEntry;
} else {
// Not added
- //* NOISY-DEBUG: */ printf('[%s:%d] NOT ADDED: %s,fqfn=%s' . PHP_EOL, __METHOD__, __LINE__, $fileName, $fqfn);
+ //* NOISY-DEBUG: */ printf('[%s:%d] NOT ADDED: %s,currentEntry=%s' . PHP_EOL, __METHOD__, __LINE__, $fileName, $currentEntry);
}
// Advance to next entry
// Construct the FQFN for the cache
if (!defined('DEVELOPER')) {
- $this->listCacheFQFN = $this->configInstance->getConfigEntry('local_database_path') . 'list-' . $this->configInstance->getConfigEntry('detected_app_name') . '.cache';
- $this->classCacheFQFN = $this->configInstance->getConfigEntry('local_database_path') . 'class-' . $this->configInstance->getConfigEntry('detected_app_name') . '.cache';
+ $this->listCacheFile = new SplFileInfo($this->configInstance->getConfigEntry('local_database_path') . 'list-' . $this->configInstance->getConfigEntry('detected_app_name') . '.cache');
+ $this->classCacheFile = new SplFileInfo($this->configInstance->getConfigEntry('local_database_path') . 'class-' . $this->configInstance->getConfigEntry('detected_app_name') . '.cache');
} // END - if
// Set suffix and prefix from configuration
return;
} // END - if
- // IS the cache there?
- if (FrameworkBootstrap::isReadableFile($this->listCacheFQFN)) {
+ // Is the cache there?
+ if (FrameworkBootstrap::isReadableFile($this->listCacheFile)) {
// Load and convert it
- $this->foundClasses = json_decode(file_get_contents($this->listCacheFQFN));
+ $this->foundClasses = json_decode(file_get_contents($this->listCacheFile->getPathname()));
// List has been restored from cache!
$this->listCached = true;
} // END - if
// Does the class cache exist?
- if (FrameworkBootstrap::isReadableFile($this->listCacheFQFN)) {
+ if (FrameworkBootstrap::isReadableFile($this->classCacheFile)) {
// Then include it
- FrameworkBootstrap::loadInclude($this->classCacheFQFN);
+ FrameworkBootstrap::loadInclude($this->classCacheFile);
// Mark the class cache as loaded
$this->classesCached = true;
$shortClassName = array_pop($classNameParts);
// Create a name with prefix and suffix
- $fileName = $this->prefix . $shortClassName . $this->suffix;
+ $fileName = sprintf('%s%s%s', $this->prefix, $shortClassName, $this->suffix);
// Now look it up in our index
//* NOISY-DEBUG: */ printf('[%s:%d] ISSET: %s' . PHP_EOL, __METHOD__, __LINE__, $fileName);
- if ((isset($this->foundClasses[$fileName])) && (!isset($this->loadedClasses[$this->foundClasses[$fileName]]))) {
+ if ((isset($this->foundClasses[$fileName])) && (!isset($this->loadedClasses[$this->foundClasses[$fileName]->getPathname()]))) {
// File is found and not loaded so load it only once
//* NOISY-DEBUG: */ printf('[%s:%d] LOAD: %s - START' . PHP_EOL, __METHOD__, __LINE__, $fileName);
FrameworkBootstrap::loadInclude($this->foundClasses[$fileName]);
$this->total++;
// Mark this class as loaded for other purposes than loading it.
- $this->loadedClasses[$this->foundClasses[$fileName]] = true;
+ $this->loadedClasses[$this->foundClasses[$fileName]->getPathname()] = true;
// Remove it from classes list so it won't be found twice.
//* NOISY-DEBUG: */ printf('[%s:%d] UNSET: %s' . PHP_EOL, __METHOD__, __LINE__, $fileName);
use \stdClass;
use \Iterator;
use \ReflectionClass;
+use \SplFileInfo;
/**
* The simulator system class is the super class of all other classes. This
* Creates a full-qualified file name (FQFN) for given file name by adding
* a configured temporary file path to it.
*
- * @param $fileName Name for temporary file
- * @return $fqfn Full-qualified file name
+ * @param $infoInstance An instance of a SplFileInfo class
+ * @return $tempInstance An instance of a SplFileInfo class (temporary file)
* @throw PathWriteProtectedException If the path in 'temp_file_path' is write-protected
* @throws FileIoException If the file cannot be written
*/
- protected static function createTempPathForFile ($fileName) {
+ protected static function createTempPathForFile (SplFileInfo $infoInstance) {
// Get config entry
$basePath = FrameworkConfiguration::getSelfInstance()->getConfigEntry('temp_file_path');
// Is the path writeable?
if (!is_writable($basePath)) {
// Path is write-protected
- throw new PathWriteProtectedException($fileName, self::EXCEPTION_PATH_CANNOT_BE_WRITTEN);
+ throw new PathWriteProtectedException($infoInstance, self::EXCEPTION_PATH_CANNOT_BE_WRITTEN);
} // END - if
// Add it
- $fqfn = $basePath . DIRECTORY_SEPARATOR . $fileName;
+ $tempInstance = new SplFileInfo($basePath . DIRECTORY_SEPARATOR . $infoInstance->getBasename());
// Is it reachable?
- if (!FrameworkBootstrap::isReachableFilePath($fqfn)) {
+ if (!FrameworkBootstrap::isReachableFilePath($tempInstance)) {
// Not reachable
- throw new FileIoException($fqfn, self::EXCEPTION_FILE_NOT_REACHABLE);
+ throw new FileIoException($tempInstance, self::EXCEPTION_FILE_NOT_REACHABLE);
} // END - if
// Return it
- return $fqfn;
+ return $tempInstance;
}
/**
use CoreFramework\Filesystem\FileNotFoundException;
use CoreFramework\Generic\FrameworkException;
+// Import SPL stuff
+use \SplFileInfo;
+
/**
* Database backend class for storing objects in locally created files.
*
/**
* Setter for the last read file
*
- * @param $fqfn The FQFN of the last read file
+ * @param $infoInstance The FQFN of the last read file
* @return void
*/
- private final function setLastFile ($fqfn) {
+ private final function setLastFile (SplFileInfo $infoInstance) {
// Cast string and set it
- $this->lastFile = (string) $fqfn;
+ $this->lastFile = $infoInstance;
}
/**
/**
* Reads a local data file and returns it's contents in an array
*
- * @param $fqfn The FQFN for the requested file
+ * @param $infoInstance An instance of a SplFileInfo class
* @return $dataArray
*/
- private function getDataArrayFromFile ($fqfn) {
+ private function getDataArrayFromFile (SplFileInfo $infoInstance) {
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DATABASE: Reading elements from database file ' . $fqfn . ' ...');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DATABASE: Reading elements from database file ' . $infoInstance . ' ...');
// Init compressed data
- $compressedData = $this->getFileIoInstance()->loadFileContents($fqfn);
+ $compressedData = $this->getFileIoInstance()->loadFileContents($infoInstance);
$compressedData = $compressedData['data'];
- // Close the file and throw the instance away
- unset($fileInstance);
-
// Decompress it
$serializedData = $this->getCompressorChannel()->getCompressor()->decompressStream($compressedData);
$dataArray = json_decode($serializedData, true);
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DATABASE: Read ' . count($dataArray) . ' elements from database file ' . $fqfn . '.');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DATABASE: Read ' . count($dataArray) . ' elements from database file ' . $infoInstance . '.');
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DATABASE: dataArray=' . print_r($dataArray, true));
// Finally return it
/**
* Writes data array to local file
*
- * @param $fqfn The FQFN of the local file
+ * @param $infoInstance An instance of a SplFileInfo class
* @param $dataArray An array with all the data we shall write
* @return void
*/
- private function writeDataArrayToFqfn ($fqfn, array $dataArray) {
+ private function writeDataArrayToFqfn (SplFileInfo $infoInstance, array $dataArray) {
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DATABASE: Flushing ' . count($dataArray) . ' elements to database file ' . $fqfn . ' ...');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DATABASE: Flushing ' . count($dataArray) . ' elements to database file ' . $infoInstance . ' ...');
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DATABASE: dataArray=' . print_r($dataArray, true));
// Serialize and compress it
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DATABASE: Writing ' . strlen($compressedData) . ' bytes ...');
// Write this data BASE64 encoded to the file
- $this->getFileIoInstance()->saveStreamToFile($fqfn, $compressedData, $this);
+ $this->getFileIoInstance()->saveStreamToFile($infoInstance, $compressedData, $this);
// Debug message
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DATABASE: Flushing ' . count($dataArray) . ' elements to database file completed.');
$infoArray = array();
// Create FQFN for getting the table information file
- $fqfn = $this->generateFqfnFromDataSet($dataSetInstance, 'info');
+ $infoInstance = $this->generateFileFromDataSet($dataSetInstance, 'info');
// Get the file contents
try {
- $infoArray = $this->getDataArrayFromFile($fqfn);
+ $infoArray = $this->getDataArrayFromFile($infoInstance);
} catch (FileNotFoundException $e) {
// Not found, so ignore it here
}
}
/**
- * Generates an FQFN from given dataset instance and string
+ * Generates a file info class from given dataset instance and string
*
* @param $dataSetInstance An instance of a database set class
* @param $rowName Name of the row
- * @return $fqfn The FQFN for this row
+ * @return $infoInstance An instance of a SplFileInfo class
*/
- private function generateFqfnFromDataSet (Criteria $dataSetInstance, $rowName) {
- // This is the FQFN
- $fqfn = $this->getConfigInstance()->getConfigEntry('local_database_path') . $dataSetInstance->getTableName() . DIRECTORY_SEPARATOR . $rowName . '.' . $this->getFileExtension();
+ private function generateFileFromDataSet (Criteria $dataSetInstance, $rowName) {
+ // Instanciate new file object
+ $infoInstance = new SplFileInfo($this->getConfigInstance()->getConfigEntry('local_database_path') . $dataSetInstance->getTableName() . DIRECTORY_SEPARATOR . $rowName . '.' . $this->getFileExtension());
// Return it
- return $fqfn;
+ return $infoInstance;
}
/**
*/
private function createTableInfoFile (StoreableCriteria $dataSetInstance) {
// Create FQFN for creating the table information file
- $fqfn = $this->generateFqfnFromDataSet($dataSetInstance, 'info');
+ $infoInstance = $this->generateFileFromDataSet($dataSetInstance, 'info');
// Get the data out from dataset in a local array
$this->tableInfo[$dataSetInstance->getTableName()] = array(
);
// Write the data to the file
- $this->writeDataArrayToFqfn($fqfn, $this->tableInfo[$dataSetInstance->getTableName()]);
+ $this->writeDataArrayToFqfn($infoInstance, $this->tableInfo[$dataSetInstance->getTableName()]);
}
/**
$tableName = $dataSetInstance->getTableName();
// Create FQFN for creating the table information file
- $fqfn = $this->generateFqfnFromDataSet($dataSetInstance, 'info');
+ $infoInstance = $this->generateFileFromDataSet($dataSetInstance, 'info');
// Get the data out from dataset in a local array
$this->tableInfo[$tableName]['primary'] = $dataSetInstance->getPrimaryKey();
$this->tableInfo[$tableName]['last_updated'] = time();
// Write the data to the file
- $this->writeDataArrayToFqfn($fqfn, $this->tableInfo[$tableName]);
+ $this->writeDataArrayToFqfn($infoInstance, $this->tableInfo[$tableName]);
}
/**
// Try to save the request away
try {
// Create full path name
- $fqfn = $this->generateFqfnFromDataSet($dataSetInstance, md5($dataSetInstance->getUniqueValue()));
+ $infoInstance = $this->generateFileFromDataSet($dataSetInstance, md5($dataSetInstance->getUniqueValue()));
// Write the data away
- $this->writeDataArrayToFqfn($fqfn, $dataSetInstance->getCriteriaArray());
+ $this->writeDataArrayToFqfn($infoInstance, $dataSetInstance->getCriteriaArray());
// Update the primary key
$this->updatePrimaryKey($dataSetInstance);
use CoreFramework\Registry\Registry;
use CoreFramework\Stacker\Index\IndexableStack;
+// Import SPL stuff
+use \SplFileInfo;
+
/**
* A factory class for file-based stack indexes
*
/**
* Returns a singleton (registry-based) StackableFile instance
*
- * @param $stackName Name of the stack's file
- * @return $indexInstance An instance of a IndexableStack class
+ * @param $infoInstance An instance of a SplFileInfo class
+ * @return $indexInstance An instance of a IndexableStack class
*/
- public static final function createFileStackIndexInstance ($fileName, $type) {
+ public static final function createFileStackIndexInstance (SplFileInfo $infoInstance, $type) {
// If there is no handler?
if (Registry::getRegistry()->instanceExists($type . '_index')) {
// Get handler from registry
$indexInstance = Registry::getRegistry()->getInstance($type . '_index');
} else {
// Get the handler instance
- $indexInstance = self::createObjectByConfiguredName($type . '_file_stack_index_class', array($fileName));
+ $indexInstance = self::createObjectByConfiguredName($type . '_file_stack_index_class', array($infoInstance));
// Add check for interface
assert($indexInstance instanceof IndexableStack);
use CoreFramework\Filesystem\Block\CalculatableBlock;
use CoreFramework\Filesystem\File\BaseAbstractFile;
+// Import SPL stuff
+use \SplFileInfo;
+
/**
* A general binary file class
*
/**
* Initializes this file class
*
- * @param $fileName Name of this abstract file
+ * @param $infoInstance An instance of a SplFileInfo class
* @return void
*/
- protected function initFile ($fileName) {
+ protected function initFile (SplFileInfo $infoInstance) {
// Get a file i/o pointer instance
- $pointerInstance = ObjectFactory::createObjectByConfiguredName('file_raw_input_output_class', array($fileName));
+ $pointerInstance = ObjectFactory::createObjectByConfiguredName('file_raw_input_output_class', array($infoInstance));
// ... and set it here
$this->setPointerInstance($pointerInstance);
use CoreFramework\Filesystem\File\BaseBinaryFile;
use CoreFramework\Generic\UnsupportedOperationException;
+// Import SPL stuff
+use \SplFileInfo;
+
/**
* A stack file class
*
/**
* Creates an instance of this File class and prepares it for usage
*
- * @param $fileName Name of the stack file
+ * @param $infoInstance An instance of a SplFileInfo class
* @param $blockInstance An instance of a Block class
* @return $fileInstance An instance of this File class
*/
- public final static function createStackFile ($fileName, Block $blockInstance) {
+ public final static function createStackFile (SplFileInfo $infoInstance, Block $blockInstance) {
// Get a new instance
$fileInstance = new StackFile();
$fileInstance->setBlockInstance($blockInstance);
// Init this abstract file
- $fileInstance->initFile($fileName);
+ $fileInstance->initFile($infoInstance);
// Return the prepared instance
return $fileInstance;
*/
private $totalEntries = 0;
- /**
- * The current file we are working in
- */
- private $fileName = '';
-
/**
* Protected constructor
*
}
/**
- * Getter for the file pointer
+ * Getter for the file object
*
- * @return $filePointer The file pointer which shall be a valid file resource
+ * @return $fileObject An instance of a SplFileObject
* @throws UnsupportedOperationException If this method is called
*/
- public final function getPointer () {
+ public final function getFileObject () {
throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
}
- /**
- * Setter for file name
- *
- * @param $fileName The new file name
- * @return void
- */
- protected final function setFileName ($fileName) {
- $fileName = (string) $fileName;
- $this->fileName = $fileName;
- }
-
- /**
- * Getter for file name
- *
- * @return $fileName The current file name
- */
- public final function getFileName () {
- return $this->fileName;
- }
-
/**
* Close a file source and set it's instance to null and the file name
* to empty
*/
public function closeFile () {
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: fileName=%s - CALLED!', __METHOD__, __LINE__, $this->getFileName()));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: CALLED!', __METHOD__, __LINE__));
// Close down pointer instance as well by unsetting it
$this->unsetPointerInstance();
- // Remove file name
- $this->setFileName('');
-
// Debug message
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: EXIT!', __METHOD__, __LINE__));
}
use CoreFramework\Generic\NullPointerException;
use CoreFramework\Object\BaseFrameworkSystem;
+// Import SPL stuff
+use \SplFileObject;
+
/**
* A general FileIo class
*
*/
class BaseFileIo extends BaseFrameworkSystem implements FilePointer, CloseableFile {
/**
- * The current file we are working in
+ * The file object
*/
- private $fileName = '';
-
- /**
- * The file pointer
- */
- private $filePointer = NULL;
+ private $fileObject = NULL;
/**
* Protected constructor
*/
public final function __destruct() {
// Is there a resource pointer? Then we have to close the file here!
- if (is_resource($this->getPointer())) {
+ if (is_object($this->getFileObject())) {
// Try to close a file
$this->closeFile();
} // END - if
*
* @return void
* @throws NullPointerException If the file pointer instance is not set by setPointer()
- * @throws InvalidResourceException If there is being set
+ * @throws LogicException If there is no object being set
*/
public function closeFile () {
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: fileName=%s - CALLED!', __METHOD__, __LINE__, $this->getFileName()));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: fileName=%s - CALLED!', __METHOD__, __LINE__, $this->getFileObject()->getPathname()));
- if (is_null($this->getPointer())) {
+ if (is_null($this->getFileObject())) {
// Pointer not initialized
throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
- } elseif (!is_resource($this->getPointer())) {
+ } elseif (!is_object($this->getFileObject())) {
// Pointer is not a valid resource!
- throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE);
+ throw new LogicException(sprintf('this->fileObject[]=%s is no object', gettype($this->getFileObject())));
}
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: Closing file %s ...', __METHOD__, __LINE__, $this->getFileName()));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: Closing file %s ...', __METHOD__, __LINE__, $this->getFileObject()->getPathname()));
- // Close the file pointer and reset the instance variable
- @fclose($this->getPointer());
- $this->setPointer(NULL);
- $this->setFileName('');
+ // Close the file pointer by NULL-ing it
+ $this->resetFileObject();
// Debug message
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: EXIT!', __METHOD__, __LINE__));
}
/**
- * Setter for the file pointer
+ * Resets file object instance to NULL
*
- * @param $filePointer File resource
* @return void
*/
- protected final function setPointer ($filePointer) {
- $this->filePointer = $filePointer;
- }
-
- /**
- * Getter for the file pointer
- *
- * @return $filePointer The file pointer which shall be a valid file resource
- */
- public final function getPointer () {
- return $this->filePointer;
+ protected final function resetFileObject () {
+ // Set it to NULL
+ $this->fileObject = NULL;
}
/**
- * Setter for file name
+ * Setter for the file object
*
- * @param $fileName The new file name
+ * @param $fileObject An instance of a SplFileObject class
* @return void
*/
- protected final function setFileName ($fileName) {
- $fileName = (string) $fileName;
- $this->fileName = $fileName;
+ protected final function setFileObject (SplFileObject $fileObject) {
+ $this->fileObject = $fileObject;
}
/**
- * Getter for file name
+ * Getter for the file object
*
- * @return $fileName The current file name
+ * @return $fileObject An instance of a SplFileObject class
*/
- public final function getFileName () {
- return $this->fileName;
+ public final function getFileObject () {
+ return $this->fileObject;
}
/**
* @return $seekPosition Current seek position
*/
public final function determineSeekPosition () {
- return ftell($this->getPointer());
+ return $this->getFileObject()->ftell();
}
/**
* @return $isEndOfFileReached Whether the EOF has been reached
*/
public final function isEndOfFileReached () {
- return feof($this->getPointer());
+ return $this->getFileObject()->feof();
}
/**
*/
public function seek ($offset, $whence = SEEK_SET) {
// Seek to position
- $status = fseek($this->getPointer(), $offset, $whence);
+ $status = $this->getFileObject()->fseek($offset, $whence);
// Return status
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] status=%d', __METHOD__, __LINE__, $status));
use CoreFramework\Generic\UnsupportedOperationException;
use CoreFramework\Object\BaseFrameworkSystem;
+// Import SPL stuff
+use \SplFileInfo;
+
/**
* A class for reading files
*
* Create a file pointer based on the given file. The file will also
* be verified here.
*
- * @param $fileName The file name we shall pass to fopen()
- * @throws FileIsEmptyException If the provided file name is empty.
+ * @param $infoInstance 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 ($fileName) {
+ public static final function createFrameworkRawFileInputPointer (SplFileInfo $infoInstance) {
// Some pre-sanity checks...
- if ((is_null($fileName)) || (empty($fileName))) {
- // No filename given
- throw new FileIsEmptyException(NULL, self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
- } elseif (!FrameworkBootstrap::isReachableFilePath($fileName)) {
+ if (!FrameworkBootstrap::isReachableFilePath($infoInstance)) {
// File cannot be accessed (due to open_basedir restriction)
- throw new FileIoException($fileName, self::EXCEPTION_FILE_NOT_REACHABLE);
- } elseif ((!FrameworkBootstrap::isReadableFile($fileName)) && (file_exists($fileName))) {
- // File exists but cannot be read from
- throw new FileReadProtectedException($fileName, self::EXCEPTION_FILE_CANNOT_BE_READ);
- } elseif ((!FrameworkBootstrap::isReadableFile($fileName)) && (!file_exists($fileName))) {
+ throw new FileIoException($infoInstance, self::EXCEPTION_FILE_NOT_REACHABLE);
+ } elseif ((!FrameworkBootstrap::isReadableFile($infoInstance)) && (!$infoInstance->isFile())) {
// File does not exist
- throw new FileNotFoundException($fileName, self::EXCEPTION_FILE_NOT_FOUND);
+ throw new FileNotFoundException($infoInstance, self::EXCEPTION_FILE_NOT_FOUND);
+ } elseif ((!FrameworkBootstrap::isReadableFile($infoInstance)) && ($infoInstance->isFile())) {
+ // File exists but cannot be read from
+ throw new FileReadProtectedException($infoInstance, self::EXCEPTION_FILE_CANNOT_BE_READ);
}
// Try to open a handler
- $filePointer = fopen($fileName, 'rb');
- if ((is_null($filePointer)) || ($filePointer === false)) {
+ $fileObject = $infoInstance->openFile('rb');
+ if ((is_null($fileObject)) || ($fileObject === false)) {
// Something bad happend
- throw new FileIoException($fileName, self::EXCEPTION_FILE_POINTER_INVALID);
+ throw new FileIoException($infoInstance, self::EXCEPTION_FILE_POINTER_INVALID);
} // END - if
// Create new instance
$pointerInstance = new FrameworkRawFileInputPointer();
// Set file pointer and file name
- $pointerInstance->setPointer($filePointer);
- $pointerInstance->setFileName($fileName);
+ $pointerInstance->setFileObject($fileObject);
// Return the instance
return $pointerInstance;
* Read data a file pointer
*
* @return mixed The result of fread()
- * @throws NullPointerException If the file pointer instance
- * is not set by setPointer()
- * @throws InvalidResourceException If there is being set
+ * @throws NullPointerException If the file pointer instance is not set by setPointer()
+ * @throws LogicException If there is no object being set
*/
public function readFromFile () {
- if (is_null($this->getPointer())) {
+ if (is_null($this->getFileObject())) {
// Pointer not initialized
throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
- } elseif (!is_resource($this->getPointer())) {
+ } elseif (!is_object($this->getFileObject())) {
// Pointer is not a valid resource!
- throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE);
+ throw new LogicException(sprintf('this->fileObject[]=%s is no object', gettype($this->getFileObject())));
}
// Read data from the file pointer and return it
assert(is_int($bytes));
// Try to read given characters
- $data = fread($this->getPointer(), $bytes);
+ $data = $this->getFileObject()->fread($bytes);
// Then return it
return $data;
* @throws FileReadProtectedException If the file cannot be read from
* @return void
*/
- public static final function createFrameworkTextFileInputPointer ($fileName) {
- // Some pre-sanity checks...
- if ((is_null($fileName)) || (empty($fileName))) {
- // No filename given
- throw new FileIsEmptyException(NULL, self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
- } elseif (!FrameworkBootstrap::isReachableFilePath($fileName)) {
+ public static final function createFrameworkTextFileInputPointer ($infoInstance) {
+ if (!FrameworkBootstrap::isReachableFilePath($infoInstance)) {
// File cannot be reached
- throw new FileIoException($fileName, self::EXCEPTION_FILE_NOT_REACHABLE);
- } elseif ((!FrameworkBootstrap::isReadableFile($fileName)) && (!file_exists($fileName))) {
+ throw new FileIoException($infoInstance, self::EXCEPTION_FILE_NOT_REACHABLE);
+ } elseif ((!FrameworkBootstrap::isReadableFile($infoInstance)) && (!$infoInstance->isFile())) {
// File does not exist!
- throw new FileNotFoundException($fileName, self::EXCEPTION_FILE_CANNOT_BE_READ);
- } elseif ((!FrameworkBootstrap::isReadableFile($fileName)) && (file_exists($fileName))) {
+ throw new FileNotFoundException($infoInstance, self::EXCEPTION_FILE_CANNOT_BE_READ);
+ } elseif ((!FrameworkBootstrap::isReadableFile($infoInstance)) && ($infoInstance->isFile())) {
// File cannot be read from (but exists)
- throw new FileReadProtectedException($fileName, self::EXCEPTION_FILE_CANNOT_BE_READ);
+ throw new FileReadProtectedException($infoInstance, self::EXCEPTION_FILE_CANNOT_BE_READ);
}
// Try to open a handler
- $filePointer = fopen($fileName, 'r');
- if ((is_null($filePointer)) || ($filePointer === false)) {
+ $fileObject = $infoInstance->openFile('r');
+ if ((is_null($fileObject)) || ($fileObject === false)) {
// Something bad happend
- throw new FileIoException($fileName, self::EXCEPTION_FILE_POINTER_INVALID);
+ throw new FileIoException($infoInstance, self::EXCEPTION_FILE_POINTER_INVALID);
} // END - if
// Create new instance
$pointerInstance = new FrameworkTextFileInputPointer();
// Set file pointer and file name
- $pointerInstance->setPointer($filePointer);
- $pointerInstance->setFileName($fileName);
+ $pointerInstance->setPointer($fileObject);
// Return the instance
return $pointerInstance;
*
* @param $bytes Amount of bytes to read or whole line (only text files)
* @return $data Data read from file
- * @throws NullPointerException If the file pointer instance
- * is not set by setPointer()
- * @throws InvalidResourceException If there is being set
+ * @throws NullPointerException If the file pointer instance is not set by setPointer()
+ * @throws InvalidResourceException If there is no object being set
*/
public function read ($bytes = NULL) {
// Some sanity checks
- if (is_null($this->getPointer())) {
+ if (is_null($this->getFileObject())) {
// Pointer not initialized
throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
- } elseif (!is_resource($this->getPointer())) {
+ } elseif (!is_object($this->getFileObject())) {
// Pointer is not a valid resource!
- throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE);
+ throw new LogicException(sprintf('this->fileObject[]=%s is no object', gettype($this->getFileObject())));
}
// Is $bytes set?
if (is_int($bytes)) {
// Try to read given characters
- $data = fgets($this->getPointer(), $bytes);
+ $data = $this->getFileObject()->fread($bytes);
} else {
// Try to read whole line
- $data = fgets($this->getPointer());
+ $data = $this->getFileObject()->fgets();
}
// Then return it
use CoreFramework\Generic\UnsupportedOperationException;
use CoreFramework\Object\BaseFrameworkSystem;
+// Import SPL stuff
+use \SplFileInfo;
+
/**
* A class for reading files
*
* Create a file pointer based on the given file. The file will also
* be verified here.
*
- * @param $fileName The file name we shall pass to fopen()
+ * @param $fileInstance An instance of a SplFileInfo class
* @return void
- * @throws FileIsEmptyException If the given file name is NULL or empty
* @throws FileReadProtectedException If PHP cannot read an existing file
* @throws FileWriteProtectedException If PHP cannot write an existing file
* @throws PathWriteProtectedException If PHP cannot write to an existing path
* @throws FileIoException If fopen() returns not a file resource
*/
- public static final function createFrameworkFileInputOutputPointer ($fileName) {
+ public static final function createFrameworkFileInputOutputPointer (SplFileInfo $fileInstance) {
// Some pre-sanity checks...
- if ((is_null($fileName)) || (empty($fileName))) {
- // No filename given
- throw new FileIsEmptyException(NULL, self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
- } elseif (!FrameworkBootstrap::isReachableFilePath($fileName)) {
+ if (!FrameworkBootstrap::isReachableFilePath($fileInstance)) {
// File exists but cannot be read
- throw new FileIoException($fileName, self::EXCEPTION_FILE_NOT_REACHABLE);
- } elseif ((!FrameworkBootstrap::isReadableFile($fileName)) && (file_exists($fileName))) {
+ throw new FileIoException($fileInstance, self::EXCEPTION_FILE_NOT_REACHABLE);
+ } elseif ((!FrameworkBootstrap::isReadableFile($fileInstance)) && (file_exists($fileInstance))) {
// File exists but cannot be read
- throw new FileReadProtectedException($fileName, self::EXCEPTION_FILE_CANNOT_BE_READ);
- } elseif ((file_exists($fileName)) && (!is_writable($fileName))) {
+ throw new FileReadProtectedException($fileInstance, self::EXCEPTION_FILE_CANNOT_BE_READ);
+ } elseif (($fileInstance->isFile()) && (!$fileInstance->isWritable())) {
// File exists but cannot be written
- throw new FileWriteProtectedException($fileName, self::EXCEPTION_FILE_CANNOT_BE_WRITTEN);
- } elseif (!is_writable(dirname($fileName))) {
+ throw new FileWriteProtectedException($fileInstance, self::EXCEPTION_FILE_CANNOT_BE_WRITTEN);
+ } elseif (!is_writable($fileInstance->getPath())) {
// Path is not writable
- throw new PathWriteProtectedException($fileName, self::EXCEPTION_PATH_CANNOT_BE_WRITTEN);
+ throw new PathWriteProtectedException($fileInstance, self::EXCEPTION_PATH_CANNOT_BE_WRITTEN);
}
// Try to open a handler
- $filePointer = fopen($fileName, 'c+b');
- if ((is_null($filePointer)) || ($filePointer === false)) {
+ $fileObject = $fileInstance->openFile('c+b');
+
+ // Is it valid?
+ if ((is_null($fileObject)) || ($fileObject === false)) {
// Something bad happend
- throw new FileIoException($fileName, self::EXCEPTION_FILE_POINTER_INVALID);
+ throw new FileIoException($fileInstance->getPathname(), self::EXCEPTION_FILE_POINTER_INVALID);
} // END - if
// Create new instance
$pointerInstance = new FrameworkFileInputOutputPointer();
- // Set file pointer and file name
- $pointerInstance->setPointer($filePointer);
- $pointerInstance->setFileName($fileName);
+ // Set file object and file name
+ $pointerInstance->setFileObject($fileObject);
// Return the instance
return $pointerInstance;
* @return void
* @throws NullPointerException If the file pointer instance
* is not set by setPointer()
- * @throws InvalidResourceException If there is being set
+ * @todo Add more checks
*/
private function validateFilePointer () {
- if (is_null($this->getPointer())) {
+ if (is_null($this->getFileObject())) {
// Pointer not initialized
throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
- } elseif (!is_resource($this->getPointer())) {
- // Pointer is not a valid resource!
- throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE);
- }
+ } // END - if
// All fine here
}
$this->validateFilePointer();
// Write data to the file pointer and return written bytes
- return fwrite($this->getPointer(), $dataStream, strlen($dataStream));
+ return $this->getFileObject()->fwrite($dataStream, strlen($dataStream));
}
/**
$this->validateFilePointer();
// Rewind the pointer
- return rewind($this->getPointer());
+ return $this->getFileObject()->rewind();
}
/**
$this->validateFilePointer();
// Move the file pointer
- return fseek($this->getPointer(), $seekPosition, $whence);
+ return $this->getFileObject()->fseek($seekPosition, $whence);
}
/**
// Is $bytes set?
if (is_int($bytes)) {
// Try to read given characters
- $data = fread($this->getPointer(), $bytes);
+ $data = $this->getFileObject()->fread($bytes);
} else {
// Try to read whole line
- $data = fread($this->getPointer());
+ $data = $this->getFileObject()->fgets();
}
// Then return it
$this->validateFilePointer();
// Get file's data
- $fileData = fstat($this->getPointer());
+ $fileData = $this->getFileObject()->fstat();
// Make sure the required array key is there
assert(isset($fileData['size']));
use CoreFramework\Stream\Filesystem\FileInputStreamer;
use CoreFramework\Stream\Filesystem\FileOutputStreamer;
+// Import SPL stuff
+use \SplFileInfo;
+
/**
* An universal class for file input/output streams.
*
/**
* Saves data to a given local file and create missing directory structures
*
- * @param $fileName The file name for the to be saved file
+ * @param $fileInstance An instance of a SplFileInfo class
* @param $dataArray The data we shall store to the file
* @return void
* @see FileOutputStreamer
* @todo This method needs heavy rewrite
*/
- public final function saveFile ($fileName, array $dataArray) {
+ public final function saveFile (SplFileInfo $fileInstance, array $dataArray) {
// Try it five times
$dirName = '';
$fileInstance = NULL;
for ($idx = 0; $idx < 5; $idx++) {
// Get a file output pointer
try {
- $fileInstance = ObjectFactory::createObjectByConfiguredName('file_raw_output_class', array($fileName, 'wb'));
+ $fileInstance = ObjectFactory::createObjectByConfiguredName('file_raw_output_class', array($fileInstance, 'wb'));
} catch (FileNotFoundException $e) {
// Bail out
ApplicationEntryPoint::exitApplication('The application has made a fatal error. Exception: ' . $e->__toString() . ' with message: ' . $e->getMessage());
/**
* Reads from a local file
*
- * @param $fqfn The full-qualified file-name which we shall load
+ * @param $infoInstance An instance of a SplFileInfo class
* @return $array An array with the element 'header' and 'data'
* @see FileInputStreamer
*/
- public final function loadFileContents ($fqfn) {
+ public final function loadFileContents (SplFileInfo $infoInstance) {
// Initialize some variables and arrays
$inputBuffer = '';
$lastBuffer = '';
$readData = ''; // This will contain our read data
// Get a file input handler
- $fileInstance = ObjectFactory::createObjectByConfiguredName('file_raw_input_class', array($fqfn));
+ $fileInstance = ObjectFactory::createObjectByConfiguredName('file_raw_input_class', array($infoInstance));
// Read all it's contents (we very and transparently decompress it below)
while ($readRawLine = $fileInstance->readFromFile()) {
use CoreFramework\Filesystem\Pointer\OutputPointer;
use CoreFramework\Generic\NullPointerException;
+// Import SPL stuff
+use \SplFileInfo;
+
/**
* A class for writing files
*
* Create a file pointer based on the given file. The file will also
* be verified here.
*
- * @param $fileName The file name we shall pass to fopen()
+ * @param $infoInstance An instance of a SplFileInfo class
* @param $mode The output mode ('w', 'a' are valid)
* @throws FileIsEmptyException If the provided file name is empty.
* @throws FileIoException If fopen() returns not a file resource
* @return void
*/
- public static final function createFrameworkRawFileOutputPointer ($fileName, $mode) {
+ public static final function createFrameworkRawFileOutputPointer (SplFileInfo $infoInstance, $mode) {
// Some pre-sanity checks...
- if (is_null($fileName)) {
- // No filename given
+ if (is_null($infoInstance)) {
+ // No infoInstance given
throw new FileIsEmptyException(NULL, self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
} // END - if
// Try to open a handler
- $filePointer = @fopen($fileName, $mode);
- if ((is_null($filePointer)) || ($filePointer === false)) {
+ $fileObject = $infoInstance->openFile($mode);
+ if ((is_null($fileObject)) || ($fileObject === false)) {
// Something bad happend
- throw new FileIoException ($fileName, self::EXCEPTION_FILE_POINTER_INVALID);
+ throw new FileIoException ($infoInstance, self::EXCEPTION_FILE_POINTER_INVALID);
} // END - if
// Create new instance
$pointerInstance = new FrameworkRawFileOutputPointer();
// Set file pointer and file name
- $pointerInstance->setPointer($filePointer);
- $pointerInstance->setFileName($fileName);
+ $pointerInstance->setFileObject($fileObject);
// Return the instance
return $pointerInstance;
*
* @param $dataStream The data stream we shall write to the file
* @return mixed Number of writes bytes or false on error
- * @throws NullPointerException If the file pointer instance
- * is not set by setPointer()
- * @throws InvalidResourceException If there is being set
- * an invalid file resource
+ * @throws NullPointerException If the file pointer instance is not set by setPointer()
+ * @throws LogicException If there is no object being set
*/
public function writeToFile ($dataStream) {
- if (is_null($this->getPointer())) {
+ if (is_null($this->getFileObject())) {
// Pointer not initialized
throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
- } elseif (!is_resource($this->getPointer())) {
+ } elseif (!is_object($this->getFileObject())) {
// Pointer is not a valid resource!
- throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE);
+ throw new LogicException(sprintf('this->fileObject[]=%s is no object', gettype($this->getFileObject())));
}
// Write data to the file pointer and return written bytes
- return fwrite($this->getPointer(), $dataStream);
+ return $this->getFileObject()->fwrite($dataStream);
}
/**
use CoreFramework\Generic\NullPointerException;
use CoreFramework\Generic\UnsupportedOperationException;
+// Import SPL stuff
+use \SplFileInfo;
+
/**
* A class for writing files
*
* Create a file pointer based on the given file. The file will also
* be verified here.
*
- * @param $fileName The file name we shall pass to fopen()
+ * @param $fileInstance An instance of a SplFileInfo class
* @param $mode The output mode ('w', 'a' are valid)
* @throws FileIsEmptyException If the provided file name is empty.
* @throws FileIoException If fopen() returns not a file resource
* @return void
*/
- public static final function createFrameworkTextFileOutputPointer ($fileName, $mode) {
+ public static final function createFrameworkTextFileOutputPointer (SplFileInfo $fileInstance, $mode) {
// Some pre-sanity checks...
- if (is_null($fileName)) {
+ if (is_null($fileInstance)) {
// No filename given
throw new FileIsEmptyException(NULL, self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
} // END - if
// Try to open a handler
- $filePointer = @fopen($fileName, $mode);
- if ((is_null($filePointer)) || ($filePointer === false)) {
+ $fileObject = $fileInstance->openFile($mode);
+ if ((is_null($fileObject)) || ($fileObject === false)) {
// Something bad happend
throw new FileIoException ($fileName, self::EXCEPTION_FILE_POINTER_INVALID);
} // END - if
// Create new instance
$pointerInstance = new FrameworkTextFileOutputPointer();
- // Set file pointer and file name
- $pointerInstance->setPointer($filePointer);
- $pointerInstance->setFileName($fileName);
+ // Set file object
+ $pointerInstance->setFileObject($fileObject);
// Return the instance
return $pointerInstance;
*
* @param $dataStream The data stream we shall write to the file
* @return mixed Number of writes bytes or false on error
- * @throws NullPointerException If the file pointer instance
- * is not set by setPointer()
- * @throws InvalidResourceException If there is being set
- * an invalid file resource
+ * @throws NullPointerException If the file pointer instance is not set by setPointer()
+ * @throws LogicException If there is no object being set
*/
public function writeToFile ($dataStream) {
- if (is_null($this->getPointer())) {
+ if (is_null($this->getFileObject())) {
// Pointer not initialized
throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
- } elseif (!is_resource($this->getPointer())) {
- // Pointer is not a valid resource!
- throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE);
+ } elseif (!is_object($this->getFileObject())) {
+ // Pointer is not a valid object!
+ throw new LogicException(sprintf('this->fileObject[]=%s is no object', gettype($this->getFileObject())));
}
// Write data to the file pointer and return written bytes
- return fwrite($this->getPointer(), $dataStream);
+ return $this->getFileObject()->fwrite($dataStream);
}
/**
use CoreFramework\Filesystem\File\BaseAbstractFile;
use CoreFramework\Generic\UnsupportedOperationException;
+// Import SPL stuff
+use \SplFileInfo;
+
/**
* A general text file class
*
/**
* Reads from a local or remote file
*
- * @param $fqfn The file's FQFN we shall load
+ * @param $infoInstance An instance of a SplFileInfo class
* @return $array An array containing all read lines
* @throws InvalidArrayCountException If an array has not the expected size
* @throws InvalidMD5ChecksumException If two MD5 hashes did not match
*/
- public function loadFileContents ($fqfn) {
+ public function loadFileContents (SplFileInfo $infoInstance) {
/*
* This class (or its implementations) are special file readers/writers.
* There is no need to read/write the whole file.
*/
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . '] fqfn=' . $fqfn);
+ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . '] infoInstance=' . $infoInstance);
throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
}
// Get a new instance
$fileInstance = new CsvInputFile();
- // Set file name
- $fileInstance->setFileName($fileName);
-
// Init this abstract file
$fileInstance->initFile($fileName);
*/
public function getContent () {
// Get cache file name
- $cacheFile = $this->getTemplateInstance()->getImageCacheFqfn();
+ $cacheFile = $this->getTemplateInstance()->getImageCacheFile();
+
+ // Open it for reading
+ $fileObject = $cacheFile->openFile('r');
+
+ // Rewind to beginning
+ $fileObject->rewind();
// Load the content
- $imageContent = file_get_contents($cacheFile);
+ $imageContent = $fileObject->fread($cacheFile->getSize());
// And return it
return $imageContent;
use CoreFramework\Bootstrap\FrameworkBootstrap;
use CoreFramework\Template\CompileableTemplate;
+// Import SPL stuff
+use \SplFileInfo;
+
/**
* A PNG image generator
*
* Finish this image by producing it
*
* @return void
+ * @todo Rewrite this to SplFileInfo/Object
*/
public function finishImage () {
+ $this->partialStub('Unfinished method.');
+ return;
+
// Call parent method
parent::finishImage();
// Get a file name for our image
- $cacheFile = $this->getTemplateInstance()->getImageCacheFqfn();
+ $cacheFile = $this->getTemplateInstance()->getImageCacheFile();
// Does it exist?
if (FrameworkBootstrap::isReadableFile($cacheFile)) {
// Remove it
- @unlink($cacheFile);
+ unlink($cacheFile->getPathname());
} // END - if
// Finish the image and send it to a cache file
- imagepng($this->getImageResource(), $cacheFile, 9, PNG_ALL_FILTERS);
+ imagepng($this->getImageResource(), $cacheFile->getPathname(), 9, PNG_ALL_FILTERS);
}
}
throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
}
- /**
- * Getter for file name
- *
- * @return $fileName The current file name
- * @throws UnsupportedOperationException If this method is called
- */
- public function getFileName () {
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
/**
* Initializes counter for valid entries, arrays for damaged entries and
* an array for gap seek positions. If you call this method on your own,
throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getPointerInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
}
- /**
- * Getter for file name
- *
- * @return $fileName The current file name
- * @throws UnsupportedOperationException This method is not (and maybe never will be) supported
- */
- public function getFileName () {
- throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getPointerInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
/**
* Getter for size of given stack (array count)
*
use CoreFramework\Object\BaseFrameworkSystem;
use CoreFramework\Response\Responseable;
+// Import SPL stuff
+use \SplFileInfo;
+
/**
* A generic template engine
*
private $compiledData = '';
/**
- * The last loaded template's FQFN for debugging the engine
+ * The last loaded template's file instance (SplFileInfo)
*/
- private $lastTemplate = '';
+ private $lastTemplate = NULL;
/**
* The variable stack for the templates
}
/**
- * Setter for the last loaded template's FQFN
+ * Setter for the last loaded template's file instance
*
* @param $template The last loaded template
* @return void
*/
- private final function setLastTemplate ($template) {
- $this->lastTemplate = (string) $template;
+ private final function setLastTemplate (SplFileInfo $fileInstance) {
+ $this->lastTemplate = $fileInstance;
}
/**
- * Getter for the last loaded template's FQFN
+ * Getter for the last loaded template's file instance
*
* @return $template The last loaded template
*/
* now entirely done by php_intl. These old thing with language-based
* template paths comes from an older time.
*/
- $fqfn = sprintf('%s%s%s%s%s%s',
+ $fileInstance = new SplFileInfo(sprintf('%s%s%s%s%s%s',
$this->getTemplateBasePath(),
$this->getGenericBasePath(),
$this->getTemplateType(),
DIRECTORY_SEPARATOR,
(string) $templateName,
$ext
- );
+ ));
// First try this
try {
// Load the raw template data
- $this->loadRawTemplateData($fqfn);
+ $this->loadRawTemplateData($fileInstance);
} catch (FileNotFoundException $e) {
// If we shall load a code-template we need to switch the file extension
if (($this->getTemplateType() != $this->getConfigInstance()->getConfigEntry('html_template_type')) && (empty($extOther))) {
$this->loadTemplate($templateName, $ext);
} else {
// Throw it again
- throw new FileNotFoundException($fqfn, self::EXCEPTION_FILE_NOT_FOUND);
+ throw new FileNotFoundException($fileInstance, self::EXCEPTION_FILE_NOT_FOUND);
}
}
/**
* A private loader for raw template names
*
- * @param $fqfn The full-qualified file name for a template
+ * @param $fileInstance An instance of a SplFileInfo class
* @return void
*/
- private function loadRawTemplateData ($fqfn) {
+ private function loadRawTemplateData (SplFileInfo $fileInstance) {
// Some debug code to look on the file which is being loaded
- //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE[' . __METHOD__ . ':' . __LINE__ . ']: FQFN=' . $fqfn);
+ //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE[' . __METHOD__ . ':' . __LINE__ . ']: fileInstance=' . $fileInstance);
// Load the raw template
- $rawTemplateData = $this->getFileIoInstance()->loadFileContents($fqfn);
+ $rawTemplateData = $this->getFileIoInstance()->loadFileContents($fileInstance);
// Store the template's contents into this class
$this->setRawTemplateData($rawTemplateData);
- // Remember the template's FQFN
- $this->setLastTemplate($fqfn);
+ // Remember the template's file instance
+ $this->setLastTemplate($fileInstance);
}
/**
use CoreFramework\Template\Engine\BaseTemplateEngine;
// Import SPL stuff
+use \SplFileInfo;
use \UnexpectedValueException;
/**
}
/**
- * 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',
+ public function getImageCacheFile () {
+ // Get the instance ready
+ $fileInstance = new SplFileInfo(sprintf('%s%s%s/%s.%s',
$this->getConfigInstance()->getConfigEntry('framework_base_path'),
$this->getGenericBasePath(),
'images/_cache',
$this->getImageInstance()->getImageName() . ':' . $this->__toString() . ':' . $this->getImageInstance()->__toString()
),
$this->getImageInstance()->getImageType()
- );
+ ));
// Return it
- return $fqfn;
+ return $fileInstance;
}
/**
$this->getMailerInstance()->invokeMailDelivery();
}
- /**
- * Getter for image cache file (FQFN)
- *
- * @return $fqfn Full-qualified file name of the image cache
- * @todo 0% done
- */
- public function getMailCacheFqfn () {
- // Initialize FQFN
- $fqfn = '';
- $this->debugBackTrace('Unfinished area!');
-
- // Return it
- return $fqfn;
- }
-
/**
* Setter for mailer instance
*
use CoreFramework\Template\Engine\BaseTemplateEngine;
// Import SPL stuff
+use \SplFileInfo;
use \UnexpectedValueException;
/**
}
/**
- * Getter for menu cache file (FQFN)
+ * Getter for menu cache file instance
*
- * @return $fqfn Full-qualified file name of the menu cache
+ * @return $fileInstance Full-qualified file name of the menu cache
*/
- public function getMenuCacheFqfn () {
+ public function getMenuCacheFile () {
// Get the application instance from registry
$applicationInstance = Registry::getRegistry()->getInstance('app');
- // Get the FQFN ready
- $fqfn = sprintf('%s%smenus/_cache/%s.%s',
+ // Get the file instance ready
+ $fileInstance = new SplFileInfo(sprintf('%s%smenus/_cache/%s.%s',
$this->getConfigInstance()->getConfigEntry('application_base_path'),
$applicationInstance->getAppShortName(),
md5(
$this->getMenuInstance()->__toString()
),
$this->getMenuInstance()->getMenuType()
- );
+ ));
// Return it
- return $fqfn;
+ return $fileInstance;
}
}
use CoreFramework\Object\BaseFrameworkSystem;
use CoreFramework\Socket\InvalidSocketException;
+// Import SPL stuff
+use \SplFileInfo;
+
/**
* This class contains static helper functions for console applications
*
// Get a new instance
$helperInstance = new ConsoleTools();
+ // Get SplFileInfo instance
+ $infoInstance = new SplFileInfo($helperInstance->getConfigInstance()->getConfigEntry('hostname_file'));
+
try {
// Get a file pointer
- $fileInstance = ObjectFactory::createObjectByConfiguredName('file_raw_input_class', array($helperInstance->getConfigInstance()->getConfigEntry('hostname_file')));
+ $fileInstance = ObjectFactory::createObjectByConfiguredName('file_raw_input_class', array($infoInstance));
// Read the file
$rawData = trim($fileInstance->readFromFile());
// Import framework stuff
use CoreFramework\Generic\FrameworkException;
+// Import SPL stuff
+use \SplFileInfo;
+
/**
* An exception thrown when a file pointer is not opened or when the file
* cannot be reached.
/**
* The constructor
*
- * @param $fqfn Full-qualified file name of (maybe) missing file
+ * @param $infoInstance An instance of a SplFileInfo class
* @param $code Code number for the exception
* @return void
*/
- public function __construct ($fqfn, $code) {
+ public function __construct (SplFileInfo $infoInstance, $code) {
// Add a message around the missing class
- $message = sprintf('A problem has been detected reading or writing to/from %s.', $fqfn);
+ $message = sprintf('A problem has been detected reading or writing to/from %s.', $infoInstance->getPathname());
// Call parent constructor
parent::__construct($message, $code);
// Import framework stuff
use CoreFramework\Generic\FrameworkException;
+// Import SPL stuff
+use \SplFileInfo;
+
/**
* An exception thrown when a file name is empty or NULL.
*
/**
* The constructor
*
- * @param $fqfn Ignored
+ * @param $infoInstance An instance of a SplFileInfo class (ignored)
* @param $code Code number for the exception
* @return void
*/
- public function __construct ($fqfn, $code) {
+ public function __construct (SplFileInfo $infoInstance, $code) {
// Call parent constructor
parent::__construct('No file name provided.', $code);
}
// Import framework stuff
use CoreFramework\Generic\FrameworkException;
+// Import SPL stuff
+use \SplFileInfo;
+
/**
* An exception thrown when a file was not found (but could be found).
*
/**
* The constructor
*
- * @param $fqfn Full-qualified file name of (maybe) missing file
+ * @param $infoInstance An instance of a SplFileInfo class
* @param $code Code number for the exception
* @return void
*/
- public function __construct ($fqfn, $code) {
+ public function __construct (SplFileInfo $infoInstance, $code) {
// Add a message around the missing class
- $message = sprintf('File %s not found.', $fqfn);
+ $message = sprintf('File "%s" not found.', $infoInstance->getPathname());
// Call parent constructor
parent::__construct($message, $code);
// Import framework stuff
use CoreFramework\Generic\FrameworkException;
+// Import SPL stuff
+use \SplFileInfo;
+
/**
* An exception thrown when a file is read-protected
*
/**
* The constructor
*
- * @param $fileName File which cannot be read from
+ * @param $infoInstance An instance of a SplFileInfo class
* @param $code Code number for the exception
* @return void
*/
- public function __construct ($fileName, $code) {
+ public function __construct (SplFileInfo $infoInstance, $code) {
// Add a message around the missing class
- $message = sprintf('File %s is read-protected. Please set read access rights (CHMOD).', $fileName);
+ $message = sprintf('File %s is read-protected. Please set read access rights (CHMOD).', $infoInstance->getPathname());
// Call parent constructor
parent::__construct($message, $code);
// Import framework stuff
use CoreFramework\Generic\FrameworkException;
+// Import SPL stuff
+use \SplFileInfo;
+
/**
* An exception thrown when a file could not be written.
*
/**
* The constructor
*
- * @param $fqfn Full-qualified file name of (maybe) missing file
+ * @param $infoInstance An instance of a SplFileInfo class
* @param $code Code number for the exception
* @return void
*/
- public function __construct ($fqfn, $code) {
+ public function __construct (SplFileInfo $infoInstance, $code) {
// Add a message around the missing class
- $message = sprintf('File %s cannot be written. Please check file and/or directory permissions.', $fqfn);
+ $message = sprintf('File %s cannot be written. Please check file and/or directory permissions.', $infoInstance->getPathname());
// Call parent constructor
parent::__construct($message, $code);
use CoreFramework\Filesystem\PathWriteProtectedException;
use CoreFramework\Generic\FrameworkException;
+// Import SPL stuff
+use \SplFileInfo;
+
/**
* An exception thrown when a path cannot be written to.
*
/**
* The constructor
*
- * @param $fqfn Full-qualified file name
+ * @param $infoInstance An instance of a SplFileInfo class
* @param $code Code number for the exception
* @return void
*/
- public function __construct ($fqfn, $code) {
+ public function __construct (SplFileInfo $infoInstance, $code) {
// Add a message around the missing class
- $message = sprintf('Path %s cannot be written to. Please check permissions.', dirname($fqfn));
+ $message = sprintf('Path "%s" cannot be written to. Please check permissions.', $infoInstance->getPath());
// Call parent constructor
parent::__construct($message, $code);
*/
function isEndOfFileReached ();
- /**
- * Getter for file name
- *
- * @return $fileName The current file name
- */
- function getFileName ();
-
/**
* Initializes counter for valid entries, arrays for damaged entries and
* an array for gap seek positions. If you call this method on your own,
*/
interface FilePointer extends FrameworkInterface {
/**
- * Getter for the file pointer
+ * Getter for the file object
*
- * @return $filePointer The file pointer which shall be a valid file resource
+ * @return $fileObject An instance of a SplFileObject class
*/
- function getPointer ();
-
- /**
- * Getter for file name
- *
- * @return $fileName The current file name
- */
- function getFileName ();
+ function getFileObject ();
/**
* Determines whether the EOF has been reached
// Import framework stuff
use CoreFramework\Stream\Input\StreamableInput;
+// Import SPL stuff
+use \SplFileInfo;
+
/**
* An interface for file input operations.
*
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
interface FileInputStreamer extends StreamableInput {
+
/**
* Reads from a local or remote file
*
- * @param $fqfn The file's FQFN we shall load
+ * @param $infoInstance An instance of a SplFileInfo class
* @return $array An array containing all read lines
* @throws InvalidArrayCountException If an array has not the expected size
* @throws InvalidMD5ChecksumException If two MD5 hashes did not match
*/
- function loadFileContents ($fqfn);
+ function loadFileContents (SplFileInfo $infoInstance);
}
// Import framework stuff
use CoreFramework\Stream\Output\StreamableOutput;
+// Import SPL stuff
+use \SplFileInfo;
+
/**
* An interface for file output operations.
*
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
interface FileOutputStreamer extends StreamableOutput {
+
/**
* Saves streamed (that are mostly serialized objects) data to files or
* external servers.
*
- * @param $fileName The local file's name including full path
- * @param $dataArray Array containing the compressor's extension and streamed data
+ * @param $infoInstance An instance of a SplFileInfo class
+ * @param $dataArray Array containing the compressor's extension and streamed data
* @return void
*/
- function saveFile ($fileName, array $dataArray);
+ function saveFile (SplFileInfo $infoInstance, array $dataArray);
}
use CoreFramework\Stream\Filesystem\FileInputStreamer;
use CoreFramework\Stream\Filesystem\FileOutputStreamer;
+// Import SPL stuff
+use \SplFileInfo;
+
/**
* An interface for I/O handlers
*
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
interface IoHandler extends FileInputStreamer, FileOutputStreamer {
+
/**
* Setter for the *real* file input instance
*
/**
* Saves a file with data by using the current output stream
*
- * @param $fileName Name of the file
+ * @param $infoInstance An instance of a SplFileInfo class
* @param $dataStream File data stream
* @param $objectInstance An instance of a FrameworkInterface class (default: NULL)
* @return void
*/
- function saveStreamToFile ($fileName, $dataStream, FrameworkInterface $objectInstance = NULL);
+ function saveStreamToFile (SplFileInfo $infoInstance, $dataStream, FrameworkInterface $objectInstance = NULL);
}
use CoreFramework\Stream\Filesystem\FileInputStreamer;
use CoreFramework\Stream\Filesystem\FileOutputStreamer;
+// Import SPL stuff
+use \SplFileInfo;
+
/**
* This is a file IO handler. It handles reading from and writing to files.
* Missing paths in writing process will be automatically created.
* Saves streamed (that are mostly serialized objects) data to files or
* external servers.
*
- * @param $fileName The local file's name including full path
+ * @param $infoInstance An instance of a SplFileInfo class
* @param $dataArray Array containing the compressor's extension and streamed data
* @return void
* @throws UnsupportedOperationException If this method is called
*/
- public function saveFile ($fileName, array $dataArray) {
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('fileName=' . $fileName . ',dataArray()=' . count($dataArray));
+ public function saveFile (SplFileInfo $infoInstance, array $dataArray) {
+ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('infoInstance.pathname=' . $infoInstance->getPathname() . ',dataArray()=' . count($dataArray));
throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
}
/**
* Saves a file with data by using the current output stream
*
- * @param $fileName Name of the file
+ * @param $infoInstance An instance of a SplFileInfo class
* @param $dataStream File data stream
* @param $objectInstance An instance of a FrameworkInterface class (default: NULL)
* @return void
*/
- public function saveStreamToFile ($fileName, $dataStream, FrameworkInterface $objectInstance = NULL) {
+ public function saveStreamToFile (SplFileInfo $infoInstance, $dataStream, FrameworkInterface $objectInstance = NULL) {
// Default is this array
$className = $this->__toString();
1 => $dataStream
);
- // Send the fileName and dataArray to the output handler
- $this->getOutputStream()->saveFile($fileName, $dataArray);
+ // Send the infoInstance and dataArray to the output handler
+ $this->getOutputStream()->saveFile($infoInstance, $dataArray);
}
/** Loads data from a file over the input handler
*
- * @param $fqfn Given full-qualified file name (FQFN) to load
+ * @param $infoInstance An instance of a SplFileInfo class
* @return $array Array with the file contents
*/
- public function loadFileContents ($fqfn) {
+ public function loadFileContents (SplFileInfo $infoInstance) {
// Read from the input handler
- return $this->getInputStream()->loadFileContents($fqfn);
+ return $this->getInputStream()->loadFileContents($infoInstance);
}
/**