forked from UnionOfRAD/lithium
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add scope to
lithium\net\http\Router
and lithium\net\http\Media
.
- Routes can be scoped using the following notation: Routed::scope(); // Returns the current scope Router::scope('name'); // Use a new scope Router::scope('name'), function(){/* executed inside the scope */}); Router::attach('name'), array(), array()); //Attach a mount point to a scope Router::attached() // Returns all attachments Router::attached('name', array()); // Returns the attached mount point configuration - The Media class can be scoped using the following notation: (i.e. usefull for CDN or others media location). Media::scope(); // Returns the current scope Media::scope('name'); // Use a new scope Media::scope('name'), function(){/* executed inside the scope */}); Media::attach('name'), array()); // Attach a mount point to a scope Media::attached(); // Returns all attachements Media::attached('name'); // Returns the attached mount point configuration - The paths of assets paths now called 'paths' for consistency see `Media::_asset` (BC Break) - Include UnionOfRAD#535 it's not a good practice to use `'http:method'` at route level but it may be better to not let it buggy.
- Loading branch information
Showing
14 changed files
with
2,427 additions
and
157 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
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,105 @@ | |||
<?php | |||
/** | |||
* Lithium: the most rad php framework | |||
* | |||
* @copyright Copyright 2013, Union of RAD (http://union-of-rad.org) | |||
* @license http://opensource.org/licenses/bsd-license.php The BSD License | |||
*/ | |||
|
|||
namespace lithium\core; | |||
|
|||
use lithium\core\Environment; | |||
|
|||
/** | |||
* The `Configuration` class allow to store `Environement` based configurations. | |||
* | |||
* @see lithium\core\Environment | |||
*/ | |||
class Configuration extends \lithium\core\Object { | |||
|
|||
/** | |||
* Can provide configurations based on the environment, | |||
* i.e. `'development'`, `'production'` or `'test'` | |||
* | |||
* @var array of configurations, indexed by name. | |||
*/ | |||
public $_configurations = array(); | |||
|
|||
/** | |||
* A closure called by `_config()` which allows to automatically | |||
* assign or auto-generate additional configuration data, once a configuration is first | |||
* accessed. This allows configuration data to be lazy-loaded from adapters or other data | |||
* sources. | |||
* | |||
* @param string $name Name of the configuration which is being accessed. This is the key | |||
* name containing the specific set of configuration passed into `config()`. | |||
* @param array $config Configuration assigned to `$name`. If this configuration | |||
* is segregated by environment, then this will contain the configuration for | |||
* the current environment. | |||
* @return array Returns the final array of settings for the given named configuration. | |||
*/ | |||
public $initConfig = null; | |||
|
|||
/** | |||
* Sets configurations for a particular adaptable implementation, or returns the current | |||
* configuration settings. | |||
* | |||
* @param string $name Name of the scope. | |||
* @param array $config Configuration to set. | |||
*/ | |||
public function set($name = null, $config = null) { | |||
if ($config && is_array($config)) { | |||
$this->_configurations[$name] = $config; | |||
return; | |||
} | |||
if ($config === false) { | |||
unset($this->_configurations[$name]); | |||
} | |||
} | |||
|
|||
/** | |||
* Gets an array of settings for the given named configuration in the current | |||
* environment. | |||
* | |||
* @see lithium\core\Environment | |||
* @param string $name Name of the configuration. | |||
* @return array Settings of the named configuration. | |||
*/ | |||
public function get($name = null) { | |||
if ($name === null) { | |||
$result = array(); | |||
$this->_configurations = array_filter($this->_configurations); | |||
|
|||
foreach ($this->_configurations as $key => $value) { | |||
$result[$key] = $this->get($key); | |||
} | |||
return $result; | |||
} | |||
|
|||
$settings = &$this->_configurations; | |||
|
|||
if (!isset($settings[$name])) { | |||
return null; | |||
} | |||
|
|||
if (isset($settings[$name][0])) { | |||
return $settings[$name][0]; | |||
} | |||
$env = Environment::get(); | |||
|
|||
$config = isset($settings[$name][$env]) ? $settings[$name][$env] : $settings[$name]; | |||
|
|||
$method = is_callable($this->initConfig) ? $this->initConfig : null; | |||
$settings[$name][0] = $method ? $method($name, $config) : $config; | |||
return $settings[$name][0]; | |||
} | |||
|
|||
/** | |||
* Clears all configurations. | |||
*/ | |||
public function reset() { | |||
$this->_configurations = array(); | |||
} | |||
} | |||
|
|||
?> |
Oops, something went wrong.