Download the PHP package philiprehberger/env-validator without Composer

On this page you can find all versions of the php package philiprehberger/env-validator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package env-validator

PHP Env Validator

Tests Latest Version on Packagist Last updated

Validate required environment variables with type checking and defaults.

Requirements

Installation

Usage

Required Variables

Check that environment variables are present:

Schema with Type Rules

Define variables with type validation in a single call:

Default Values

Provide fallback values for variables that may not be set:

Optional Variables

Optional variables generate warnings but do not cause validation failure:

Type Validation

Add type rules to individual variables:

Validate or Fail

Throw an exception if validation fails:

IP Validation

Validate IP addresses with specific version constraints:

Custom Validation Rules

Define your own validation logic with a callable:

Enum Validation

Validate that a value matches one of a backed enum's cases:

Dependency Rules

Make variables conditionally required based on other variables:

.env File Parsing

Validate a .env file without loading it into the environment:

The parser handles comments, quoted values, multiline values, export prefix, and ${VAR} interpolation.

Environment Profiles

Register named validation profiles for different environments:

Supported Types

Type Description
string Always passes (any string value)
int, integer Numeric digits, optionally prefixed with -
float, number Any numeric value (uses is_numeric)
bool, boolean true, false, 1, 0, yes, no (case-insensitive)
url Valid URL (uses FILTER_VALIDATE_URL)
email Valid email (uses FILTER_VALIDATE_EMAIL)
ip Valid IP address (uses FILTER_VALIDATE_IP)
ipv4 Valid IPv4 address
ipv6 Valid IPv6 address
json Valid JSON string

API

EnvValidator

Method Description
required(array $vars): PendingValidation Define required environment variables
schema(array $rules): PendingValidation Define variables with type rules
fromFile(string $path): PendingFileValidation Validate a .env file without loading it
profile(string $name, array $schema): void Register a named validation profile
validateProfile(string $name): ValidationResult Validate against a named profile

PendingValidation

Method Description
optional(array $vars): self Add optional variables (warnings only)
defaults(array $defaults): self Set default values for missing variables
type(string $var, string $type): self Add a type rule for a variable
custom(string $var, callable $validator, string $message = ''): self Add a custom validation rule
enum(string $var, string $enumClass): self Validate against a backed enum
dependsOn(string $var, string $dependency): self Require variable only when dependency is set
requiredIf(string $var, string $conditionVar, mixed $value): self Require variable when condition equals value
requiredUnless(string $var, string $conditionVar, mixed $value): self Require variable unless condition equals value
validate(): ValidationResult Run validation and return result
validateOrFail(): void Run validation, throw on failure

ValidationResult

Property Type Description
passed bool Whether validation passed
missing array<string> List of missing required variables
invalid array<string, string> Map of variable names to error messages
warnings array<string> List of warning messages
toArray() array Convert result to array

Development

Support

If you find this project useful:

Star the repo

🐛 Report issues

💡 Suggest features

❤️ Sponsor development

🌐 All Open Source Projects

💻 GitHub Profile

🔗 LinkedIn Profile

License

MIT


All versions of env-validator with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package philiprehberger/env-validator contains the following files

Loading the files please wait ...