// 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%sclasses%sclass_BaseFrameworkSystem.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;