From bc4b8979b0e9ccba959ca3579bee41326a9bdd8a Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Sat, 15 Aug 2009 21:18:31 +0300 Subject: [PATCH] Basic environment set functionality is in place. --- config/environment.php | 25 +++++ config/environments/development.php | 5 + config/environments/production.php | 5 + config/environments/staging.php | 5 + config/environments/test.php | 5 + config/hosts.php | 26 +++++ config/routes.php | 5 + vendor/zynapse/action_environment.php | 134 ++++++++++++++++++++++++++ vendor/zynapse/zynapse.php | 15 ++- 9 files changed, 224 insertions(+), 1 deletion(-) create mode 100644 config/environment.php create mode 100644 config/environments/development.php create mode 100644 config/environments/production.php create mode 100644 config/environments/staging.php create mode 100644 config/environments/test.php create mode 100644 config/hosts.php create mode 100644 config/routes.php create mode 100644 vendor/zynapse/action_environment.php diff --git a/config/environment.php b/config/environment.php new file mode 100644 index 0000000..b075f60 --- /dev/null +++ b/config/environment.php @@ -0,0 +1,25 @@ + \ No newline at end of file diff --git a/config/environments/development.php b/config/environments/development.php new file mode 100644 index 0000000..ba2e1f6 --- /dev/null +++ b/config/environments/development.php @@ -0,0 +1,5 @@ + \ No newline at end of file diff --git a/config/environments/production.php b/config/environments/production.php new file mode 100644 index 0000000..ba2e1f6 --- /dev/null +++ b/config/environments/production.php @@ -0,0 +1,5 @@ + \ No newline at end of file diff --git a/config/environments/staging.php b/config/environments/staging.php new file mode 100644 index 0000000..ba2e1f6 --- /dev/null +++ b/config/environments/staging.php @@ -0,0 +1,5 @@ + \ No newline at end of file diff --git a/config/environments/test.php b/config/environments/test.php new file mode 100644 index 0000000..ba2e1f6 --- /dev/null +++ b/config/environments/test.php @@ -0,0 +1,5 @@ + \ No newline at end of file diff --git a/config/hosts.php b/config/hosts.php new file mode 100644 index 0000000..f8b0afb --- /dev/null +++ b/config/hosts.php @@ -0,0 +1,26 @@ + array( + // + // ), + // 'wap.zynapse' => array( + // 'mode' => 'wap', + // ), + // 'admin.zynapse' => array( + // 'root' => 'admin', + // ), + // 'zynapse.org' => array( + // 'environment' => 'production', + // ), + // 'admin.zynapse.org' => array( + // 'environment' => 'production', + // 'root' => 'admin', + // ), +); + +?> \ No newline at end of file diff --git a/config/routes.php b/config/routes.php new file mode 100644 index 0000000..ba2e1f6 --- /dev/null +++ b/config/routes.php @@ -0,0 +1,5 @@ + \ No newline at end of file diff --git a/vendor/zynapse/action_environment.php b/vendor/zynapse/action_environment.php new file mode 100644 index 0000000..c3dc515 --- /dev/null +++ b/vendor/zynapse/action_environment.php @@ -0,0 +1,134 @@ +set_paths(); + $this->set_include_paths(); + $this->load_environment_file(); + } + + function load_environment_file () { + require_once(ZNAP_CONFIG . "/environment.php"); + $this->env = $environment; + if ( !empty($enable_host_specific_configuration) ) { + $this->load_hosts_file(); + } + } + + function load_hosts_file () { + require_once(ZNAP_CONFIG . "/hosts.php"); + $host = $this->match_to_host($hosts); + if ( !empty($host) ) { + if ( !empty($host['environment']) ) $this->env = $host['environment']; + if ( !empty($host['mode']) ) $this->mode = $host['mode']; + if ( !empty($host['root']) ) { + if ( !empty($_SERVER['REQUEST_URI']) ) $_SERVER['REQUEST_URI'] = '/'.$host['root'].$_SERVER['REQUEST_URI']; + if ( !empty($_SERVER['REDIRECT_URL']) ) $_SERVER['REDIRECT_URL'] = '/'.$host['root'].$_SERVER['REDIRECT_URL']; + } + } + } + + function set_paths () { + $this->apps_path = ZNAP_ROOT . "/apps"; + $this->lib_path = ZNAP_ROOT . "/lib"; + $this->log_path = ZNAP_ROOT . "/log"; + $this->public_path = ZNAP_ROOT . "/public"; + $this->tmp_path = ZNAP_ROOT . "/tmp"; + $this->cache_path = $this->tmp_path . "/log"; + $this->scripts_path = ZNAP_LIB_ROOT . "/shell_scripts"; + } + + function set_include_paths () { + if ( substr(PHP_OS, 0, 3) != 'WIN' ) { + $this->is_windows = false; + $this->path_seperator = ":"; + } else { + $this->is_windows = true; + $this->path_seperator = ";"; + } + + ini_set("include_path", + '.' . $this->path_seperator . + ZNAP_LIB_ROOT . $this->path_seperator . + $this->scripts_path . $this->path_seperator . + $this->lib_path . $this->path_seperator . + ini_get('include_path') + ); + + } + + function match_to_host ($list = array()) { + if ( is_array($list) && !empty($list) ) { + $new_config = array(); + foreach( $list as $host => $settings ) { + $regex = preg_quote($host, '/'); + $regex = str_replace('\*', '.*', $regex); + $http_host = (substr($_SERVER['HTTP_HOST'], 0, 4) == 'www.') ? substr($_SERVER['HTTP_HOST'], 4) : $_SERVER['HTTP_HOST'] ; + if ( preg_match('/^'.$regex.'$/i', $http_host) ) { + foreach( $settings as $key => $value ) { + if ( !array_key_exists($key, $new_config) ) { + $new_config[$key] = $value; + } + } + } + } + } + return (!empty($new_config)) ? $new_config : false ; + } + + +} + +?> \ No newline at end of file diff --git a/vendor/zynapse/zynapse.php b/vendor/zynapse/zynapse.php index a0ae344..185b251 100644 --- a/vendor/zynapse/zynapse.php +++ b/vendor/zynapse/zynapse.php @@ -33,8 +33,21 @@ class Zynapse { + public static + $env, // ActionEnvironment + $base, // ActionController + $view, // ActionView + $locale, // ActionLocale + $log; // ActionLog + function init () { - echo "hello world"; + + require_once(ZNAP_LIB_ROOT . "/action_environment.php"); + + self::$env = new ActionEnvironment(); + + echo "hello world
\n"; + echo self::$env->env; } }