Skip to content

Commit

Permalink
Added composer.json, modified README
Browse files Browse the repository at this point in the history
  • Loading branch information
nvanderburg committed Oct 3, 2016
1 parent 8d1d923 commit ccae143
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/vendor/
13 changes: 9 additions & 4 deletions DetectEnv.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@
*/
class DetectEnv
{
public $defaultEnv = 'prod';
public function __construct($params)
{
public static $defaultEnv = 'prod';

/**
* Return env depending on server name
* @param $params
* @return string
*/
public static function get($params){
$serverName = $_SERVER['SERVER_NAME'];
if(isset($params[$serverName])){
return $params[$serverName];
}
return $this->defaultEnv;
return self::$defaultEnv;
}
}
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,36 @@
# detectenv
Simple PHP Class to get environment depende on server name

Installation
------------

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist proximity/detectenv "*"
```

or add

```
"proximity/detectenv": "*"
```

to the require section of your `composer.json` file.


Usage
-----

Once the extension is installed, simply use it in your code by :

```php
$hosts = [
'mydevhost.dev'=>'dev',
'mytesthost.com'=>'test',
'myprodhost.com'=>'prod',
];
$env = \proximity\detectenv\DetectEnv::get($hosts);
```
14 changes: 14 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "proximity/detectenv",
"description": "A simple PHP class to detect environment depending on server name",
"type": "library",
"require": {
"php": ">=5.4.0"
},
"authors": [
{
"name": "n.vanderburg",
"email": "nvanderburg@proximity.es"
}
]
}

0 comments on commit ccae143

Please sign in to comment.