From 2f24307e5124c4f2f337cba2da8e5ce5655c74f4 Mon Sep 17 00:00:00 2001 From: devcoder-xyz Date: Wed, 20 Mar 2024 06:19:51 +0000 Subject: [PATCH] Improved documentation for better clarity and understanding. --- .phpunit.result.cache | 1 + README.md | 103 +++++++++-------- composer.json | 2 +- composer.lock | 175 +++++++++++++++-------------- src/DotEnv.php | 52 +++++---- src/Processor/BooleanProcessor.php | 5 + src/Processor/IProcessor.php | 5 + src/Processor/NumberProcessor.php | 9 ++ src/Processor/QuotedProcessor.php | 7 +- 9 files changed, 198 insertions(+), 161 deletions(-) create mode 100644 .phpunit.result.cache diff --git a/.phpunit.result.cache b/.phpunit.result.cache new file mode 100644 index 0000000..c14ca70 --- /dev/null +++ b/.phpunit.result.cache @@ -0,0 +1 @@ +{"version":1,"defects":[],"times":{"Test\\DevCoder\\DotenvTest::testLoad":0.002,"Test\\DevCoder\\DotenvTest::testFileNotExist":0.001,"Test\\DevCoder\\DotenvTest::testIncompatibleProcessors":0.002,"Test\\DevCoder\\DotenvTest::testProcessBoolean":0.001,"Test\\DevCoder\\DotenvTest::testDontProcessBoolean":0.001,"Test\\DevCoder\\DotenvTest::testProcessQuotes":0.001,"Test\\DevCoder\\DotenvTest::testDontProcessQuotes":0.001,"Test\\DevCoder\\DotenvTest::testProcessNumbers":0.001}} \ No newline at end of file diff --git a/README.md b/README.md index 81d0c23..3c6d63f 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,31 @@ -# php-dotenv -# Loads environment variables from .env file to getenv(), $_ENV and $_SERVER. +# PHP-DotEnv + [![Latest Stable Version](https://poser.pugx.org/devcoder-xyz/php-dotenv/v)](https://packagist.org/packages/devcoder-xyz/php-dotenv) [![Total Downloads](https://poser.pugx.org/devcoder-xyz/php-dotenv/downloads)](https://packagist.org/packages/devcoder-xyz/php-dotenv) [![Latest Unstable Version](https://poser.pugx.org/devcoder-xyz/php-dotenv/v/unstable)](//packagist.org/packages/devcoder-xyz/php-dotenv) [![License](https://poser.pugx.org/devcoder-xyz/php-dotenv/license)](https://packagist.org/packages/devcoder-xyz/php-dotenv) [![PHP Version Require](http://poser.pugx.org/devcoder-xyz/php-dotenv/require/php)](https://packagist.org/packages/devcoder-xyz/php-dotenv) +## Introduction +PHP-DotEnv is a lightweight PHP library designed to simplify the management of environment variables in your PHP applications. It provides an elegant solution for loading configuration values from a `.env` file into the environment variables accessible via `getenv()`, `$_ENV`, and `$_SERVER`. This documentation aims to guide you through the installation, usage, and features of PHP-DotEnv. + ## Installation -Use [Composer](https://getcomposer.org/) +To install PHP-DotEnv, you can use [Composer](https://getcomposer.org/), the dependency manager for PHP. ### Composer Require -``` +```bash composer require devcoder-xyz/php-dotenv ``` ## Requirements -* PHP version 7.4 +- PHP version 7.4 or higher -**How to use ?** +## Usage -``` +### 1. Define Environment Variables + +Before using PHP-DotEnv, you need to define your environment variables in a `.env` file. This file should be placed in the root directory of your project. Each line in the file should follow the `KEY=VALUE` format. + +```dotenv APP_ENV=dev DATABASE_DNS=mysql:host=localhost;dbname=test; DATABASE_USER="root" @@ -28,7 +35,9 @@ NUMBER_LITERAL=0 NULL_VALUE=null ``` -## Load the variables +### 2. Load the Variables + +After defining your environment variables, you can load them into your PHP application using PHP-DotEnv. ```php load(); ``` -# Use them! +### 3. Access Environment Variables + +Once loaded, you can access the environment variables using PHP's `getenv()` function. + ```php /** - * string(33) "mysql:host=localhost;dbname=test;" + * Retrieve the value of DATABASE_DNS */ var_dump(getenv('DATABASE_DNS')); +``` -/** - * Removes double and single quotes from the variable: - * - * string(4) "root" - */ -var_dump(getenv('DATABASE_USER')); +### Automatic Type Conversion -/** - * Processes booleans as such: - * - * bool(true) - */ -var_dump(getenv('MODULE_ENABLED')); +PHP-DotEnv provides automatic type conversion for certain types of values: -/** - * Process the numeric value: - * - * int(0) - */ -var_dump(getenv('NUMBER_LITERAL')); +- Booleans: Processed as `true` or `false`. +- Quoted Strings: Surrounding quotes are removed. +- Null Values: Converted to `null`. +- Numeric Values: Converted to integers or floats. -/** - * Check for literal null values: - * - * NULL - */ -var_dump(getenv('NULL_VALUE')); -``` +## Processors + +PHP-DotEnv allows you to define custom processors to handle specific types of values in your `.env` file. These processors enable you to control how values are parsed and converted. -Ideal for small project +### BooleanProcessor -Simple and easy! +The `BooleanProcessor` converts boolean values specified in the `.env` file to PHP boolean types (`true` or `false`). -# Processors +```dotenv +MODULE_ENABLED=true +``` -Also the variables are parsed according to the configuration passed as parameter to the constructor. The available processors are: +### QuotedProcessor -## BooleanProcessor +The `QuotedProcessor` removes surrounding quotes from quoted strings in the `.env` file. -``VARIABLE=false`` will be processed to ```bool(false)``` +```dotenv +DATABASE_USER="root" +``` -NOTE: ``VARIABLE="true"`` will be processed to ```string(4) "true"``` +### NullProcessor -## QuotedProcessor +The `NullProcessor` converts the string "null" to the PHP `null` value. -``VARIABLE="anything"`` will be processed to ```string(8) "anything"``` +```dotenv +NULL_VALUE=null +``` -## NullProcessor +### NumberProcessor -``VARIABLE=null`` will be processed to ```NULL``` +The `NumberProcessor` converts numeric values to integers or floats. -## NumberProcessor +```dotenv +NUMBER_LITERAL=0 +``` -``VARIABLE=0`` will be processed to ```int(0)``` +## Conclusion -``VARIABLE=0.1`` will be processed to ```float(0.1)``` \ No newline at end of file +PHP-DotEnv offers a straightforward and efficient solution for managing environment variables in PHP applications. By providing automatic type conversion and customizable processors, it simplifies the process of loading and handling configuration values from `.env` files. Whether you're working on a small project or a large-scale application, PHP-DotEnv can help streamline your development process and ensure smooth configuration management. Explore its features, integrate it into your projects, and experience the convenience it brings to your PHP development workflow. \ No newline at end of file diff --git a/composer.json b/composer.json index 5e7833b..f6a1b98 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "devcoder-xyz/php-dotenv", - "description": "Parses .env files", + "description": "PHP-DotEnv is a lightweight PHP library designed to simplify the management of environment variables in your PHP applications.", "type": "library", "license": "MIT", "authors": [ diff --git a/composer.lock b/composer.lock index aa621e3..f5a8cfd 100644 --- a/composer.lock +++ b/composer.lock @@ -79,16 +79,16 @@ }, { "name": "myclabs/deep-copy", - "version": "1.11.0", + "version": "1.11.1", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "14daed4296fae74d9e3201d2c4925d1acb7aa614" + "reference": "7284c22080590fb39f2ffa3e9057f10a4ddd0e0c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/14daed4296fae74d9e3201d2c4925d1acb7aa614", - "reference": "14daed4296fae74d9e3201d2c4925d1acb7aa614", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/7284c22080590fb39f2ffa3e9057f10a4ddd0e0c", + "reference": "7284c22080590fb39f2ffa3e9057f10a4ddd0e0c", "shasum": "" }, "require": { @@ -126,7 +126,7 @@ ], "support": { "issues": "https://github.com/myclabs/DeepCopy/issues", - "source": "https://github.com/myclabs/DeepCopy/tree/1.11.0" + "source": "https://github.com/myclabs/DeepCopy/tree/1.11.1" }, "funding": [ { @@ -134,29 +134,31 @@ "type": "tidelift" } ], - "time": "2022-03-03T13:19:32+00:00" + "time": "2023-03-08T13:26:56+00:00" }, { "name": "nikic/php-parser", - "version": "v4.15.3", + "version": "v5.0.2", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "570e980a201d8ed0236b0a62ddf2c9cbb2034039" + "reference": "139676794dc1e9231bf7bcd123cfc0c99182cb13" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/570e980a201d8ed0236b0a62ddf2c9cbb2034039", - "reference": "570e980a201d8ed0236b0a62ddf2c9cbb2034039", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/139676794dc1e9231bf7bcd123cfc0c99182cb13", + "reference": "139676794dc1e9231bf7bcd123cfc0c99182cb13", "shasum": "" }, "require": { + "ext-ctype": "*", + "ext-json": "*", "ext-tokenizer": "*", - "php": ">=7.0" + "php": ">=7.4" }, "require-dev": { "ircmaxell/php-yacc": "^0.0.7", - "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0 || ^9.0" + "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0" }, "bin": [ "bin/php-parse" @@ -164,7 +166,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.9-dev" + "dev-master": "5.0-dev" } }, "autoload": { @@ -188,26 +190,27 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v4.15.3" + "source": "https://github.com/nikic/PHP-Parser/tree/v5.0.2" }, - "time": "2023-01-16T22:05:37+00:00" + "time": "2024-03-05T20:51:40+00:00" }, { "name": "phar-io/manifest", - "version": "2.0.3", + "version": "2.0.4", "source": { "type": "git", "url": "https://github.com/phar-io/manifest.git", - "reference": "97803eca37d319dfa7826cc2437fc020857acb53" + "reference": "54750ef60c58e43759730615a392c31c80e23176" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phar-io/manifest/zipball/97803eca37d319dfa7826cc2437fc020857acb53", - "reference": "97803eca37d319dfa7826cc2437fc020857acb53", + "url": "https://api.github.com/repos/phar-io/manifest/zipball/54750ef60c58e43759730615a392c31c80e23176", + "reference": "54750ef60c58e43759730615a392c31c80e23176", "shasum": "" }, "require": { "ext-dom": "*", + "ext-libxml": "*", "ext-phar": "*", "ext-xmlwriter": "*", "phar-io/version": "^3.0.1", @@ -248,9 +251,15 @@ "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", "support": { "issues": "https://github.com/phar-io/manifest/issues", - "source": "https://github.com/phar-io/manifest/tree/2.0.3" + "source": "https://github.com/phar-io/manifest/tree/2.0.4" }, - "time": "2021-07-20T11:28:43+00:00" + "funding": [ + { + "url": "https://github.com/theseer", + "type": "github" + } + ], + "time": "2024-03-03T12:33:53+00:00" }, { "name": "phar-io/version", @@ -305,23 +314,23 @@ }, { "name": "phpunit/php-code-coverage", - "version": "9.2.24", + "version": "9.2.31", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "2cf940ebc6355a9d430462811b5aaa308b174bed" + "reference": "48c34b5d8d983006bd2adc2d0de92963b9155965" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/2cf940ebc6355a9d430462811b5aaa308b174bed", - "reference": "2cf940ebc6355a9d430462811b5aaa308b174bed", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/48c34b5d8d983006bd2adc2d0de92963b9155965", + "reference": "48c34b5d8d983006bd2adc2d0de92963b9155965", "shasum": "" }, "require": { "ext-dom": "*", "ext-libxml": "*", "ext-xmlwriter": "*", - "nikic/php-parser": "^4.14", + "nikic/php-parser": "^4.18 || ^5.0", "php": ">=7.3", "phpunit/php-file-iterator": "^3.0.3", "phpunit/php-text-template": "^2.0.2", @@ -336,8 +345,8 @@ "phpunit/phpunit": "^9.3" }, "suggest": { - "ext-pcov": "*", - "ext-xdebug": "*" + "ext-pcov": "PHP extension that provides line coverage", + "ext-xdebug": "PHP extension that provides line coverage as well as branch and path coverage" }, "type": "library", "extra": { @@ -370,7 +379,8 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.24" + "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.31" }, "funding": [ { @@ -378,7 +388,7 @@ "type": "github" } ], - "time": "2023-01-26T08:26:55+00:00" + "time": "2024-03-02T06:37:42+00:00" }, { "name": "phpunit/php-file-iterator", @@ -725,16 +735,16 @@ }, { "name": "sebastian/cli-parser", - "version": "1.0.1", + "version": "1.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/cli-parser.git", - "reference": "442e7c7e687e42adc03470c7b668bc4b2402c0b2" + "reference": "2b56bea83a09de3ac06bb18b92f068e60cc6f50b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/cli-parser/zipball/442e7c7e687e42adc03470c7b668bc4b2402c0b2", - "reference": "442e7c7e687e42adc03470c7b668bc4b2402c0b2", + "url": "https://api.github.com/repos/sebastianbergmann/cli-parser/zipball/2b56bea83a09de3ac06bb18b92f068e60cc6f50b", + "reference": "2b56bea83a09de3ac06bb18b92f068e60cc6f50b", "shasum": "" }, "require": { @@ -769,7 +779,7 @@ "homepage": "https://github.com/sebastianbergmann/cli-parser", "support": { "issues": "https://github.com/sebastianbergmann/cli-parser/issues", - "source": "https://github.com/sebastianbergmann/cli-parser/tree/1.0.1" + "source": "https://github.com/sebastianbergmann/cli-parser/tree/1.0.2" }, "funding": [ { @@ -777,7 +787,7 @@ "type": "github" } ], - "time": "2020-09-28T06:08:49+00:00" + "time": "2024-03-02T06:27:43+00:00" }, { "name": "sebastian/code-unit", @@ -966,20 +976,20 @@ }, { "name": "sebastian/complexity", - "version": "2.0.2", + "version": "2.0.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/complexity.git", - "reference": "739b35e53379900cc9ac327b2147867b8b6efd88" + "reference": "25f207c40d62b8b7aa32f5ab026c53561964053a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/complexity/zipball/739b35e53379900cc9ac327b2147867b8b6efd88", - "reference": "739b35e53379900cc9ac327b2147867b8b6efd88", + "url": "https://api.github.com/repos/sebastianbergmann/complexity/zipball/25f207c40d62b8b7aa32f5ab026c53561964053a", + "reference": "25f207c40d62b8b7aa32f5ab026c53561964053a", "shasum": "" }, "require": { - "nikic/php-parser": "^4.7", + "nikic/php-parser": "^4.18 || ^5.0", "php": ">=7.3" }, "require-dev": { @@ -1011,7 +1021,7 @@ "homepage": "https://github.com/sebastianbergmann/complexity", "support": { "issues": "https://github.com/sebastianbergmann/complexity/issues", - "source": "https://github.com/sebastianbergmann/complexity/tree/2.0.2" + "source": "https://github.com/sebastianbergmann/complexity/tree/2.0.3" }, "funding": [ { @@ -1019,20 +1029,20 @@ "type": "github" } ], - "time": "2020-10-26T15:52:27+00:00" + "time": "2023-12-22T06:19:30+00:00" }, { "name": "sebastian/diff", - "version": "4.0.4", + "version": "4.0.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "3461e3fccc7cfdfc2720be910d3bd73c69be590d" + "reference": "ba01945089c3a293b01ba9badc29ad55b106b0bc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/3461e3fccc7cfdfc2720be910d3bd73c69be590d", - "reference": "3461e3fccc7cfdfc2720be910d3bd73c69be590d", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/ba01945089c3a293b01ba9badc29ad55b106b0bc", + "reference": "ba01945089c3a293b01ba9badc29ad55b106b0bc", "shasum": "" }, "require": { @@ -1077,7 +1087,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/diff/issues", - "source": "https://github.com/sebastianbergmann/diff/tree/4.0.4" + "source": "https://github.com/sebastianbergmann/diff/tree/4.0.6" }, "funding": [ { @@ -1085,7 +1095,7 @@ "type": "github" } ], - "time": "2020-10-26T13:10:38+00:00" + "time": "2024-03-02T06:30:58+00:00" }, { "name": "sebastian/environment", @@ -1152,16 +1162,16 @@ }, { "name": "sebastian/exporter", - "version": "4.0.5", + "version": "4.0.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "ac230ed27f0f98f597c8a2b6eb7ac563af5e5b9d" + "reference": "78c00df8f170e02473b682df15bfcdacc3d32d72" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/ac230ed27f0f98f597c8a2b6eb7ac563af5e5b9d", - "reference": "ac230ed27f0f98f597c8a2b6eb7ac563af5e5b9d", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/78c00df8f170e02473b682df15bfcdacc3d32d72", + "reference": "78c00df8f170e02473b682df15bfcdacc3d32d72", "shasum": "" }, "require": { @@ -1217,7 +1227,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/exporter/issues", - "source": "https://github.com/sebastianbergmann/exporter/tree/4.0.5" + "source": "https://github.com/sebastianbergmann/exporter/tree/4.0.6" }, "funding": [ { @@ -1225,20 +1235,20 @@ "type": "github" } ], - "time": "2022-09-14T06:03:37+00:00" + "time": "2024-03-02T06:33:00+00:00" }, { "name": "sebastian/global-state", - "version": "5.0.5", + "version": "5.0.7", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "0ca8db5a5fc9c8646244e629625ac486fa286bf2" + "reference": "bca7df1f32ee6fe93b4d4a9abbf69e13a4ada2c9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/0ca8db5a5fc9c8646244e629625ac486fa286bf2", - "reference": "0ca8db5a5fc9c8646244e629625ac486fa286bf2", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bca7df1f32ee6fe93b4d4a9abbf69e13a4ada2c9", + "reference": "bca7df1f32ee6fe93b4d4a9abbf69e13a4ada2c9", "shasum": "" }, "require": { @@ -1281,7 +1291,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/global-state/issues", - "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.5" + "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.7" }, "funding": [ { @@ -1289,24 +1299,24 @@ "type": "github" } ], - "time": "2022-02-14T08:28:10+00:00" + "time": "2024-03-02T06:35:11+00:00" }, { "name": "sebastian/lines-of-code", - "version": "1.0.3", + "version": "1.0.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/lines-of-code.git", - "reference": "c1c2e997aa3146983ed888ad08b15470a2e22ecc" + "reference": "e1e4a170560925c26d424b6a03aed157e7dcc5c5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/c1c2e997aa3146983ed888ad08b15470a2e22ecc", - "reference": "c1c2e997aa3146983ed888ad08b15470a2e22ecc", + "url": "https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/e1e4a170560925c26d424b6a03aed157e7dcc5c5", + "reference": "e1e4a170560925c26d424b6a03aed157e7dcc5c5", "shasum": "" }, "require": { - "nikic/php-parser": "^4.6", + "nikic/php-parser": "^4.18 || ^5.0", "php": ">=7.3" }, "require-dev": { @@ -1338,7 +1348,7 @@ "homepage": "https://github.com/sebastianbergmann/lines-of-code", "support": { "issues": "https://github.com/sebastianbergmann/lines-of-code/issues", - "source": "https://github.com/sebastianbergmann/lines-of-code/tree/1.0.3" + "source": "https://github.com/sebastianbergmann/lines-of-code/tree/1.0.4" }, "funding": [ { @@ -1346,7 +1356,7 @@ "type": "github" } ], - "time": "2020-11-28T06:42:11+00:00" + "time": "2023-12-22T06:20:34+00:00" }, { "name": "sebastian/object-enumerator", @@ -1525,16 +1535,16 @@ }, { "name": "sebastian/resource-operations", - "version": "3.0.3", + "version": "3.0.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/resource-operations.git", - "reference": "0f4443cb3a1d92ce809899753bc0d5d5a8dd19a8" + "reference": "05d5692a7993ecccd56a03e40cd7e5b09b1d404e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/0f4443cb3a1d92ce809899753bc0d5d5a8dd19a8", - "reference": "0f4443cb3a1d92ce809899753bc0d5d5a8dd19a8", + "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/05d5692a7993ecccd56a03e40cd7e5b09b1d404e", + "reference": "05d5692a7993ecccd56a03e40cd7e5b09b1d404e", "shasum": "" }, "require": { @@ -1546,7 +1556,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0-dev" + "dev-main": "3.0-dev" } }, "autoload": { @@ -1567,8 +1577,7 @@ "description": "Provides a list of PHP built-in functions that operate on resources", "homepage": "https://www.github.com/sebastianbergmann/resource-operations", "support": { - "issues": "https://github.com/sebastianbergmann/resource-operations/issues", - "source": "https://github.com/sebastianbergmann/resource-operations/tree/3.0.3" + "source": "https://github.com/sebastianbergmann/resource-operations/tree/3.0.4" }, "funding": [ { @@ -1576,7 +1585,7 @@ "type": "github" } ], - "time": "2020-09-28T06:45:17+00:00" + "time": "2024-03-14T16:00:52+00:00" }, { "name": "sebastian/type", @@ -1689,16 +1698,16 @@ }, { "name": "theseer/tokenizer", - "version": "1.2.1", + "version": "1.2.3", "source": { "type": "git", "url": "https://github.com/theseer/tokenizer.git", - "reference": "34a41e998c2183e22995f158c581e7b5e755ab9e" + "reference": "737eda637ed5e28c3413cb1ebe8bb52cbf1ca7a2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/theseer/tokenizer/zipball/34a41e998c2183e22995f158c581e7b5e755ab9e", - "reference": "34a41e998c2183e22995f158c581e7b5e755ab9e", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/737eda637ed5e28c3413cb1ebe8bb52cbf1ca7a2", + "reference": "737eda637ed5e28c3413cb1ebe8bb52cbf1ca7a2", "shasum": "" }, "require": { @@ -1727,7 +1736,7 @@ "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", "support": { "issues": "https://github.com/theseer/tokenizer/issues", - "source": "https://github.com/theseer/tokenizer/tree/1.2.1" + "source": "https://github.com/theseer/tokenizer/tree/1.2.3" }, "funding": [ { @@ -1735,7 +1744,7 @@ "type": "github" } ], - "time": "2021-07-28T10:34:58+00:00" + "time": "2024-03-03T12:36:25+00:00" } ], "aliases": [], @@ -1747,5 +1756,5 @@ "php": ">=7.4" }, "platform-dev": [], - "plugin-api-version": "2.1.0" + "plugin-api-version": "2.3.0" } diff --git a/src/DotEnv.php b/src/DotEnv.php index 37a013e..5ccd255 100644 --- a/src/DotEnv.php +++ b/src/DotEnv.php @@ -37,34 +37,9 @@ public function __construct(string $path, array $processors = null) $this->setProcessors($processors); } - private function setProcessors(array $processors = null): self - { - /** - * Fill with default processors - */ - if ($processors === null) { - $this->processors = [ - NullProcessor::class, - BooleanProcessor::class, - NumberProcessor::class, - QuotedProcessor::class - ]; - - return $this; - } - - foreach ($processors as $processor) { - if (is_subclass_of($processor, AbstractProcessor::class)) { - $this->processors[] = $processor; - } - } - - return $this; - } - /** - * Processes the $path of the instances and parses the values into $_SERVER and $_ENV, also returns all the data that has been read. - * Skips empty and commented lines. + * Loads the configuration data from the specified file path. + * Parses the values into $_SERVER and $_ENV arrays, skipping empty and commented lines. */ public function load(): void { @@ -91,6 +66,29 @@ public function load(): void } } + private function setProcessors(array $processors = null): void + { + /** + * Fill with default processors + */ + if ($processors === null) { + $this->processors = [ + NullProcessor::class, + BooleanProcessor::class, + NumberProcessor::class, + QuotedProcessor::class + ]; + return; + } + + foreach ($processors as $processor) { + if (is_subclass_of($processor, AbstractProcessor::class)) { + $this->processors[] = $processor; + } + } + } + + /** * Process the value with the configured processors * diff --git a/src/Processor/BooleanProcessor.php b/src/Processor/BooleanProcessor.php index d133470..5409d20 100644 --- a/src/Processor/BooleanProcessor.php +++ b/src/Processor/BooleanProcessor.php @@ -10,6 +10,11 @@ public function canBeProcessed(): bool return in_array($loweredValue, ['true', 'false'], true); } + /** + * Executes the PHP function and returns a boolean value indicating whether the value is 'true' in lowercase. + * + * @return bool The result of the comparison between the lowercase value of $this->value and 'true'. + */ public function execute() { return strtolower($this->value) === 'true'; diff --git a/src/Processor/IProcessor.php b/src/Processor/IProcessor.php index 7b06c80..15cb71b 100644 --- a/src/Processor/IProcessor.php +++ b/src/Processor/IProcessor.php @@ -5,6 +5,11 @@ interface IProcessor { public function __construct(string $value); + /** + * Check if the entity can be processed. + * + * @return bool + */ public function canBeProcessed(): bool; public function execute(); diff --git a/src/Processor/NumberProcessor.php b/src/Processor/NumberProcessor.php index 909cffd..f42dbdb 100644 --- a/src/Processor/NumberProcessor.php +++ b/src/Processor/NumberProcessor.php @@ -8,6 +8,15 @@ public function canBeProcessed(): bool return is_numeric($this->value); } + /** + * Executes the function and returns an integer or float value based on the input. + * + * This function uses the `filter_var` function with the `FILTER_VALIDATE_INT` filter to check if the input value can be + * converted to an integer. If the conversion is successful, the integer value is returned. Otherwise, the input value is + * cast to a float and returned. + * + * @return int|float The converted integer or float value. + */ public function execute() { $int = filter_var($this->value, FILTER_VALIDATE_INT); diff --git a/src/Processor/QuotedProcessor.php b/src/Processor/QuotedProcessor.php index 4d2a118..460ed92 100644 --- a/src/Processor/QuotedProcessor.php +++ b/src/Processor/QuotedProcessor.php @@ -14,7 +14,12 @@ public function canBeProcessed(): bool return $this->isWrappedByChar($this->value, '\''); } - + /** + * Executes the function and returns a substring of the value property of the current object, + * excluding the first and last characters. + * + * @return string The substring of the value property. + */ public function execute() { /**