Download the PHP package vilnisgr/env-editor without Composer

On this page you can find all versions of the php package vilnisgr/env-editor. 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-editor

EnvEditor

Advanced .env Parser, Writer, Schema Validator, and Config Factory for PHP

EnvEditor is a full-featured environment management toolkit for modern PHP projectsβ€”
designed to replace fragile string-based .env handling with a structured, validated, type-safe, and developer-friendly system.

This documentation covers every part of the library in depth:

πŸ”Ή Writer (editing .env files with order control & multiline support)
πŸ”Ή Reader / Parser (accurately parses any real-world dotenv file)
πŸ”Ή Formatter (ensures valid dotenv formatting & escaping)
πŸ”Ή Schema Validator (required/optional keys, casting, rules, grouping)
πŸ”Ή Rules Engine (min/max/regex/length/in/custom)
πŸ”Ή Config Factory (DTO Generator) for type-safe config objects
πŸ”Ή Vanilla PHP Integration Guide
πŸ”Ή Full examples for every method


Features

Feature Category Description
Parser High-precision dotenv parser with strict key validation, escape handling, and export removal.
Writer Smart writer with ordering, spacing, top/bottom, before/after insertion.
Multiline Support Fully supports multiline values with proper quote detection and unescaping.
Comments Preserves inline comments and full line comments exactly as they appear.
Atomic Saving Safer writes using temp files to prevent corruption.
Casting Built-in casting: array, json, bool, float, int.
Enum Casting Convert values into backed PHP enums automatically.
Validation Rules min, max, regex, in, length, custom callbacks.
Schema Groups Namespaced schemas: e.g., group('DB_', fn($db) => … ).
DTO Factory Build typed objects from env via EnvConfigFactory.
Env Loader Loads validated env values into putenv(), $_ENV, and $_SERVER.
Test Coverage Comprehensive test suite validating all core features.

Installation


Usage Guide


1. DOTENV WRITER – FULL DOCUMENTATION & TUTORIAL

1.1 Creating the writer


1.2 Setting / updating a key

If the key exists, it's updated.
If not, it's added at the bottom.


1.3 Insert AFTER another key


1.4 Insert BEFORE a key


1.5 Spacing (adds blank lines before inserting)


1.6 Insert at TOP or BOTTOM


1.7 Array-style positioning


1.8 Remove a key


1.9 Import multiple keys


1.10 Export env to array


1.11 Save (atomic & non-atomic)


1.12 Preview without saving


1.13 Backup & Restore


1.14 Diff

Returns:


1.15 Merge

overrideExisting:

Example:
Current .env has : APP_ENV=production
other file has : APP_ENV=local

merge(..., false) -> keeps the value from your current .env ("production")
merge(..., true) -> replaces it with the value from the other file ("local")


2. DOTENV PARSER

Inline comments preserved

export` keyword support

Multiline values

Escapes recognized

Key validation

Key must match:


3. VALUE FORMATTER

Ensures correct .env formatting.

Auto-quotes values containing:

Escape rules


4. ENV LOADER

Loads parsed env into:

Example:


5. ENV SCHEMA – COMPLETE VALIDATOR


Type Casts

Method Result
int() converts "123" β†’ 123
float() "1.5" β†’ 1.5
bool() "true" β†’ true
array() "a,b,c" β†’ ['a','b','c']
json() '{"a":1}' β†’ ['a'=>1]
castEnum() "A" β†’ Enum::A

Validation Rules


Schema Groups

Generates:


6. CONFIG FACTORY – DTO BUILDER


7. VANILLA PHP INTEGRATION

AppConfig.php (DTO class)

Loading .env and creating config

Retrieving env values (3 different ways)


1. From the writer (raw .env, uncasted)


2. From the typed DTO


3. From PHP runtime environment (after EnvLoader)

When to use which?


8. FULL LIST OF ALL PUBLIC METHODS

Writer Methods

Method Description
load() Load a .env file into the writer.
set() Add or update a key with optional position & spacing.
remove() Remove a key from the file.
save() Save the file (atomic or non-atomic).
preview() Get the output without writing to disk.
toArray() Export all env entries as key => value.
import() Import an associative array of values.
has() Check if a key exists.
missingKeys() Return keys missing from the file.
backup() Create a backup of the env file.
restore() Restore from a backup.
diff() Compare against another env file.
merge() Merge another env file into the current one.
after() Insert the next set() after a specific key.
before() Insert the next set() before a specific key.
top() Insert the next set() at the top.
bottom() Insert the next set() at the bottom.
spacing() Add blank lines before inserting with set().

Schema Methods

Method Description
required() Define keys that must appear in the env.
optional() Define optional keys with default values.
cast() Cast a key using a specific type (int, bool, etc.).
bool() Convenience method: cast to boolean.
int() Convenience method: cast to integer.
float() Cast to float.
array() Cast comma-separated lists to arrays.
json() Cast values to decoded JSON arrays.
castEnum() Cast value into a PHP backed enum.
rules() Get the rules object for adding validation rules.
group() Create grouped/namespaced schemas (e.g., DB_HOST).
validate() Validate & cast writer values based on schema.

Rules Methods

Method Description
add() Add a custom validation rule (callable).
validate() Validate a value against all rules for a key.
min() Require numeric value >= minimum.
max() Require numeric value <= maximum.
in() Require value to be in a fixed allow-list.
regex() Require value to match a regular expression.
length() Require string length to be between [min,max].
export() Export all rules for use in grouped schemas.

ConfigFactory Methods

Method Description
make() Build a typed configuration DTO from validated environment variables.

License, Author & Support

EnvEditor - Complete .env Toolkit for PHP
Maintained by: VilnisGrinbergs2000
License: MIT (Free for commercial and private use)
Source Code & Issues: https://github.com/VilnisGrinbergs2000/env-editor


All versions of env-editor with dependencies

PHP Build Version
Package Version
Requires php Version >=8.3
ext-ctype Version *
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 vilnisgr/env-editor contains the following files

Loading the files please wait ...