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




return [

    /**
     * Validation classes which contain environment rules
     * applied by env artisan commands.
     *
     * Add your validation classes created by
     * `php artisan make:envrule` command to apply their rules
     *
     * @var array
     */
    'rules' => [
        \App\Env\BaseEnvValidationRules::class
    ]
];



namespace App\Env;

use Lionix\EnvValidator;

class BaseEnvValidationRules extends EnvValidator
{
    /**
     * Validation rules that apply to the .env variables.
     *
     * @return array
     */
    public function rules() : array
    {
        return [
            //
        ];
    }
}

...
public function rules() : array
{
    return [
        'DB_CONNECTION' => '



namespace App\Env;

use Lionix\EnvValidator;

class DatabaseEnvRules extends EnvValidator
{
    /**
     * Validation rules that apply to the .env variables.
     *
     * @return array
     */
    public function rules() : array
    {
        return [
            //
        ];
    }
}

...
public function rules() : array
{
    return [
        'DB_CONNECTION' => 'requried|in:mysql,sqlite,pgsql,sqlsrv'
        'DB_HOST' => 'requried',
        'DB_PORT' => 'requried|numeric',
        'DB_DATABASE' => 'requried',
        'DB_USERNAME' => 'requried',
        'DB_PASSWORD' => 'requried'
    ];
}
...




return [

    /**
     * Validation classes which contain environment rules
     * applied by env artisan commands.
     *
     * Add your validation classes created by
     * `php artisan make:envrule` command to apply their rules
     *
     * @var array
     */
    'rules' => [
        \App\Env\BaseEnvValidationRules::class
        \App\Env\DatabaseEnvRules::class // <- our database rules
    ]
];

...
$client = app()->make(\Lionix\Envclient::class);

$client->useValidator(new \App\Env\DatabaseEnvRules())->update($databaseCredentials);

if ($client->errors()->isNotEmpty()) {
    // handle errors
} else {
    // success, the variables are updated
}
...

php artisan vendor:publish --provider='Lionix\EnvClient\Providers\EnvClientServiceProvider' --tag='config'

php artisan make:envrule DatabaseEnvRules