PHP code example of lionix / envclient

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

    

lionix / envclient example snippets


'rules' => [
    \App\Env\BaseEnvValidationRules::class,
],

namespace App\Env;

use Lionix\EnvClient\Services\EnvValidator;

class BaseEnvValidationRules extends EnvValidator
{
    public function rules(): array
    {
        return [
            'APP_ENV' => ['

'rules' => [
    \Lionix\EnvClient\Rules\AppRules::class,
    \Lionix\EnvClient\Rules\DatabaseRules::class,
    \App\Env\BaseEnvValidationRules::class,
],

namespace App\Env;

use Illuminate\Support\Str;
use Lionix\EnvClient\Services\EnvGenerator;

class DeploymentEnv extends EnvGenerator
{
    public function values(): array
    {
        return [
            'QUEUE_CONNECTION' => 'redis',
            'SESSION_DRIVER' => 'redis',
            'APP_KEY' => fn () => 'base64:'.base64_encode(random_bytes(32)),
            'WEBHOOK_SECRET' => fn () => Str::random(40),
        ];
    }
}

'generators' => [
    \App\Env\DeploymentEnv::class,
],

use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Log;
use Lionix\EnvClient\Events\EnvironmentFileUpdated;

Event::listen(function (EnvironmentFileUpdated $event) {
    Log::info('Environment updated', ['file' => $event->path, 'keys' => $event->keys()]);
});

use Lionix\EnvClient\Facades\EnvClient;
use Lionix\EnvClient\Rules\DatabaseRules;

$client = EnvClient::useValidator(new DatabaseRules())
    ->update([
        'DB_HOST' => '127.0.0.1',
        'DB_DATABASE' => 'forge',
    ]);

if ($client->errors()->isNotEmpty()) {
    // $client->errors() is an Illuminate\Support\MessageBag
}

EnvClient::forget(['LEGACY_API_URL']);
bash
php artisan vendor:publish --tag=envclient
bash
php artisan env:set APP_NAME "My Application"
php artisan env:get APP_NAME
php artisan env:unset OLD_FEATURE_FLAG LEGACY_API_URL
bash
$ php artisan env:get DB_PASSWORD
********

$ php artisan env:get DB_PASSWORD --reveal
hunter2
bash
$ php artisan env:diff
  WARN  Missing from the environment file:
  ⇂ NEW_FEATURE_FLAG

$ php artisan env:sync
  INFO  Added to the environment file:
  ⇂ NEW_FEATURE_FLAG
bash
$ php artisan env:set APP_ENV prod
   ERROR  The selected APP_ENV is invalid.

$ php artisan env:check
   ERROR  The selected APP_ENV is invalid.
bash
php artisan make:envrule DatabaseEnvRules
php artisan make:envrule Services/MailEnvRules   # app/Env/Services/MailEnvRules.php
bash
php artisan make:envgenerator DeploymentEnv