PHP code example of markwalet / environment-manager
1. Go to this page and download the library: Download markwalet/environment-manager library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
markwalet / environment-manager example snippets
MarkWalet\EnvironmentManager\EnvironmentManagerServiceProvider::class
$app->register(\MarkWalet\EnvironmentManager\EnvironmentManagerServiceProvider::class);
$environment = app(Environment::class);
$environment->add("FOO", "Bar")->after("OTHER_KEY");
$environment->update("EXISTING_KEY", "updatedValue");
/**
* Original content:
*
* TEST1=value1
* TEST2=value2
* TEST3=value3
*/
$environment->mutate(function(EnvironmentBuilder $builder){
$builder->add('TEST4', 'escaped value');
$builder->update('TEST2', 'updated')->after('TEST3');
$builder->delete('TEST1');
});
/**
* New content:
*
* TEST3=value3
* TEST2=updated
* TEST4="escaped value"
*/
use MarkWalet\EnvironmentManager\Changes\Change;
class Increment extends Change
{
use HasKey;
function __construct(string $key)
{
$this->key = $key;
}
/**
* Apply the pending change to the given content.
*
* @param $content
*
* @return mixed
*/
public function apply(string $content): string
{
$search = '/'.$this->getKey().'=(.*)/';
preg_match($search, $content, $matches);
$value = $matches[1];
$replacement = $this->getKey().'='.($value + 1);
return preg_replace($search, $replacement, $content);
}
}
$environment->extend('increment', Increment::class);
/**
* Original content:
*
* TEST1=value1
* INCREMENT=56
*/
$environment->increment('INCREMENT');
/**
* New content:
*
* TEST1=value1
* INCREMENT=57
*/