protected $date_changed = NULL;
protected $date_locked = NULL;
- protected $include = NULL;
+ protected $include_directory = NULL;
+ protected $include_name = NULL;
/**
* Class constructor.
$this->date_changed = NULL;
$this->date_locked = NULL;
- $this->include = NULL;
+ $this->include_directory = NULL;
+ $this->include_name = NULL;
}
/**
unset($this->date_changed);
unset($this->date_locked);
- unset($this->include);
+ unset($this->include_directory);
+ unset($this->include_name);
parent::__destruct();
}
}
/**
- * Assign an include file needed to process this path.
+ * Assign an include path directory needed to process this path.
*
- * @param string $path
+ * This is the prefix part of the path.
+ *
+ * @param string|null $directory
* A path to a file that may be found via the PHP search path.
*
* @return c_base_return_status
* TRUE on success, FALSE otherwise.
*/
- public function set_include($path) {
- if (!is_string($path)) {
- $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'path', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT);
+ public function set_include_directory($directory) {
+ if (!is_string($directory) && !is_null($directory)) {
+ $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_directory' => 'directory', ':function_directory' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT);
+ return c_base_return_error::s_false($error);
+ }
+
+ $this->include_directory = $directory;
+ return new c_base_return_true();
+ }
+
+ /**
+ * Assign an include path name needed to process this path.
+ *
+ * This is the suffix part of the path.
+ *
+ * @param string|null $path
+ * A path to a file that may be found via the PHP search path.
+ *
+ * @return c_base_return_status
+ * TRUE on success, FALSE otherwise.
+ */
+ public function set_include_name($name) {
+ if (!is_string($name) && !is_null($name)) {
+ $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'name', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT);
return c_base_return_error::s_false($error);
}
- $this->include = $path;
+ $this->include_name = $name;
return new c_base_return_true();
}
}
/**
- * Get the assigned include path.
+ * Get the assigned include path directory.
+ *
+ * This is the prefix part of the path.
*
* @return c_base_return_string|c_base_return_null
* Include path string on success.
* NULL is returned if the include path is not assigned.
* Error bit is set on error.
*/
- public function get_include() {
- if (!is_string($this->include)) {
+ public function get_include_directory() {
+ if (!is_string($this->include_directory)) {
return new c_base_return_null();
}
- return c_base_return_string::s_new($this->include);
+ return c_base_return_string::s_new($this->include_directory);
+ }
+
+ /**
+ * Get the assigned include path name.
+ *
+ * This is the suffix part of the path.
+ *
+ * @return c_base_return_string|c_base_return_null
+ * Include path string on success.
+ * NULL is returned if the include path is not assigned.
+ * Error bit is set on error.
+ */
+ public function get_include_name() {
+ if (!is_string($this->include_name)) {
+ return new c_base_return_null();
+ }
+
+ return c_base_return_string::s_new($this->include_name);
}
/**
* An executed array object with error bit set is returned on error.
*/
public function do_execute(&$http, &$database, &$session, $settings = array()) {
- if (!($database instanceof c_base_database)) {
- $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'database', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT);
+ if (!($http instanceof c_base_http)) {
+ $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'http', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT);
return c_base_return_error::s_value(array(), 'c_base_path_executed', $error);
}
- if (!($http instanceof c_base_http)) {
- $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'http', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT);
+ if (!($database instanceof c_base_database)) {
+ $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'database', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT);
return c_base_return_error::s_value(array(), 'c_base_path_executed', $error);
}
*
* @todo: should redirect and alias booleans be added as parameters?
*
+ * @pram string $directory
+ * The first part of the file path
* @pram string $path
* The url path in which the handler applies to.
* @param string $handler
* The name of an implementation of c_base_path.
- * @param string|null $include
- * (optional) The file path (relative to the PHP includes) to include that contains the requested path.
+ * @param string|null $directory
+ * (optional) The prefix path (relative to the PHP includes) to include that contains the requested path.
+ * When not NULL, both $directory and $name must not be NULL.
+ * @param string|null $name
+ * (optional) The suffix path (relative to the PHP includes) to include that contains the requested path.
+ * When not NULL, both $directory and $name must not be NULL.
*
* @return c_base_return_status
* TRUE is returned on success.
* FALSE with error bit set is returned on error.
*/
- public function set_path($path, $handler, $include = NULL) {
+ public function set_path($path, $handler, $include_directory = NULL, $include_name = NULL) {
if (!is_string($path)) {
$error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'path', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT);
return c_base_return_error::s_false($error);
return c_base_return_error::s_false($error);
}
- if (!is_null($include) && !is_string($include)) {
- $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'include', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT);
+ if ((!is_null($include_directory) || (is_null($include_directory) && !is_null($include_name))) && !is_string($include_directory)) {
+ $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'include_directory', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT);
+ return c_base_return_error::s_false($error);
+ }
+
+ if ((!is_null($include_name) || (is_null($include_name) && !is_null($include_directory))) && !is_string($include_name)) {
+ $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'include_name', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT);
return c_base_return_error::s_false($error);
}
if (mb_strlen($path) == 0) {
- $this->root = array('handler' => $handler, 'include' => $include, 'is_root' => TRUE);
+ $this->root = array('handler' => $handler, 'include_directory' => $include_directory, 'include_name' => $include_name, 'is_root' => TRUE);
return new c_base_return_true();
}
$depth_total = count($path_parts);
foreach ($path_parts as $path_part) {
if ($depth_current == $depth_total) {
- $path_tree['include'] = $include;
+ $path_tree['include_directory'] = $include_directory;
+ $path_tree['include_name'] = $include_name;
$path_tree['handler'] = $handler;
break;
}
if (!isset($path_tree['paths'][$path_part])) {
$path_tree['paths'][$path_part] = array(
'paths' => array(),
- 'include' => NULL,
+ 'include_directory' => NULL,
+ 'include_name' => NULL,
'handler' => NULL,
);
}
*
* @return c_base_return_array|c_base_return_int|c_base_return_null
* An array containing:
- * - 'include': the file to include that contains the handler class implementation.
+ * - 'include_directory': the prefix path of the file to include that contains the handler class implementation.
+ * - 'include_name': the suffix path of the file to include that contains the handler class implementation.
* - 'handler': the name of the handler class.
* - 'redirect': if specified, then a redirect path (instead of include/handler).
* - 'code': if redirect is specified, then the http response code associated with the redirect.
foreach ($path_parts as $path_part) {
if ($depth_current == $depth_total) {
if (isset($path_tree['handler'])) {
- $found = array('include' => $path_tree['include'], 'handler' => $path_tree['handler']);
+ $found = array('include_directory' => $path_tree['include_directory'], 'include_name' => $path_tree['include_name'], 'handler' => $path_tree['handler']);
break;
}
}
if (!isset($path_tree['paths'][$path_part])) {
if ($depth_current == $depth_total) {
if (isset($path_tree['handler'])) {
- $found = array('include' => $path_tree['include'], 'handler' => $path_tree['handler']);
+ $found = array('include_directory' => $path_tree['include_directory'], 'include_name' => $path_tree['include_name'], 'handler' => $path_tree['handler']);
break;
}
}
private $session = NULL;
private $output = NULL;
private $logged_in = NULL;
- private $paths = NULL;
+
+ private $paths = NULL;
+ private $path = NULL;
+
+ private $alias = NULL;
/**
* Class constructor.
$this->session = NULL;
$this->output = NULL;
$this->logged_in = NULL;
- $this->paths = NULL;
- $this->path = NULL;
+
+ $this->paths = NULL;
+ $this->path = NULL;
+
+ $this->alias = NULL;
}
/**
unset($this->session);
unset($this->output);
unset($this->logged_in);
+
unset($this->paths);
unset($this->path);
+
+ unset($this->alias);
}
/**
$this->output = NULL;
$this->logged_in = $logged_in;
+ $this->p_get_language_alias();
// require HTTPS for access to any part of this website.
if (!isset($_SERVER["HTTPS"])) {
return $redirect->do_execute($this->http, $this->database, $this->session, $this->settings);
}
else {
- if (!empty($handler_settings['include']) && is_string($handler_settings['include'])) {
- require_once($handler_settings['include']);
+ if (!empty($handler_settings['include_name']) && is_string($handler_settings['include_name'])) {
+ require_once($handler_settings['include_directory'] . $handler_settings['include_name']);
+ }
+
+ // execute path handler, using custom-language if defined.
+ if (empty($handler_settings['handler'])) {
+ $server_error = $this->p_get_path_server_error();
+ return $server_error->do_execute($this->http, $this->database, $this->session, $this->settings);
}
+ elseif (is_string($this->alias)) {
+ @include_once($handler_settings['include_directory'] . $this->alias . '/' . $handler_settings['include_name']);
- if (empty($handler_settings['handler']) || !class_exists($handler_settings['handler'])) {
- $not_found = $this->p_get_path_server_error();
- return $not_found->do_execute($this->http, $this->database, $this->session, $this->settings);
+ $handler_class = $handler_settings['handler'] . '_' . $this->alias;
+ if (class_exists($handler_class)) {
+ $this->path = new $handler_class();
+
+ unset($handler_class);
+ }
+ else {
+ unset($handler_class);
+
+ // attempt to fallback to default handler if the language-specific handler class is not found.
+ if (!class_exists($handler_settings['handler'])) {
+ $server_error = $this->p_get_path_server_error();
+ return $server_error->do_execute($this->http, $this->database, $this->session, $this->settings);
+ }
+ else {
+ $this->path = new $handler_settings['handler']();
+ }
+ }
}
else {
- $this->path = new $handler_settings['handler']();
- if (isset($handler_settings['is_root']) && $handler_settings['is_root']) {
- $this->path->set_is_root(TRUE);
+ if (class_exists($handler_settings['handler'])) {
+ $this->path = new $handler_settings['handler']();
+ }
+ else {
+ $server_error = $this->p_get_path_server_error();
+ return $server_error->do_execute($this->http, $this->database, $this->session, $this->settings);
}
}
+
+ if (isset($handler_settings['is_root']) && $handler_settings['is_root']) {
+ $this->path->set_is_root(TRUE);
+ }
}
unset($handler_settings);
$this->paths = new c_base_paths();
// set root path to be the user dashboard.
- $this->paths->set_path('', 'c_reservation_path_user_dashboard', 'program/reservation/paths/u/dashboard.php');
+ $this->paths->set_path('', 'c_reservation_path_user_dashboard', 'program/reservation/paths/u/', 'dashboard.php');
// create login/logout paths
- $this->paths->set_path('/u/login', 'c_reservation_path_user_login', 'program/reservation/login.php');
- $this->paths->set_path('/u/logout', 'c_reservation_path_user_logout', 'program/reservation/logout.php');
+ $this->paths->set_path('/u/login', 'c_reservation_path_user_login', 'program/reservation/', 'login.php');
+ $this->paths->set_path('/u/logout', 'c_reservation_path_user_logout', 'program/reservation/', 'logout.php');
// user dashboard
- $this->paths->set_path('/u/dashboard', 'c_reservation_path_user_dashboard', 'program/reservation/paths/u/dashboard.php');
+ $this->paths->set_path('/u/dashboard', 'c_reservation_path_user_dashboard', 'program/reservation/paths/u/', 'dashboard.php');
}
/**
}
/**
+ * Load and save the current preferred language alias.
+ *
+ * This will be stored in $this->alias.
+ */
+ private function p_get_language_alias() {
+ $aliases = array();
+ $languages = $this->http->get_response_content_language()->get_value_exact();
+ if (is_array($languages) && !empty($languages)) {
+ $language = reset($languages);
+
+ // us-english is the default, so do not attempt to include any external files.
+ if ($language == i_base_language::ENGLISH_US || $language == i_base_language::ENGLISH) {
+ unset($language);
+ unset($aliases);
+ unset($languages);
+
+ $this->alias = NULL;
+ return;
+ }
+
+ $aliases = c_base_defaults_global::s_get_languages()::s_get_aliases_by_id($language)->get_value_exact();
+ }
+ unset($language);
+
+ // use default if no aliases are found.
+ if (empty($aliases)) {
+ unset($aliases);
+ unset($languages);
+
+ $this->alias = NULL;
+ return;
+ }
+
+ $this->alias = end($aliases);
+ }
+
+ /**
* Will include a custom language path if one exists.
*
* The default language files ends in "${path}${name}.php".
private function p_include_path($path, $name, $class) {
require_once($path . $name . '.php');
- $aliases = array();
- $languages = $this->http->get_response_content_language()->get_value_exact();
- if (is_array($languages) && !empty($languages)) {
- $language = reset($languages);
-
- // us-english is the default, so do not attempt to include any external files.
- if ($language == i_base_language::ENGLISH_US || $language == i_base_language::ENGLISH) {
- unset($language);
- unset($aliases);
- unset($languages);
- return new $class();
- }
-
- $aliases = c_base_defaults_global::s_get_languages()::s_get_aliases_by_id($language)->get_value_exact();
- }
- unset($language);
-
// use default if no aliases are found.
- if (empty($aliases)) {
- unset($aliases);
- unset($languages);
+ if (is_null($this->alias)) {
return new $class();
}
- $alias = end($aliases);
- unset($aliases);
-
// use include_once instead of require_require to allow for failsafe behavior.
- @include_once($path . $alias . '/' . $name . '.php');
+ @include_once($path . $this->alias . '/' . $name . '.php');
- $language_class = $class . '_' . $alias;
+ $language_class = $class . '_' . $this->alias;
if (class_exists($language_class)) {
- unset($alias);
-
return new $language_class();
}
- unset($alias);
unset($language_class);
// if unable to find, fallback to original class