PHP code example of ghostwriter / environment

1. Go to this page and download the library: Download ghostwriter/environment 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/ */

    

ghostwriter / environment example snippets


$environment = new \Ghostwriter\Environment\Environment();

$environment->has('APP_ENV'); // false
$environment->get('APP_ENV', 'dev'); // dev
$environment->get('APP_ENV'); // throws NotFoundException
$environment->set('APP_ENV', 'production');
$environment->has('APP_ENV'); // true
$environment->get('APP_ENV'); // production
$environment->unset('APP_ENV');

$environment->set('APP_KEY', 'secrete');
$environment->has('APP_KEY'); // true
$environment->get('APP_KEY'); // secrete
$environment->unset('APP_KEY');
$environment->has('APP_KEY'); // false
$environment->get('APP_KEY', 'fallback-value'); // fallback-value
$environment->get('APP_KEY'); // throws NotFoundException

interface Variables extends Countable, IteratorAggregate
{
    public function count(): int;
    public function get(string $name, string|null $default = null): string;
    /**
     * @return Generator<non-empty-string,non-empty-string>
     */
    public function getIterator(): Generator;
    public function has(string $name): bool;
    public function set(string $name, string $value): void;
    /**
     * @return non-empty-array<non-empty-string,non-empty-string>
     */
    public function toArray(): array;
    public function unset(string $name): void;
}