first commit

This commit is contained in:
Sampanna Rimal
2024-08-27 17:48:06 +05:45
commit 53c0140f58
10839 changed files with 1125847 additions and 0 deletions

42
vendor/league/config/CHANGELOG.md vendored Normal file
View File

@ -0,0 +1,42 @@
# Change Log
All notable changes to this project will be documented in this file.
Updates should follow the [Keep a CHANGELOG](https://keepachangelog.com/) principles.
## [Unreleased][unreleased]
## [1.2.0] - 2022-12-11
### Changed
- Values can now be set prior to the corresponding schema being registered.
- `exists()` and `get()` now only trigger validation for the relevant schema, not the entire config at once.
## [1.1.1] - 2021-08-14
### Changed
- Bumped the minimum version of dflydev/dot-access-data for PHP 8.1 support
## [1.1.0] - 2021-06-19
### Changed
- Bumped the minimum PHP version to 7.4+
- Bumped the minimum version of nette/schema to 1.2.0
## [1.0.1] - 2021-05-31
### Fixed
- Fixed the `ConfigurationExceptionInterface` marker interface not extending `Throwable` (#2)
## [1.0.0] - 2021-05-31
Initial release! 🎉
[unreleased]: https://github.com/thephpleague/config/compare/v1.2.0...main
[1.2.0]: https://github.com/thephpleague/config/compare/v1.1.1...v.1.2.0
[1.1.1]: https://github.com/thephpleague/config/compare/v1.1.0...v1.1.1
[1.1.0]: https://github.com/thephpleague/config/compare/v1.0.1...v1.1.0
[1.0.1]: https://github.com/thephpleague/config/compare/v1.0.0...v1.0.1
[1.0.0]: https://github.com/thephpleague/config/releases/tag/v1.0.0

28
vendor/league/config/LICENSE.md vendored Normal file
View File

@ -0,0 +1,28 @@
BSD 3-Clause License
Copyright (c) 2022, Colin O'Dell. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

153
vendor/league/config/README.md vendored Normal file
View File

@ -0,0 +1,153 @@
# league/config
[![Latest Version](https://img.shields.io/packagist/v/league/config.svg?style=flat-square)](https://packagist.org/packages/league/config)
[![Total Downloads](https://img.shields.io/packagist/dt/league/config.svg?style=flat-square)](https://packagist.org/packages/league/config)
[![Software License](https://img.shields.io/badge/License-BSD--3-brightgreen.svg?style=flat-square)](LICENSE)
[![Build Status](https://img.shields.io/github/workflow/status/thephpleague/config/Tests/main.svg?style=flat-square)](https://github.com/thephpleague/config/actions?query=workflow%3ATests+branch%3Amain)
[![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/thephpleague/config.svg?style=flat-square)](https://scrutinizer-ci.com/g/thephpleague/config/code-structure)
[![Quality Score](https://img.shields.io/scrutinizer/g/thephpleague/config.svg?style=flat-square)](https://scrutinizer-ci.com/g/thephpleague/config)
[![Sponsor development of this project](https://img.shields.io/badge/sponsor%20this%20package-%E2%9D%A4-ff69b4.svg?style=flat-square)](https://www.colinodell.com/sponsor)
**league/config** helps you define nested configuration arrays with strict schemas and access configuration values with dot notation. It was created by [Colin O'Dell][@colinodell].
## 📦 Installation
This project requires PHP 7.4 or higher. To install it via [Composer] simply run:
```bash
composer require league/config
```
## 🧰️ Basic Usage
The `Configuration` class provides everything you need to define the configuration structure and fetch values:
```php
use League\Config\Configuration;
use Nette\Schema\Expect;
// Define your configuration schema
$config = new Configuration([
'database' => Expect::structure([
'driver' => Expect::anyOf('mysql', 'postgresql', 'sqlite')->required(),
'host' => Expect::string()->default('localhost'),
'port' => Expect::int()->min(1)->max(65535),
'ssl' => Expect::bool(),
'database' => Expect::string()->required(),
'username' => Expect::string()->required(),
'password' => Expect::string()->nullable(),
]),
'logging' => Expect::structure([
'enabled' => Expect::bool()->default($_ENV['DEBUG'] == true),
'file' => Expect::string()->deprecated("use logging.path instead"),
'path' => Expect::string()->assert(function ($path) { return \is_writeable($path); })->required(),
]),
]);
// Set the values, either all at once with `merge()`:
$config->merge([
'database' => [
'driver' => 'mysql',
'port' => 3306,
'database' => 'mydb',
'username' => 'user',
'password' => 'secret',
],
]);
// Or one-at-a-time with `set()`:
$config->set('logging.path', '/var/log/myapp.log');
// You can now retrieve those values with `get()`.
// Validation and defaults will be applied for you automatically
$config->get('database'); // Fetches the entire "database" section as an array
$config->get('database.driver'); // Fetch a specific nested value with dot notation
$config->get('database/driver'); // Fetch a specific nested value with slash notation
$config->get('database.host'); // Returns the default value "localhost"
$config->get('logging.path'); // Guaranteed to be writeable thanks to the assertion in the schema
// If validation fails an `InvalidConfigurationException` will be thrown:
$config->set('database.driver', 'mongodb');
$config->get('database.driver'); // InvalidConfigurationException
// Attempting to fetch a non-existent key will result in an `InvalidConfigurationException`
$config->get('foo.bar');
// You could avoid this by checking whether that item exists:
$config->exists('foo.bar'); // Returns `false`
```
## 📓 Documentation
Full documentation can be found at [config.thephpleague.com][docs].
## 💭 Philosophy
This library aims to provide a **simple yet opinionated** approach to configuration with the following goals:
- The configuration should operate on **arrays with nested values** which are easily accessible
- The configuration structure should be **defined with strict schemas** defining the overall structure, allowed types, and allowed values
- Schemas should be defined using a **simple, fluent interface**
- You should be able to **add and combine schemas but never modify existing ones**
- Both the configuration values and the schema should be **defined and managed with PHP code**
- Schemas should be **immutable**; they should never change once they are set
- Configuration values should never define or influence the schemas
As a result, this library will likely **never** support features like:
- Loading and/or exporting configuration values or schemas using YAML, XML, or other files
- Parsing configuration values from a command line or other user interface
- Dynamically changing the schema, allowed values, or default values based on other configuration values
If you need that functionality you should check out other libraries like:
- [symfony/config]
- [symfony/options-resolver]
- [hassankhan/config]
- [consolidation/config]
- [laminas/laminas-config]
## 🏷️ Versioning
[SemVer](http://semver.org/) is followed closely. Minor and patch releases should not introduce breaking changes to the codebase.
Any classes or methods marked `@internal` are not intended for use outside this library and are subject to breaking changes at any time, so please avoid using them.
## 🛠️ Maintenance & Support
When a new **minor** version (e.g. `1.0` -> `1.1`) is released, the previous one (`1.0`) will continue to receive security and critical bug fixes for *at least* 3 months.
When a new **major** version is released (e.g. `1.1` -> `2.0`), the previous one (`1.1`) will receive critical bug fixes for *at least* 3 months and security updates for 6 months after that new release comes out.
(This policy may change in the future and exceptions may be made on a case-by-case basis.)
## 👷‍️ Contributing
Contributions to this library are **welcome**! We only ask that you adhere to our [contributor guidelines] and avoid making changes that conflict with our Philosophy above.
## 🧪 Testing
```bash
composer test
```
## 📄 License
**league/config** is licensed under the BSD-3 license. See the [`LICENSE.md`][license] file for more details.
## 🗺️ Who Uses It?
This project is used by [league/commonmark][league-commonmark].
[docs]: https://config.thephpleague.com/
[@colinodell]: https://www.twitter.com/colinodell
[Composer]: https://getcomposer.org/
[PHP League]: https://thephpleague.com
[symfony/config]: https://symfony.com/doc/current/components/config.html
[symfony/options-resolver]: https://symfony.com/doc/current/components/options_resolver.html
[hassankhan/config]: https://github.com/hassankhan/config
[consolidation/config]: https://github.com/consolidation/config
[laminas/laminas-config]: https://docs.laminas.dev/laminas-config/
[contributor guidelines]: https://github.com/thephpleague/config/blob/main/.github/CONTRIBUTING.md
[license]: https://github.com/thephpleague/config/blob/main/LICENSE.md
[league-commonmark]: https://commonmark.thephpleague.com

69
vendor/league/config/composer.json vendored Normal file
View File

@ -0,0 +1,69 @@
{
"name": "league/config",
"type": "library",
"description": "Define configuration arrays with strict schemas and access values with dot notation",
"keywords": ["configuration","config","schema","array","nested","dot","dot-access"],
"homepage": "https://config.thephpleague.com",
"license": "BSD-3-Clause",
"authors": [
{
"name": "Colin O'Dell",
"email": "colinodell@gmail.com",
"homepage": "https://www.colinodell.com",
"role": "Lead Developer"
}
],
"support": {
"docs": "https://config.thephpleague.com/",
"issues": "https://github.com/thephpleague/config/issues",
"rss": "https://github.com/thephpleague/config/releases.atom",
"source": "https://github.com/thephpleague/config"
},
"require": {
"php": "^7.4 || ^8.0",
"dflydev/dot-access-data": "^3.0.1",
"nette/schema": "^1.2"
},
"require-dev": {
"phpstan/phpstan": "^1.8.2",
"phpunit/phpunit": "^9.5.5",
"scrutinizer/ocular": "^1.8.1",
"unleashedtech/php-coding-standard": "^3.1",
"vimeo/psalm": "^4.7.3"
},
"minimum-stability": "dev",
"prefer-stable": true,
"autoload": {
"psr-4": {
"League\\Config\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"League\\Config\\Tests\\": "tests"
}
},
"scripts": {
"phpcs": "phpcs",
"phpstan": "phpstan analyse",
"phpunit": "phpunit --no-coverage",
"psalm": "psalm",
"test": [
"@phpcs",
"@phpstan",
"@psalm",
"@phpunit"
]
},
"extra": {
"branch-alias": {
"dev-main": "1.2-dev"
}
},
"config": {
"sort-packages": true,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}

View File

@ -0,0 +1,255 @@
<?php
declare(strict_types=1);
/*
* This file is part of the league/config package.
*
* (c) Colin O'Dell <colinodell@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace League\Config;
use Dflydev\DotAccessData\Data;
use Dflydev\DotAccessData\DataInterface;
use Dflydev\DotAccessData\Exception\DataException;
use Dflydev\DotAccessData\Exception\InvalidPathException;
use Dflydev\DotAccessData\Exception\MissingPathException;
use League\Config\Exception\UnknownOptionException;
use League\Config\Exception\ValidationException;
use Nette\Schema\Expect;
use Nette\Schema\Processor;
use Nette\Schema\Schema;
use Nette\Schema\ValidationException as NetteValidationException;
final class Configuration implements ConfigurationBuilderInterface, ConfigurationInterface
{
/** @psalm-readonly */
private Data $userConfig;
/**
* @var array<string, Schema>
*
* @psalm-allow-private-mutation
*/
private array $configSchemas = [];
/** @psalm-allow-private-mutation */
private Data $finalConfig;
/**
* @var array<string, mixed>
*
* @psalm-allow-private-mutation
*/
private array $cache = [];
/** @psalm-readonly */
private ConfigurationInterface $reader;
/**
* @param array<string, Schema> $baseSchemas
*/
public function __construct(array $baseSchemas = [])
{
$this->configSchemas = $baseSchemas;
$this->userConfig = new Data();
$this->finalConfig = new Data();
$this->reader = new ReadOnlyConfiguration($this);
}
/**
* Registers a new configuration schema at the given top-level key
*
* @psalm-allow-private-mutation
*/
public function addSchema(string $key, Schema $schema): void
{
$this->invalidate();
$this->configSchemas[$key] = $schema;
}
/**
* {@inheritDoc}
*
* @psalm-allow-private-mutation
*/
public function merge(array $config = []): void
{
$this->invalidate();
$this->userConfig->import($config, DataInterface::REPLACE);
}
/**
* {@inheritDoc}
*
* @psalm-allow-private-mutation
*/
public function set(string $key, $value): void
{
$this->invalidate();
try {
$this->userConfig->set($key, $value);
} catch (DataException $ex) {
throw new UnknownOptionException($ex->getMessage(), $key, (int) $ex->getCode(), $ex);
}
}
/**
* {@inheritDoc}
*
* @psalm-external-mutation-free
*/
public function get(string $key)
{
if (\array_key_exists($key, $this->cache)) {
return $this->cache[$key];
}
try {
$this->build(self::getTopLevelKey($key));
return $this->cache[$key] = $this->finalConfig->get($key);
} catch (InvalidPathException | MissingPathException $ex) {
throw new UnknownOptionException($ex->getMessage(), $key, (int) $ex->getCode(), $ex);
}
}
/**
* {@inheritDoc}
*
* @psalm-external-mutation-free
*/
public function exists(string $key): bool
{
if (\array_key_exists($key, $this->cache)) {
return true;
}
try {
$this->build(self::getTopLevelKey($key));
return $this->finalConfig->has($key);
} catch (InvalidPathException | UnknownOptionException $ex) {
return false;
}
}
/**
* @psalm-mutation-free
*/
public function reader(): ConfigurationInterface
{
return $this->reader;
}
/**
* @psalm-external-mutation-free
*/
private function invalidate(): void
{
$this->cache = [];
$this->finalConfig = new Data();
}
/**
* Applies the schema against the configuration to return the final configuration
*
* @throws ValidationException|UnknownOptionException|InvalidPathException
*
* @psalm-allow-private-mutation
*/
private function build(string $topLevelKey): void
{
if ($this->finalConfig->has($topLevelKey)) {
return;
}
if (! isset($this->configSchemas[$topLevelKey])) {
throw new UnknownOptionException(\sprintf('Missing config schema for "%s"', $topLevelKey), $topLevelKey);
}
try {
$userData = [$topLevelKey => $this->userConfig->get($topLevelKey)];
} catch (DataException $ex) {
$userData = [];
}
try {
$schema = $this->configSchemas[$topLevelKey];
$processor = new Processor();
$processed = $processor->process(Expect::structure([$topLevelKey => $schema]), $userData);
$this->raiseAnyDeprecationNotices($processor->getWarnings());
$this->finalConfig->import((array) self::convertStdClassesToArrays($processed));
} catch (NetteValidationException $ex) {
throw new ValidationException($ex);
}
}
/**
* Recursively converts stdClass instances to arrays
*
* @phpstan-template T
*
* @param T $data
*
* @return mixed
*
* @phpstan-return ($data is \stdClass ? array<string, mixed> : T)
*
* @psalm-pure
*/
private static function convertStdClassesToArrays($data)
{
if ($data instanceof \stdClass) {
$data = (array) $data;
}
if (\is_array($data)) {
foreach ($data as $k => $v) {
$data[$k] = self::convertStdClassesToArrays($v);
}
}
return $data;
}
/**
* @param string[] $warnings
*/
private function raiseAnyDeprecationNotices(array $warnings): void
{
foreach ($warnings as $warning) {
@\trigger_error($warning, \E_USER_DEPRECATED);
}
}
/**
* @throws InvalidPathException
*/
private static function getTopLevelKey(string $path): string
{
if (\strlen($path) === 0) {
throw new InvalidPathException('Path cannot be an empty string');
}
$path = \str_replace(['.', '/'], '.', $path);
$firstDelimiter = \strpos($path, '.');
if ($firstDelimiter === false) {
return $path;
}
return \substr($path, 0, $firstDelimiter);
}
}

View File

@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
/*
* This file is part of the league/config package.
*
* (c) Colin O'Dell <colinodell@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace League\Config;
/**
* Implement this class to facilitate setter injection of the configuration where needed
*/
interface ConfigurationAwareInterface
{
public function setConfiguration(ConfigurationInterface $configuration): void;
}

View File

@ -0,0 +1,21 @@
<?php
declare(strict_types=1);
/*
* This file is part of the league/config package.
*
* (c) Colin O'Dell <colinodell@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace League\Config;
/**
* An interface that provides the ability to set both the schema and configuration values
*/
interface ConfigurationBuilderInterface extends MutableConfigurationInterface, SchemaBuilderInterface
{
}

View File

@ -0,0 +1,46 @@
<?php
declare(strict_types=1);
/*
* This file is part of the league/config package.
*
* (c) Colin O'Dell <colinodell@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace League\Config;
use League\Config\Exception\UnknownOptionException;
use League\Config\Exception\ValidationException;
/**
* Interface for reading configuration values
*/
interface ConfigurationInterface
{
/**
* @param string $key Configuration option path/key
*
* @psalm-param non-empty-string $key
*
* @return mixed
*
* @throws ValidationException if the schema failed to validate the given input
* @throws UnknownOptionException if the requested key does not exist or is malformed
*/
public function get(string $key);
/**
* @param string $key Configuration option path/key
*
* @psalm-param non-empty-string $key
*
* @return bool Whether the given option exists
*
* @throws ValidationException if the schema failed to validate the given input
*/
public function exists(string $key): bool;
}

View File

@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
/*
* This file is part of the league/config package.
*
* (c) Colin O'Dell <colinodell@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace League\Config;
/**
* Interface for a service which provides a readable configuration object
*/
interface ConfigurationProviderInterface
{
public function getConfiguration(): ConfigurationInterface;
}

View File

@ -0,0 +1,21 @@
<?php
declare(strict_types=1);
/*
* This file is part of the league/config package.
*
* (c) Colin O'Dell <colinodell@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace League\Config\Exception;
/**
* Marker interface for any/all exceptions thrown by this library
*/
interface ConfigurationExceptionInterface extends \Throwable
{
}

View File

@ -0,0 +1,46 @@
<?php
declare(strict_types=1);
/*
* This file is part of the league/config package.
*
* (c) Colin O'Dell <colinodell@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace League\Config\Exception;
class InvalidConfigurationException extends \UnexpectedValueException implements ConfigurationExceptionInterface
{
/**
* @param string $option Name/path of the option
* @param mixed $valueGiven The invalid option that was provided
* @param ?string $description Additional text describing the issue (optional)
*/
public static function forConfigOption(string $option, $valueGiven, ?string $description = null): self
{
$message = \sprintf('Invalid config option for "%s": %s', $option, self::getDebugValue($valueGiven));
if ($description !== null) {
$message .= \sprintf(' (%s)', $description);
}
return new self($message);
}
/**
* @param mixed $value
*
* @psalm-pure
*/
private static function getDebugValue($value): string
{
if (\is_object($value)) {
return \get_class($value);
}
return \print_r($value, true);
}
}

View File

@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
/*
* This file is part of the league/config package.
*
* (c) Colin O'Dell <colinodell@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace League\Config\Exception;
use Throwable;
final class UnknownOptionException extends \InvalidArgumentException implements ConfigurationExceptionInterface
{
private string $path;
public function __construct(string $message, string $path, int $code = 0, ?Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
$this->path = $path;
}
public function getPath(): string
{
return $this->path;
}
}

View File

@ -0,0 +1,37 @@
<?php
declare(strict_types=1);
/*
* This file is part of the league/config package.
*
* (c) Colin O'Dell <colinodell@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace League\Config\Exception;
use Nette\Schema\ValidationException as NetteException;
final class ValidationException extends InvalidConfigurationException
{
/** @var string[] */
private array $messages;
public function __construct(NetteException $innerException)
{
parent::__construct($innerException->getMessage(), (int) $innerException->getCode(), $innerException);
$this->messages = $innerException->getMessages();
}
/**
* @return string[]
*/
public function getMessages(): array
{
return $this->messages;
}
}

View File

@ -0,0 +1,34 @@
<?php
declare(strict_types=1);
/*
* This file is part of the league/config package.
*
* (c) Colin O'Dell <colinodell@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace League\Config;
use League\Config\Exception\UnknownOptionException;
/**
* Interface for setting/merging user-defined configuration values into the configuration object
*/
interface MutableConfigurationInterface
{
/**
* @param mixed $value
*
* @throws UnknownOptionException if $key contains a nested path which doesn't point to an array value
*/
public function set(string $key, $value): void;
/**
* @param array<string, mixed> $config
*/
public function merge(array $config = []): void;
}

View File

@ -0,0 +1,40 @@
<?php
declare(strict_types=1);
/*
* This file is part of the league/config package.
*
* (c) Colin O'Dell <colinodell@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace League\Config;
/**
* Provides read-only access to a given Configuration object
*/
final class ReadOnlyConfiguration implements ConfigurationInterface
{
private Configuration $config;
public function __construct(Configuration $config)
{
$this->config = $config;
}
/**
* {@inheritDoc}
*/
public function get(string $key)
{
return $this->config->get($key);
}
public function exists(string $key): bool
{
return $this->config->exists($key);
}
}

View File

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
/*
* This file is part of the league/config package.
*
* (c) Colin O'Dell <colinodell@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace League\Config;
use Nette\Schema\Schema;
/**
* Interface that allows new schemas to be added to a configuration
*/
interface SchemaBuilderInterface
{
/**
* Registers a new configuration schema at the given top-level key
*/
public function addSchema(string $key, Schema $schema): void;
}