-
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.
- Loading branch information
0 parents
commit 50e2364
Showing
3 changed files
with
131 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,24 @@ | ||
#Primal.Environment | ||
|
||
Created and Copyright 2012 by Jarvis Badgley, chiper at chipersoft dot com. | ||
|
||
Environment is a very simple data storage class for saving and retrieving environmental configuration variables, such as would be defined in a project's config file. | ||
|
||
* Any value can be stored or retrieved by calling a function with the name, prefixed by get or set. | ||
* Example: `$env->setConvertPath('/path/to/convert')` or `$env->getConvertPath()` | ||
* Values can also be set or retrieved directly by name: `$env->convertPath` | ||
* Set functions return $this to allow chaining | ||
* Any undefined value will retrieve as `null` | ||
|
||
##Example: | ||
|
||
```php | ||
//config.php | ||
Environment::Singleton() | ||
->setName('development') | ||
->setDBName('PrimalTest') | ||
->setDBUser('php') | ||
->setDBPassword('Ornare856') | ||
->setDebug(true) | ||
; | ||
``` |
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,22 @@ | ||
{ | ||
"name": "Primal/Environment", | ||
"description": "Very basic environmental settings management library", | ||
"homepage": "http://github.com/Primal/Environment", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Jarvis Badgley", | ||
"homepage": "http://chipersoft.com", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.3.10" | ||
}, | ||
"type": "library", | ||
"autoload": { | ||
"psr-0": { | ||
"Primal": "lib\/" | ||
} | ||
} | ||
} |
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,85 @@ | ||
<?php | ||
|
||
namespace Primal; | ||
|
||
/** | ||
* Very simple class for managing environmental variables. | ||
* | ||
* @package default | ||
*/ | ||
|
||
class Environment { | ||
protected $_data = array( | ||
'name' => 'development', | ||
); | ||
|
||
/** | ||
* Constructor, declared private to prevent external initialization | ||
* | ||
* @package default | ||
*/ | ||
private function __construct() {} | ||
|
||
/** | ||
* Singleton static variable | ||
* | ||
* @author Jarvis Badgley | ||
*/ | ||
protected static $singleton; | ||
|
||
|
||
/** | ||
* Static Singleton retrieval function | ||
* | ||
* @return Request | ||
*/ | ||
static function Singleton() { | ||
return (!static::$singleton) ? static::$singleton = new static() : static::$singleton; | ||
} | ||
|
||
|
||
/** | ||
* Getter & Setter Implementation | ||
* Any value can be stored or retrieved by calling a function with the name, prefixed by get or set. | ||
* Example: $env->setConvertPath('/path/to/convert') or $env->getConvertPath() | ||
* Set functions return $this to allow chaining | ||
* | ||
* @param string $name | ||
* @param array $args | ||
* @return void|$this | ||
*/ | ||
public function __call($name, $args) { | ||
switch (substr($name, 0, 3)) { | ||
|
||
case 'get': | ||
$index = strtolower(substr($name, 3)); | ||
return isset($this->_data[$index]) ? $this->_data[$index] : null; | ||
|
||
case 'set': | ||
$index = strtolower(substr($name, 4)); | ||
$this->_data[$index] = $args[0]; | ||
return $this; | ||
|
||
default: | ||
throw new \BadMethodCallException("Unknown function, Environment->$name."); | ||
|
||
} | ||
} | ||
|
||
|
||
|
||
public function __get($index) { | ||
$index = strtolower($index); | ||
return isset($this->_data[$index]) ? $this->_data[$index] : null; | ||
} | ||
|
||
public function __set($index, $value) { | ||
$this->_data[strtolower($index)] = $value; | ||
} | ||
|
||
public function __isset($index) { | ||
return isset($this->_data[strtolower($index)]); | ||
} | ||
|
||
|
||
} |