diff --git a/classes/Config/File.php b/classes/Config/File.php new file mode 100644 index 0000000..c84c042 --- /dev/null +++ b/classes/Config/File.php @@ -0,0 +1,62 @@ +load($name); + * + * It means that if application runs on yours.domain.name.com the groups + * list would be somothing like that: + * - "cookie" - default application configuration, which could be under under cvs + * - "cookie.host.yours.domain.name.com" - hostname oriented configuration, which could be used on stages + * - "cookie.local" - most powerfull configuration is development environment + * @param string $group configuration group name + * @return $this current object + * @uses Kohana::load + */ + public function load($group) { + $config = array(); + + $groups = Arr::merge( + array($group), + $this->build_hosts_groups($group, $_SERVER['HTTP_HOST'], self::HTTP_HOST_SUFFIX), + array($group . '.local') + ); + + if ($groups) { + foreach ($groups as $group) { + // Merge each file to the configuration array + $config = Arr::merge($config, parent::load($group)); + } + } + + return $config; + } + + /** + * Build list of configs based on host name + * @param string $group configuration group name + * @param string $host host name + * @param string $suffix configuration group suffix + * @return array + */ + private function build_hosts_groups($group, $host, $suffix) { + $groups = array(); + $tail = array(); + + foreach (array_reverse(explode('.', $host)) as $index => $part) { + array_unshift($tail, $part); + + if ($index !== 0) { + $groups[] = "$group.$suffix." . join('.', $tail); + } + } + + return $groups; + } + +} \ No newline at end of file diff --git a/classes/Cookie.php b/classes/Cookie.php new file mode 100644 index 0000000..de19ef2 --- /dev/null +++ b/classes/Cookie.php @@ -0,0 +1,18 @@ +load('cookie')); + * + * @param Config_Group $config + */ + public static function init(Config_Group $config) { + foreach ($config as $key => $value) { + Cookie::${$key} = $value; + } + } + +} diff --git a/config/.empty b/config/.empty new file mode 100644 index 0000000..e69de29 diff --git a/config/cookie.php b/config/cookie.php new file mode 100644 index 0000000..62a79d0 --- /dev/null +++ b/config/cookie.php @@ -0,0 +1,10 @@ + $_SERVER['SERVER_NAME'], + 'domain' => '.' . join('.', array_slice(explode('.', $_SERVER['HTTP_HOST'], 2), 1)), + 'path' => '/', + 'expiration' => 0, + 'secure' => false, + 'httponly' => false, +); \ No newline at end of file