PHP code example of philiprehberger / env-validator

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

    

philiprehberger / env-validator example snippets


use PhilipRehberger\EnvValidator\EnvValidator;

$result = EnvValidator::de(', ', $result->missing);
}

$result = EnvValidator::schema([
    'APP_PORT' => 'int',
    'APP_DEBUG' => 'bool',
    'APP_URL' => 'url',
    'ADMIN_EMAIL' => 'email',
])->validate();

$result = EnvValidator::  'APP_PORT' => '8080',
        'APP_ENV' => 'production',
    ])
    ->validate();

$result = EnvValidator::DRIVER', 'QUEUE_CONNECTION'])
    ->validate();

// $result->warnings contains notices about unset optional vars

$result = EnvValidator::'int')
    ->type('API_URL', 'url')
    ->validate();

use PhilipRehberger\EnvValidator\Exceptions\EnvValidationException;

try {
    EnvValidator::
    // Access the full result
    $result = $e->result;
}

$result = EnvValidator:: 'ip')
    ->type('GATEWAY_V4', 'ipv4')
    ->type('GATEWAY_V6', 'ipv6')
    ->validate();

$result = EnvValidator::T', fn (string $value) => strlen($value) >= 32, 'Secret must be at least 32 characters.')
    ->validate();

enum Environment: string
{
    case Production = 'production';
    case Staging = 'staging';
    case Development = 'development';
}

$result = EnvValidator::

// DB_HOST is only ator::', 'DB_DRIVER')
    ->validate();

// REDIS_HOST is redIf('REDIS_HOST', 'CACHE_DRIVER', 'redis')
    ->validate();

// APP_SECRET is 

$result = EnvValidator::fromFile('/path/to/.env')
    ->type('APP_PORT', 'int')
    ->type('APP_URL', 'url')
    ->validate();

// Register profiles
EnvValidator::profile('web', [
    'APP_URL' => 'url',
    'APP_PORT' => 'int',
    'APP_DEBUG' => 'bool',
]);

EnvValidator::profile('worker', [
    'QUEUE_CONNECTION' => 'string',
    'REDIS_HOST' => 'string',
]);

// Validate against a profile
$result = EnvValidator::validateProfile('web');