Files
lgp-admin-plus-api/laravel/config.php

100 lines
2.7 KiB
PHP
Raw Normal View History

2011-08-18 19:56:29 -05:00
<?php namespace Laravel;
class Config {
/**
* All of the loaded configuration items.
*
* @var array
*/
2011-09-16 19:59:20 -05:00
protected $config = array();
/**
* Create a new configuration manager instance.
*
2011-09-16 19:59:20 -05:00
* @param array $config
* @return void
*/
2011-09-16 19:59:20 -05:00
public function __construct($config)
{
2011-09-16 19:59:20 -05:00
$this->config = $config;
}
2011-08-18 19:56:29 -05:00
/**
* Determine if a configuration item or file exists.
*
2011-09-16 19:59:20 -05:00
* <code>
* // Determine if the "options" configuration file exists
* $options = Config::has('options');
*
* // Determine if a specific configuration item exists
* $timezone = Config::has('application.timezone');
* </code>
*
2011-08-18 19:56:29 -05:00
* @param string $key
* @return bool
*/
2011-08-26 21:42:04 -05:00
public function has($key)
2011-08-18 19:56:29 -05:00
{
2011-08-26 21:42:04 -05:00
return ! is_null($this->get($key));
2011-08-18 19:56:29 -05:00
}
/**
* Get a configuration item.
*
2011-09-16 19:59:20 -05:00
* Configuration items are stored in the application/config directory, and provide
* general configuration options for a wide range of Laravel facilities.
*
* The arrays may be accessed using JavaScript style "dot" notation to drill deep
* intot he configuration files. For example, asking for "database.connectors.sqlite"
* would return the connector closure for SQLite stored in the database configuration
* file. If no specific item is specfied, the entire configuration array is returned.
*
* Like most Laravel "get" functions, a default value may be provided, and it will
* be returned if the requested file or item doesn't exist.
2011-08-18 19:56:29 -05:00
*
2011-09-08 17:49:16 -05:00
* <code>
2011-09-16 19:59:20 -05:00
* // Get the "timezone" option from the application config file
2011-09-08 17:49:16 -05:00
* $timezone = Config::get('application.timezone');
*
2011-09-16 19:59:20 -05:00
* // Get an option, but return a default value if it doesn't exist
* $value = Config::get('some.option', 'Default');
2011-09-08 17:49:16 -05:00
* </code>
*
2011-08-18 19:56:29 -05:00
* @param string $key
* @param string $default
* @return array
*/
2011-08-26 21:42:04 -05:00
public function get($key, $default = null)
2011-08-18 19:56:29 -05:00
{
2011-09-16 19:59:20 -05:00
return Arr::get($this->items, $key, $default);
2011-08-18 19:56:29 -05:00
}
/**
* Set a configuration item.
*
2011-09-16 19:59:20 -05:00
* Configuration items are stored in the application/config directory, and provide
* general configuration options for a wide range of Laravel facilities.
*
* Like the "get" method, this method uses JavaScript style "dot" notation to access
* and manipulate the arrays in the configuration files. Also, like the "get" method,
* if no specific item is specified, the entire configuration array will be set.
2011-08-18 19:56:29 -05:00
*
2011-09-08 17:49:16 -05:00
* <code>
2011-09-16 19:59:20 -05:00
* // Set the "timezone" option in the "application" array
2011-09-08 17:49:16 -05:00
* Config::set('application.timezone', 'America/Chicago');
*
2011-09-16 19:59:20 -05:00
* // Set the entire "session" configuration array
* Config::set('session', $array);
2011-09-08 17:49:16 -05:00
* </code>
*
2011-08-18 19:56:29 -05:00
* @param string $key
* @param mixed $value
* @return void
*/
2011-08-26 21:42:04 -05:00
public function set($key, $value)
2011-08-18 19:56:29 -05:00
{
2011-09-16 19:59:20 -05:00
Arr::set($this->items, $key, $value);
2011-08-18 19:56:29 -05:00
}
}