https://github.com/cryptiklemur/environment-php
Environment Class for PHP
https://github.com/cryptiklemur/environment-php
Last synced: 10 months ago
JSON representation
Environment Class for PHP
- Host: GitHub
- URL: https://github.com/cryptiklemur/environment-php
- Owner: cryptiklemur
- License: apache-2.0
- Created: 2014-04-08T03:25:44.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2020-09-24T19:57:27.000Z (over 5 years ago)
- Last Synced: 2025-08-12T15:46:45.587Z (10 months ago)
- Language: PHP
- Size: 26.4 KB
- Stars: 11
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Environment
===========
This class is pretty simple. It adds environments to your PHP project.
## To Install
Install with composer:
```sh
composer require aequasi/environment
```
## To Use
To get set up, drop the `Environment` class in your front controller. For example:
```php
getType();
// Above will echo 'dev';
var_dump($environment->isDebug());
// Above will dump true
```
You can set what the default environment is with `Environment::$DEFAULT_ENVIRONMENT` (`string`),
and you can set what environments are in debug mode with `Environment::$DEBUG_TYPES` (`string[]`).
The allowed environments can also be changed by overriding the `Environment::$DEFAULT_TYPE` (`string[]`) parameter.
### Setting Environments
Once you are ready to start using other environments (`test`, `staging`, and `prod`), there are a couple ways to do that.
#### 1. `php.ini`
In your `php.ini` file, setting `php.environment` will set the environment for all processes using the php for that php.ini
#### 2. `$_SERVER['PHP_ENVIRONMENT']`
You can either use Apache or Nginx to set a server variable, or you can modify your `$_SERVER` header to set the environment
* For Apache, use [`SetEnv`][0]
* And Nginx is a little different. Check [this][1] StackOverflow post for an example.
#### 3. CLI Arguments
If you are using the `SymfonyEnvironment` class, you can tie into the arguments (`--env` and `--no-debug`) by creating your environment
a little differently:
```php
#!/usr/bin/env php
isDebug() ) {
Debug::enable();
}
$kernel = new AppKernel( $env->getType(), $env->isDebug() );
$application = new Application($kernel);
$application->run( $input );
```
[0]: http://httpd.apache.org/docs/2.2/mod/mod_env.html#SetEnv
[1]: http://stackoverflow.com/a/19491780/248903