forked from coffeeich/kohana-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add simple configuration tricky style - using local environment orien…
…ted setting
- Loading branch information
Showing
4 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php defined('SYSPATH') OR die('No direct script access.'); | ||
|
||
class Config_File extends Kohana_Config_File { | ||
|
||
const HTTP_HOST_SUFFIX = 'host'; | ||
|
||
/** | ||
* Load and merge all of the configuration files in this group. | ||
* | ||
* $config->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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php defined('SYSPATH') OR die('No direct script access.'); | ||
|
||
class Cookie extends Kohana_Cookie { | ||
|
||
/** | ||
* Fast and easy way to accept configuration settings of cookies: | ||
* | ||
* Cookie::init(Kohana::$config->load('cookie')); | ||
* | ||
* @param Config_Group $config | ||
*/ | ||
public static function init(Config_Group $config) { | ||
foreach ($config as $key => $value) { | ||
Cookie::${$key} = $value; | ||
} | ||
} | ||
|
||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
return array( | ||
'salt' => $_SERVER['SERVER_NAME'], | ||
'domain' => '.' . join('.', array_slice(explode('.', $_SERVER['HTTP_HOST'], 2), 1)), | ||
'path' => '/', | ||
'expiration' => 0, | ||
'secure' => false, | ||
'httponly' => false, | ||
); |