Файловый менеджер - Редактировать - /home/tuudkjt/globeasy/wp-includes/ID3/hassankhan.tar
Назад
config/composer.json 0000777 00000002150 15251357461 0010551 0 ustar 00 { "name": "hassankhan\/config", "type": "library", "description": "Lightweight configuration file loader that supports PHP, INI, XML, JSON, and YAML files", "keywords": [ "configuration", "config", "json", "yaml", "yml", "ini", "xml", "unframework", "microphp" ], "homepage": "http:\/\/hassankhan.me\/config\/", "license": "MIT", "authors": [ { "name": "Hassan Khan", "role": "Developer", "homepage": "http:\/\/hassankhan.me\/" } ], "require": { "php": ">=7.4" }, "require-dev": { "phpunit\/phpunit": "^9.5", "scrutinizer\/ocular": "^1.9", "squizlabs\/php_codesniffer": "^3.6", "symfony\/yaml": "^5.4" }, "suggest": { "symfony\/yaml": "^5.4" }, "autoload": { "psr-4": { "Rvx\\Noodlehaus\\": "src" } }, "autoload-dev": { "psr-4": { "Rvx\\Noodlehaus\\Test\\": "tests" } }, "config": { "sort-packages": true } } config/LICENSE.md 0000777 00000002124 15251357461 0007434 0 ustar 00 The MIT License (MIT) Copyright © 2015 Hassan Khan <contact@hassankhan.me> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. config/CHANGELOG.md 0000777 00000011166 15251357461 0007647 0 ustar 00 # Changelog All notable changes to `Config` will be documented in this file ## 3.2.0 - 2024-12-09 ### Added * PHP 8.3 and 8.4 to the build matrix (#164) ### Fixed * Fatal error when root is null in has() method (#159 and #160) * PHP 8.4 deprecations implicitly marking parameter as nullable is deprecated (#163) ## 3.1.0 - 2022-12-20 ### Added * PHP 8.2 to the build matrix (#154) ### Fixed * Use assertEquals instead of assertSame (#153) * Namespaces in tests (#154) ### Removed * .travis.yml file (#152) * support for the end of life PHP versions (#144) ## 3.0.1 - 2022-03-26 ### Added - Fix merge method (#145 and #147) ## 3.0.0 - 2021-12-30 ### Added - Move CI to GitHub actions (#132, #136 and #137) - PHP 8.0 support, adding it to the build matrix (#138 and #139) - PHP 8.1 support, adding it to the build matrix (#135, #140 and #141) ## 2.2.0 - 2020-12-07 ### Added - Serialization support (#127) - Support for Properties files (#128) ### Fixed - Test enhancement (#126) - Typehint on Xml parser, parse method (#130) ## 2.1.0 - 2019-09-01 ### Added - Support for writing configuration back to file and string (#122) ## 2.0.2 - 2019-04-06 ### Fixed - Implementations of `ParserInterface` and cleanup (#120) - Tests for PHP 7 ## 2.0.1 - 2019-02-02 ### Fixed - Parsing PHP file (#114) - Parsing PHP string with `$config` variable (#118) ## 2.0.0 - 2018-10-03 ### Added - Usage of short array syntax (#109) - Support for string parsers (#111) ### Breaking changes - Changes of interface and parsers ## 1.1.0 - 2018-08-22 ### Added - Added support for PHP constants in YAML (#112) ## 1.0.1 - 2018-03-31 ### Fixed - Possibility to use an own file parser (#103) ## 1.0.0 - 2018-03-03 ### Added - Merge support (#96) - Set PHP 5.5.9 as minimum required version (#75 and #99) ### Fixed - Fix PHP 5.6 test (#100) - Edit PHP versions tested on Travis (#101) - Add more info about the symfony/yaml requirement (#97 and #102) ### Breaking changes - PHP 5.3 and 5.4 are no longer supported. ## 0.10.0 - 2016-02-11 ### Added - Package-level exceptions so callers can catch exceptions at package-level - Added support for files suffixed with the `.dist` extension ### Fixed - Rearranged error-handling in `FileParser\Json` for better test coverage - Project-wide code style fixes to adhere to PSR-2 - Fixes `has()` method returning `false` on `null` values in a config field ## 0.9.1 - 2016-01-23 ### Added - PHP 7.0 is now tested on Travis ## 0.9.0 - 2015-10-22 ### Added - Added namespace to example in `README.md` - Added `has()` method to `ConfigInterface` and implemented in `AbstractConfig` - Added `all()` method to `ConfigInterface` and implemented in `AbstractConfig` - Added documentation for new methods - `AbstractConfig` now implements the `Iterator` interface ### Fixed - PSR-2 compliance - Give YamlParser file content instead of path - Updated `AbstractConfig` constructor to only accept arrays - Removed check to fix loading an empty array - Fix for #44: Warnings emitted if configuration file is empty - Fix for #55: Unset cache after a set ## 0.8.2 - 2015-03-21 ### Fixed - Some code smells in `Config` - Updated README.md ## 0.8.1 - 2015-03-21 ### Fixed - Various things relating to recent repo transfer ## 0.8.0 - 2015-03-21 ### Added - Individual `FileParser` classes for each filetype, and a `FileParserInterface` to type-hint methods with - Optional paths; you can now prefix a path with '?' and `Config` will skip the file if it doesn't exist ### Fixed - Made the Symfony YAML component a suggested dependency - Parent constructor was not being called from `Config` ## 0.7.1 - 2015-02-24 ### Added - Moved file logic into file-specific loaders ### Fixed - Corrected class name in README.md ## 0.7.0 - 2015-02-23 ### Fixed - Removed kludgy hack for YAML/YML ## 0.6.0 - 2015-02-23 ### Added - Can now extend `AbstractConfig` to create simple subclasses without any file IO ## 0.5.0 - 2015-02-23 ### Added - Moved file logic into file-specific loaders ### Fixed - Cleaned up exception class constructors, PSR-2 compliance ## 0.4.0 - 2015-02-22 ### Fixed - Moved file logic into file-specific loaders ## 0.3.0 - 2015-02-22 ### Fixed - Created new classes `ConfigInterface` and `AbstractConfig` to simplify code ## 0.2.1 - 2015-02-22 ### Added - Array and directory support in constructor ### Fixed - Corrected deprecated usage of `Symfony\Yaml` ## 0.2.0 - 2015-02-21 ### Added - Array and directory support in constructor ### Fixed - Now can load .YAML and .YML files ## 0.1.0 - 2014-11-27 ### Added - Uses PSR-4 for autoloading - Supports YAML - Now uses custom exceptions ## 0.0.1 - 2014-11-19 ### Added - Tagged first release config/CONTRIBUTING.md 0000777 00000002472 15251357461 0010267 0 ustar 00 # Contributing Contributions are **welcome** and will be fully **credited**. We accept contributions via Pull Requests on [GitHub](https://github.com/noodlehaus/config). ## Pull Requests - **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer). - **Add tests!** - Your patch won't be accepted if it doesn't have tests. - **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. - **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option. - **Use Git Flow** - Don't ask us to pull from your master branch. Set up [Git Flow](http://nvie.com/posts/a-successful-git-branching-model/) and create a new feature branch from `develop` - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. - **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please squash them before submitting. ## Running Tests ``` bash $ phpunit ``` **Happy coding**! config/src/Exception/UnsupportedFormatException.php 0000777 00000000201 15251357461 0016640 0 ustar 00 <?php namespace Rvx\Noodlehaus\Exception; use Rvx\Noodlehaus\Exception; class UnsupportedFormatException extends Exception { } config/src/Exception/EmptyDirectoryException.php 0000777 00000000176 15251357461 0016135 0 ustar 00 <?php namespace Rvx\Noodlehaus\Exception; use Rvx\Noodlehaus\Exception; class EmptyDirectoryException extends Exception { } config/src/Exception/FileNotFoundException.php 0000777 00000000174 15251357461 0015504 0 ustar 00 <?php namespace Rvx\Noodlehaus\Exception; use Rvx\Noodlehaus\Exception; class FileNotFoundException extends Exception { } config/src/Exception/ParseException.php 0000777 00000001267 15251357461 0014226 0 ustar 00 <?php namespace Rvx\Noodlehaus\Exception; use Rvx\Noodlehaus\ErrorException; class ParseException extends ErrorException { public function __construct(array $error) { $message = $error['message'] ?: 'There was an error parsing the file'; $code = isset($error['code']) ? $error['code'] : 0; $severity = isset($error['type']) ? $error['type'] : 1; $filename = isset($error['file']) ? $error['file'] : __FILE__; $lineno = isset($error['line']) ? $error['line'] : __LINE__; $exception = isset($error['exception']) ? $error['exception'] : null; parent::__construct($message, $code, $severity, $filename, $lineno, $exception); } } config/src/Exception/WriteException.php 0000777 00000001203 15251357461 0014234 0 ustar 00 <?php namespace Rvx\Noodlehaus\Exception; use Rvx\Noodlehaus\ErrorException; class WriteException extends ErrorException { public function __construct(array $error) { $message = isset($error['message']) ? $error['message'] : 'There was an error writing the file'; $code = isset($error['code']) ? $error['code'] : 0; $severity = isset($error['type']) ? $error['type'] : 1; $filename = isset($error['file']) ? $error['file'] : __FILE__; $exception = isset($error['exception']) ? $error['exception'] : null; parent::__construct($message, $code, $severity, $filename, $exception); } } config/src/ConfigInterface.php 0000777 00000002220 15251357461 0012353 0 ustar 00 <?php namespace Rvx\Noodlehaus; /** * Config interface * * @package Config * @author Jesus A. Domingo <jesus.domingo@gmail.com> * @author Hassan Khan <contact@hassankhan.me> * @link https://github.com/noodlehaus/config * @license MIT */ interface ConfigInterface { /** * Gets a configuration setting using a simple or nested key. * Nested keys are similar to JSON paths that use the dot * dot notation. * * @param string $key * @param mixed $default * * @return mixed */ public function get($key, $default = null); /** * Function for setting configuration values, using * either simple or nested keys. * * @param string $key * @param mixed $value * * @return void */ public function set($key, $value); /** * Function for checking if configuration values exist, using * either simple or nested keys. * * @param string $key * * @return boolean */ public function has($key); /** * Get all of the configuration items * * @return array */ public function all(); } config/src/Parser/Xml.php 0000777 00000003751 15251357461 0011333 0 ustar 00 <?php namespace Rvx\Noodlehaus\Parser; use Rvx\Noodlehaus\Exception\ParseException; /** * XML parser * * @package Config * @author Jesus A. Domingo <jesus.domingo@gmail.com> * @author Hassan Khan <contact@hassankhan.me> * @author Filip Š <projects@filips.si> * @link https://github.com/noodlehaus/config * @license MIT */ class Xml implements ParserInterface { /** * {@inheritDoc} * Parses an XML file as an array * * @throws ParseException If there is an error parsing the XML file */ public function parseFile($filename) { \libxml_use_internal_errors(\true); $data = \simplexml_load_file($filename, null, \LIBXML_NOERROR); return (array) $this->parse($data, $filename); } /** * {@inheritDoc} * Parses an XML string as an array * * @throws ParseException If there is an error parsing the XML string */ public function parseString($config) { \libxml_use_internal_errors(\true); $data = \simplexml_load_string($config, null, \LIBXML_NOERROR); return (array) $this->parse($data); } /** * Completes parsing of XML data * * @param \SimpleXMLElement|null $data * @param string $filename * * @return array|null * * @throws ParseException If there is an error parsing the XML data */ protected function parse($data = null, $filename = null) { if ($data === \false) { $errors = \libxml_get_errors(); $latestError = \array_pop($errors); $error = ['message' => $latestError->message, 'type' => $latestError->level, 'code' => $latestError->code, 'file' => $filename, 'line' => $latestError->line]; throw new ParseException($error); } $data = \json_decode(\json_encode($data), \true); return $data; } /** * {@inheritDoc} */ public static function getSupportedExtensions() { return ['xml']; } } config/src/Parser/AbstractParser.php 0000777 00000001344 15251357461 0013507 0 ustar 00 <?php namespace Rvx\Noodlehaus\Parser; /** * Abstract parser * * @package Config * @author Jesus A. Domingo <jesus.domingo@gmail.com> * @author Hassan Khan <contact@hassankhan.me> * @author Filip Š <projects@filips.si> * @link https://github.com/noodlehaus/config * @license MIT */ abstract class AbstractParser implements ParserInterface { /** * String with configuration * * @var string */ protected $config; /** * Sets the string with configuration * * @param string $config * @param string $filename * * @codeCoverageIgnore */ public function __construct($config, $filename = null) { $this->config = $config; } } config/src/Parser/Yaml.php 0000777 00000003437 15251357461 0011476 0 ustar 00 <?php namespace Rvx\Noodlehaus\Parser; use Exception; use Rvx\Symfony\Component\Yaml\Yaml as YamlParser; use Rvx\Noodlehaus\Exception\ParseException; /** * YAML parser * * @package Config * @author Jesus A. Domingo <jesus.domingo@gmail.com> * @author Hassan Khan <contact@hassankhan.me> * @author Filip Š <projects@filips.si> * @link https://github.com/noodlehaus/config * @license MIT */ class Yaml implements ParserInterface { /** * {@inheritDoc} * Loads a YAML/YML file as an array * * @throws ParseException If there is an error parsing the YAML file */ public function parseFile($filename) { try { $data = YamlParser::parseFile($filename, YamlParser::PARSE_CONSTANT); } catch (Exception $exception) { throw new ParseException(['message' => 'Error parsing YAML file', 'exception' => $exception]); } return (array) $this->parse($data); } /** * {@inheritDoc} * Loads a YAML/YML string as an array * * @throws ParseException If If there is an error parsing the YAML string */ public function parseString($config) { try { $data = YamlParser::parse($config, YamlParser::PARSE_CONSTANT); } catch (Exception $exception) { throw new ParseException(['message' => 'Error parsing YAML string', 'exception' => $exception]); } return (array) $this->parse($data); } /** * Completes parsing of YAML/YML data * * @param array $data * * @return array|null */ protected function parse($data = null) { return $data; } /** * {@inheritDoc} */ public static function getSupportedExtensions() { return ['yaml', 'yml']; } } config/src/Parser/ParserInterface.php 0000777 00000001661 15251357461 0013646 0 ustar 00 <?php namespace Rvx\Noodlehaus\Parser; /** * Config file parser interface * * @package Config * @author Jesus A. Domingo <jesus.domingo@gmail.com> * @author Hassan Khan <contact@hassankhan.me> * @author Filip Š <projects@filips.si> * @link https://github.com/noodlehaus/config * @license MIT */ interface ParserInterface { /** * Parses a configuration from file `$filename` and gets its contents as an array * * @param string $filename * * @return array */ public function parseFile($filename); /** * Parses a configuration from string `$config` and gets its contents as an array * * @param string $config * * @return array */ public function parseString($config); /** * Returns an array of allowed file extensions for this parser * * @return array */ public static function getSupportedExtensions(); } config/src/Parser/Serialize.php 0000777 00000002153 15251357461 0012515 0 ustar 00 <?php namespace Rvx\Noodlehaus\Parser; use Rvx\Noodlehaus\Exception\ParseException; /** * Class Serialize * * @package Config */ class Serialize implements ParserInterface { /** * {@inheritdoc} */ public function parseFile($filename) { $data = \file_get_contents($filename); return (array) $this->parse($data, $filename); } /** * {@inheritdoc} */ public function parseString($config) { return (array) $this->parse($config); } /** * Completes parsing of JSON data * * @param string $data * @param string $filename * @return array|null * * @throws ParseException If there is an error parsing the serialized data */ protected function parse($data = null, $filename = null) { $serializedData = @\unserialize($data); if ($serializedData === \false) { throw new ParseException(\error_get_last()); } return $serializedData; } /** * {@inheritdoc} */ public static function getSupportedExtensions() { return ['txt']; } } config/src/Parser/Properties.php 0000777 00000002765 15251357461 0012733 0 ustar 00 <?php namespace Rvx\Noodlehaus\Parser; /** * Properties parser. * * @package Config * @author Jesus A. Domingo <jesus.domingo@gmail.com> * @author Hassan Khan <contact@hassankhan.me> * @author Filip Š <projects@filips.si> * @author Mark de Groot <mail@markdegroot.nl> * @link https://github.com/noodlehaus/config * @license MIT */ class Properties implements ParserInterface { /** * {@inheritdoc} * Parses a Properties file as an array. */ public function parseFile($filename) { return $this->parse(\file_get_contents($filename)); } /** * {@inheritdoc} * Parses a Properties string as an array. */ public function parseString($config) { return $this->parse($config); } private function parse($txtProperties) { $result = []; // first remove all escaped whitespace characters: $txtProperties = \preg_replace('/(?<!\\\\)\\\\[\\r\\n\\t\\f\\v][ \\r]*/', '', $txtProperties); // next split all lines not starting with # or ! on characters = or : (unless escaped): \preg_match_all('/^([^#!].*)(?<!\\\\)[=:](.*)$/mU', $txtProperties, $matches, \PREG_SET_ORDER, 0); foreach ($matches as $match) { $result[\trim(\stripslashes($match[1]))] = \trim(\stripslashes($match[2])); } return $result; } /** * {@inheritdoc} */ public static function getSupportedExtensions() { return ['properties']; } } config/src/Parser/Ini.php 0000777 00000005603 15251357461 0011310 0 ustar 00 <?php namespace Rvx\Noodlehaus\Parser; use Rvx\Noodlehaus\Exception\ParseException; /** * INI parser * * @package Config * @author Jesus A. Domingo <jesus.domingo@gmail.com> * @author Hassan Khan <contact@hassankhan.me> * @author Filip Š <projects@filips.si> * @link https://github.com/noodlehaus/config * @license MIT */ class Ini implements ParserInterface { /** * {@inheritDoc} * Parses an INI file as an array * * @throws ParseException If there is an error parsing the INI file */ public function parseFile($filename) { $data = @\parse_ini_file($filename, \true); return $this->parse($data, $filename); } /** * {@inheritDoc} * Parses an INI string as an array * * @throws ParseException If there is an error parsing the INI string */ public function parseString($config) { $data = @\parse_ini_string($config, \true); return $this->parse($data); } /** * Completes parsing of INI data * * @param array $data * @param string $filename * * @throws ParseException If there is an error parsing the INI data */ protected function parse($data = null, $filename = null) { if (!$data) { $error = \error_get_last(); // Parse functions may return NULL but set no error if the string contains no parsable data if (!\is_array($error)) { $error["message"] = "No parsable content in data."; } $error["file"] = $filename; // if string contains no parsable data, no error is set, resulting in any previous error // persisting in error_get_last(). in php 7 this can be addressed with error_clear_last() if (\function_exists("error_clear_last")) { \error_clear_last(); } throw new ParseException($error); } return $this->expandDottedKey($data); } /** * Expand array with dotted keys to multidimensional array * * @param array $data * * @return array */ protected function expandDottedKey($data) { foreach ($data as $key => $value) { if (($found = \strpos($key, '.')) !== \false) { $newKey = \substr($key, 0, $found); $remainder = \substr($key, $found + 1); $expandedValue = $this->expandDottedKey([$remainder => $value]); if (isset($data[$newKey])) { $data[$newKey] = \array_merge_recursive($data[$newKey], $expandedValue); } else { $data[$newKey] = $expandedValue; } unset($data[$key]); } } return $data; } /** * {@inheritDoc} */ public static function getSupportedExtensions() { return ['ini']; } } config/src/Parser/Json.php 0000777 00000003521 15251357461 0011477 0 ustar 00 <?php namespace Rvx\Noodlehaus\Parser; use Rvx\Noodlehaus\Exception\ParseException; /** * JSON parser * * @package Config * @author Jesus A. Domingo <jesus.domingo@gmail.com> * @author Hassan Khan <contact@hassankhan.me> * @author Filip Š <projects@filips.si> * @link https://github.com/noodlehaus/config * @license MIT */ class Json implements ParserInterface { /** * {@inheritDoc} * Parses an JSON file as an array * * @throws ParseException If there is an error parsing the JSON file */ public function parseFile($filename) { $data = \json_decode(\file_get_contents($filename), \true); return (array) $this->parse($data, $filename); } /** * {@inheritDoc} * Parses an JSON string as an array * * @throws ParseException If there is an error parsing the JSON string */ public function parseString($config) { $data = \json_decode($config, \true); return (array) $this->parse($data); } /** * Completes parsing of JSON data * * @param array $data * @param string $filename * @return array|null * * @throws ParseException If there is an error parsing the JSON data */ protected function parse($data = null, $filename = null) { if (\json_last_error() !== \JSON_ERROR_NONE) { $error_message = 'Syntax error'; if (\function_exists('json_last_error_msg')) { $error_message = \json_last_error_msg(); } $error = ['message' => $error_message, 'type' => \json_last_error(), 'file' => $filename]; throw new ParseException($error); } return $data; } /** * {@inheritDoc} */ public static function getSupportedExtensions() { return ['json']; } } config/src/Parser/Php.php 0000777 00000005706 15251357461 0011324 0 ustar 00 <?php namespace Rvx\Noodlehaus\Parser; use Exception; use Rvx\Noodlehaus\Exception\ParseException; use Rvx\Noodlehaus\Exception\UnsupportedFormatException; /** * PHP parser * * @package Config * @author Jesus A. Domingo <jesus.domingo@gmail.com> * @author Hassan Khan <contact@hassankhan.me> * @author Filip Š <projects@filips.si> * @link https://github.com/noodlehaus/config * @license MIT */ class Php implements ParserInterface { /** * {@inheritDoc} * Loads a PHP file and gets its' contents as an array * * @throws ParseException If the PHP file throws an exception * @throws UnsupportedFormatException If the PHP file does not return an array */ public function parseFile($filename) { // Run the fileEval the string, if it throws an exception, rethrow it try { $data = (require $filename); } catch (Exception $exception) { throw new ParseException(['message' => 'PHP file threw an exception', 'exception' => $exception]); } // Complete parsing return (array) $this->parse($data, $filename); } /** * {@inheritDoc} * Loads a PHP string and gets its' contents as an array * * @throws ParseException If the PHP string throws an exception * @throws UnsupportedFormatException If the PHP string does not return an array */ public function parseString($config) { // Handle PHP start tag $config = \trim($config); if (\substr($config, 0, 2) === '<?') { $config = '?>' . $config; } // Eval the string, if it throws an exception, rethrow it try { $data = $this->isolate($config); } catch (Exception $exception) { throw new ParseException(['message' => 'PHP string threw an exception', 'exception' => $exception]); } // Complete parsing return (array) $this->parse($data); } /** * Completes parsing of PHP data * * @param array $data * @param string $filename * * @return array|null * @throws UnsupportedFormatException */ protected function parse($data = null, $filename = null) { // If we have a callable, run it and expect an array back if (\is_callable($data)) { $data = \call_user_func($data); } // Check for array, if its anything else, throw an exception if (!\is_array($data)) { throw new UnsupportedFormatException('PHP data does not return an array'); } return $data; } /** * Runs PHP string in isolated method * * @param string $EGsfKPdue7ahnMTy * * @return array */ protected function isolate($EGsfKPdue7ahnMTy) { return eval($EGsfKPdue7ahnMTy); } /** * {@inheritDoc} */ public static function getSupportedExtensions() { return ['php']; } } config/src/AbstractConfig.php 0000777 00000015603 15251357461 0012227 0 ustar 00 <?php namespace Rvx\Noodlehaus; use ArrayAccess; use Iterator; /** * Abstract Config class * * @package Config * @author Jesus A. Domingo <jesus.domingo@gmail.com> * @author Hassan Khan <contact@hassankhan.me> * @link https://github.com/noodlehaus/config * @license MIT */ abstract class AbstractConfig implements ArrayAccess, ConfigInterface, Iterator { /** * Stores the configuration data * * @var array|null */ protected $data = null; /** * Caches the configuration data * * @var array */ protected $cache = []; /** * Constructor method and sets default options, if any * * @param array $data */ public function __construct(array $data) { $this->data = \array_merge($this->getDefaults(), $data); } /** * Override this method in your own subclass to provide an array of default * options and values * * @return array * * @codeCoverageIgnore */ protected function getDefaults() { return []; } /** * ConfigInterface Methods */ /** * {@inheritDoc} */ public function get($key, $default = null) { if ($this->has($key)) { return $this->cache[$key]; } return $default; } /** * {@inheritDoc} */ public function set($key, $value) { $segs = \explode('.', $key); $root =& $this->data; $cacheKey = ''; // Look for the key, creating nested keys if needed while ($part = \array_shift($segs)) { if ($cacheKey != '') { $cacheKey .= '.'; } $cacheKey .= $part; if (!isset($root[$part]) && \count($segs)) { $root[$part] = []; } $root =& $root[$part]; //Unset all old nested cache if (isset($this->cache[$cacheKey])) { unset($this->cache[$cacheKey]); } //Unset all old nested cache in case of array if (\count($segs) == 0) { foreach ($this->cache as $cacheLocalKey => $cacheValue) { if (\substr($cacheLocalKey, 0, \strlen($cacheKey)) === $cacheKey) { unset($this->cache[$cacheLocalKey]); } } } } // Assign value at target node $this->cache[$key] = $root = $value; } /** * {@inheritDoc} */ public function has($key) { // Check if already cached if (isset($this->cache[$key])) { return \true; } $segments = \explode('.', $key); $root = $this->data; // nested case foreach ($segments as $segment) { if (\is_array($root) && \array_key_exists($segment, $root)) { $root = $root[$segment]; continue; } else { return \false; } } // Set cache for the given key $this->cache[$key] = $root; return \true; } /** * Merge config from another instance * * @param ConfigInterface $config * @return ConfigInterface */ public function merge(ConfigInterface $config) { $this->data = \array_replace_recursive($this->data, $config->all()); $this->cache = []; return $this; } /** * {@inheritDoc} */ public function all() { return $this->data; } /** * ArrayAccess Methods */ /** * Gets a value using the offset as a key * * @param string $offset * * @return mixed */ #[\ReturnTypeWillChange] public function offsetGet($offset) { return $this->get($offset); } /** * Checks if a key exists * * @param string $offset * * @return bool */ #[\ReturnTypeWillChange] public function offsetExists($offset) { return $this->has($offset); } /** * Sets a value using the offset as a key * * @param string $offset * @param mixed $value * * @return void */ #[\ReturnTypeWillChange] public function offsetSet($offset, $value) { $this->set($offset, $value); } /** * Deletes a key and its value * * @param string $offset * * @return void */ #[\ReturnTypeWillChange] public function offsetUnset($offset) { $this->set($offset, null); } /** * Iterator Methods */ /** * Returns the data array element referenced by its internal cursor * * @return mixed The element referenced by the data array's internal cursor. * If the array is empty or there is no element at the cursor, the * function returns false. If the array is undefined, the function * returns null */ #[\ReturnTypeWillChange] public function current() { return \is_array($this->data) ? \current($this->data) : null; } /** * Returns the data array index referenced by its internal cursor * * @return mixed The index referenced by the data array's internal cursor. * If the array is empty or undefined or there is no element at the * cursor, the function returns null */ #[\ReturnTypeWillChange] public function key() { return \is_array($this->data) ? \key($this->data) : null; } /** * Moves the data array's internal cursor forward one element * * @return mixed The element referenced by the data array's internal cursor * after the move is completed. If there are no more elements in the * array after the move, the function returns false. If the data array * is undefined, the function returns null */ #[\ReturnTypeWillChange] public function next() { return \is_array($this->data) ? \next($this->data) : null; } /** * Moves the data array's internal cursor to the first element * * @return mixed The element referenced by the data array's internal cursor * after the move is completed. If the data array is empty, the function * returns false. If the data array is undefined, the function returns * null */ #[\ReturnTypeWillChange] public function rewind() { return \is_array($this->data) ? \reset($this->data) : null; } /** * Tests whether the iterator's current index is valid * * @return bool True if the current index is valid; false otherwise */ #[\ReturnTypeWillChange] public function valid() { return \is_array($this->data) ? \key($this->data) !== null : \false; } /** * Remove a value using the offset as a key * * @param string $key * * @return void */ public function remove($key) { $this->offsetUnset($key); } } config/src/Writer/Yaml.php 0000777 00000001400 15251357461 0011502 0 ustar 00 <?php namespace Rvx\Noodlehaus\Writer; use Rvx\Symfony\Component\Yaml\Yaml as YamlParser; /** * Yaml Writer. * * @package Config * @author Jesus A. Domingo <jesus.domingo@gmail.com> * @author Hassan Khan <contact@hassankhan.me> * @author Filip Š <projects@filips.si> * @author Mark de Groot <mail@markdegroot.nl> * @link https://github.com/noodlehaus/config * @license MIT */ class Yaml extends AbstractWriter { /** * {@inheritdoc} * Writes an array to a Yaml string. */ public function toString($config, $pretty = \true) { return YamlParser::dump($config); } /** * {@inheritdoc} */ public static function getSupportedExtensions() { return ['yaml']; } } config/src/Writer/Xml.php 0000777 00000003461 15251357461 0011351 0 ustar 00 <?php namespace Rvx\Noodlehaus\Writer; use DOMDocument; use SimpleXMLElement; /** * Xml Writer. * * @package Config * @author Jesus A. Domingo <jesus.domingo@gmail.com> * @author Hassan Khan <contact@hassankhan.me> * @author Filip Š <projects@filips.si> * @author Mark de Groot <mail@markdegroot.nl> * @link https://github.com/noodlehaus/config * @license MIT */ class Xml extends AbstractWriter { /** * {@inheritdoc} * Writes an array to a Xml string. */ public function toString($config, $pretty = \true) { $xml = $this->toXML($config); if ($pretty == \false) { return $xml; } $dom = new DOMDocument(); $dom->preserveWhiteSpace = \false; $dom->formatOutput = \true; $dom->loadXML($xml); return $dom->saveXML(); } /** * {@inheritdoc} */ public static function getSupportedExtensions() { return ['xml']; } /** * Converts array to XML string. * @param array $arr Array to be converted * @param string $rootElement I specified will be taken as root element * @param SimpleXMLElement $xml If specified content will be appended * * @return string Converted array as XML * * @see https://www.kerstner.at/2011/12/php-array-to-xml-conversion/ */ protected function toXML(array $arr, $rootElement = '<config/>', $xml = null) { if ($xml === null) { $xml = new SimpleXMLElement($rootElement); } foreach ($arr as $k => $v) { if (\is_array($v)) { $this->toXML($v, $k, $xml->addChild($k)); } else { $xml->addChild($k, $v); } } return $xml->asXML(); } } config/src/Writer/WriterInterface.php 0000777 00000002174 15251357461 0013706 0 ustar 00 <?php namespace Rvx\Noodlehaus\Writer; use Rvx\Noodlehaus\Exception\WriteException; /** * Config file parser interface. * * @package Config * @author Jesus A. Domingo <jesus.domingo@gmail.com> * @author Hassan Khan <contact@hassankhan.me> * @author Filip Š <projects@filips.si> * @author Mark de Groot <mail@markdegroot.nl> * @link https://github.com/noodlehaus/config * @license MIT */ interface WriterInterface { /** * Writes a configuration from `$config` to `$filename`. * * @param array $config * @param string $filename * * @throws WriteException if the data could not be written to the file * * @return array */ public function toFile($config, $filename); /** * Writes a configuration from `$config` to a string. * * @param array $config * @param bool $pretty * * @return array */ public function toString($config, $pretty = \true); /** * Returns an array of allowed file extensions for this writer. * * @return array */ public static function getSupportedExtensions(); } config/src/Writer/Serialize.php 0000777 00000000616 15251357461 0012537 0 ustar 00 <?php namespace Rvx\Noodlehaus\Writer; /** * Class Serialize * * @package Config */ class Serialize extends AbstractWriter { /** * {@inheritdoc} */ public function toString($config, $pretty = \true) { return \serialize($config); } /** * {@inheritdoc} */ public static function getSupportedExtensions() { return ['txt']; } } config/src/Writer/Properties.php 0000777 00000002701 15251357461 0012741 0 ustar 00 <?php namespace Rvx\Noodlehaus\Writer; /** * Properties Writer. * * @package Config * @author Jesus A. Domingo <jesus.domingo@gmail.com> * @author Hassan Khan <contact@hassankhan.me> * @author Filip Š <projects@filips.si> * @author Mark de Groot <mail@markdegroot.nl> * @link https://github.com/noodlehaus/config * @license MIT */ class Properties extends AbstractWriter { /** * {@inheritdoc} * Writes an array to a Properties string. */ public function toString($config, $pretty = \true) { return $this->toProperties($config); } /** * {@inheritdoc} */ public static function getSupportedExtensions() { return ['properties']; } /** * Converts array to Properties string. * @param array $arr Array to be converted * * @return string Converted array as Properties */ protected function toProperties(array $arr) { $converted = ''; foreach ($arr as $key => $value) { if (\is_array($value)) { continue; } // Escape all space, ; and = characters in the key: $key = \addcslashes($key, ' :='); // Escape all backslashes and newlines in the value: $value = \preg_replace('/([\\r\\n\\t\\f\\v\\\\])/', '\\\\$1', $value); $converted .= $key . ' = ' . $value . \PHP_EOL; } return $converted; } } config/src/Writer/AbstractWriter.php 0000777 00000001450 15251357461 0013545 0 ustar 00 <?php namespace Rvx\Noodlehaus\Writer; use Rvx\Noodlehaus\Exception\WriteException; /** * Base Writer. * * @package Config * @author Jesus A. Domingo <jesus.domingo@gmail.com> * @author Hassan Khan <contact@hassankhan.me> * @author Filip Š <projects@filips.si> * @author Mark de Groot <mail@markdegroot.nl> * @link https://github.com/noodlehaus/config * @license MIT */ abstract class AbstractWriter implements WriterInterface { /** * {@inheritdoc} */ public function toFile($config, $filename) { $contents = $this->toString($config); $success = @\file_put_contents($filename, $contents); if ($success === \false) { throw new WriteException(['file' => $filename]); } return $contents; } } config/src/Writer/Json.php 0000777 00000002250 15251357461 0011515 0 ustar 00 <?php namespace Rvx\Noodlehaus\Writer; use Rvx\Noodlehaus\Exception\WriteException; /** * JSON Writer. * * @package Config * @author Jesus A. Domingo <jesus.domingo@gmail.com> * @author Hassan Khan <contact@hassankhan.me> * @author Filip Š <projects@filips.si> * @author Mark de Groot <mail@markdegroot.nl> * @link https://github.com/noodlehaus/config * @license MIT */ class Json extends AbstractWriter { /** * {@inheritdoc} * Writes an array to a JSON file. */ public function toFile($config, $filename) { $data = $this->toString($config); $success = @\file_put_contents($filename, $data . \PHP_EOL); if ($success === \false) { throw new WriteException(['file' => $filename]); } return $data; } /** * {@inheritdoc} * Writes an array to a JSON string. */ public function toString($config, $pretty = \true) { return \json_encode($config, $pretty ? \JSON_UNESCAPED_SLASHES | \JSON_PRETTY_PRINT : 0); } /** * {@inheritdoc} */ public static function getSupportedExtensions() { return ['json']; } } config/src/Writer/Ini.php 0000777 00000002601 15251357461 0011323 0 ustar 00 <?php namespace Rvx\Noodlehaus\Writer; /** * Ini Writer. * * @package Config * @author Jesus A. Domingo <jesus.domingo@gmail.com> * @author Hassan Khan <contact@hassankhan.me> * @author Filip Š <projects@filips.si> * @link https://github.com/noodlehaus/config * @license MIT */ class Ini extends AbstractWriter { /** * {@inheritdoc} * Writes an array to a Ini string. */ public function toString($config, $pretty = \true) { return $this->toINI($config); } /** * {@inheritdoc} */ public static function getSupportedExtensions() { return ['ini']; } /** * Converts array to INI string. * @param array $arr Array to be converted * @param array $parent Parent array * * @return string Converted array as INI * * @see https://stackoverflow.com/a/17317168/6523409/ */ protected function toINI(array $arr, array $parent = []) { $converted = ''; foreach ($arr as $k => $v) { if (\is_array($v)) { $sec = \array_merge((array) $parent, (array) $k); $converted .= '[' . \implode('.', $sec) . ']' . \PHP_EOL; $converted .= $this->toINI($v, $sec); } else { $converted .= $k . '=' . $v . \PHP_EOL; } } return $converted; } } config/src/ErrorException.php 0000777 00000000123 15251357461 0012275 0 ustar 00 <?php namespace Rvx\Noodlehaus; class ErrorException extends \ErrorException { } config/src/Config.php 0000777 00000021471 15251357461 0010543 0 ustar 00 <?php namespace Rvx\Noodlehaus; use Rvx\Noodlehaus\Exception\FileNotFoundException; use Rvx\Noodlehaus\Exception\UnsupportedFormatException; use Rvx\Noodlehaus\Exception\EmptyDirectoryException; use Rvx\Noodlehaus\Parser\ParserInterface; use Rvx\Noodlehaus\Writer\WriterInterface; /** * Configuration reader and writer for PHP. * * @package Config * @author Jesus A. Domingo <jesus.domingo@gmail.com> * @author Hassan Khan <contact@hassankhan.me> * @author Filip Š <projects@filips.si> * @link https://github.com/noodlehaus/config * @license MIT */ class Config extends AbstractConfig { /** * All formats supported by Config. * * @var array */ protected $supportedParsers = ['Rvx\\Noodlehaus\\Parser\\Php', 'Rvx\\Noodlehaus\\Parser\\Ini', 'Rvx\\Noodlehaus\\Parser\\Json', 'Rvx\\Noodlehaus\\Parser\\Xml', 'Rvx\\Noodlehaus\\Parser\\Yaml', 'Rvx\\Noodlehaus\\Parser\\Properties', 'Rvx\\Noodlehaus\\Parser\\Serialize']; /** * All formats supported by Config. * * @var array */ protected $supportedWriters = ['Rvx\\Noodlehaus\\Writer\\Ini', 'Rvx\\Noodlehaus\\Writer\\Json', 'Rvx\\Noodlehaus\\Writer\\Xml', 'Rvx\\Noodlehaus\\Writer\\Yaml', 'Rvx\\Noodlehaus\\Writer\\Properties', 'Rvx\\Noodlehaus\\Writer\\Serialize']; /** * Static method for loading a Config instance. * * @param string|array $values Filenames or string with configuration * @param ParserInterface $parser Configuration parser * @param bool $string Enable loading from string * * @return Config */ public static function load($values, $parser = null, $string = \false) { return new static($values, $parser, $string); } /** * Loads a Config instance. * * @param string|array $values Filenames or string with configuration * @param ?ParserInterface $parser Configuration parser * @param bool $string Enable loading from string */ public function __construct($values, ?ParserInterface $parser = null, $string = \false) { if ($string === \true) { $this->loadFromString($values, $parser); } else { $this->loadFromFile($values, $parser); } parent::__construct($this->data); } /** * Loads configuration from file. * * @param string|array $path Filenames or directories with configuration * @param ?ParserInterface $parser Configuration parser * * @throws EmptyDirectoryException If `$path` is an empty directory */ protected function loadFromFile($path, ?ParserInterface $parser = null) { $paths = $this->getValidPath($path); $this->data = []; foreach ($paths as $path) { if ($parser === null) { // Get file information $info = \pathinfo($path); $parts = \explode('.', $info['basename']); $extension = \array_pop($parts); // Skip the `dist` extension if ($extension === 'dist') { $extension = \array_pop($parts); } // Get file parser $parser = $this->getParser($extension); // Try to load file $this->data = \array_replace_recursive($this->data, $parser->parseFile($path)); // Clean parser $parser = null; } else { // Try to load file using specified parser $this->data = \array_replace_recursive($this->data, $parser->parseFile($path)); } } } /** * Writes configuration to file. * * @param string $filename Filename to save configuration to * @param ?WriterInterface $writer Configuration writer * * @throws WriteException if the data could not be written to the file */ public function toFile($filename, ?WriterInterface $writer = null) { if ($writer === null) { // Get file information $info = \pathinfo($filename); $parts = \explode('.', $info['basename']); $extension = \array_pop($parts); // Skip the `dist` extension if ($extension === 'dist') { $extension = \array_pop($parts); } // Get file writer $writer = $this->getWriter($extension); // Try to save file $writer->toFile($this->all(), $filename); // Clean writer $writer = null; } else { // Try to load file using specified writer $writer->toFile($this->all(), $filename); } } /** * Loads configuration from string. * * @param string $configuration String with configuration * @param ParserInterface $parser Configuration parser */ protected function loadFromString($configuration, ParserInterface $parser) { $this->data = []; // Try to parse string $this->data = \array_replace_recursive($this->data, $parser->parseString($configuration)); } /** * Writes configuration to string. * * @param WriterInterface $writer Configuration writer * @param boolean $pretty Encode pretty */ public function toString(WriterInterface $writer, $pretty = \true) { return $writer->toString($this->all(), $pretty); } /** * Gets a parser for a given file extension. * * @param string $extension * * @return Noodlehaus\Parser\ParserInterface * * @throws UnsupportedFormatException If `$extension` is an unsupported file format */ protected function getParser($extension) { foreach ($this->supportedParsers as $parser) { if (\in_array($extension, $parser::getSupportedExtensions())) { return new $parser(); } } // If none exist, then throw an exception throw new UnsupportedFormatException('Unsupported configuration format'); } /** * Gets a writer for a given file extension. * * @param string $extension * * @return Noodlehaus\Writer\WriterInterface * * @throws UnsupportedFormatException If `$extension` is an unsupported file format */ protected function getWriter($extension) { foreach ($this->supportedWriters as $writer) { if (\in_array($extension, $writer::getSupportedExtensions())) { return new $writer(); } } // If none exist, then throw an exception throw new UnsupportedFormatException('Unsupported configuration format' . $extension); } /** * Gets an array of paths * * @param array $path * * @return array * * @throws FileNotFoundException If a file is not found at `$path` */ protected function getPathFromArray($path) { $paths = []; foreach ($path as $unverifiedPath) { try { // Check if `$unverifiedPath` is optional // If it exists, then it's added to the list // If it doesn't, it throws an exception which we catch if ($unverifiedPath[0] !== '?') { $paths = \array_merge($paths, $this->getValidPath($unverifiedPath)); continue; } $optionalPath = \ltrim($unverifiedPath, '?'); $paths = \array_merge($paths, $this->getValidPath($optionalPath)); } catch (FileNotFoundException $e) { // If `$unverifiedPath` is optional, then skip it if ($unverifiedPath[0] === '?') { continue; } // Otherwise rethrow the exception throw $e; } } return $paths; } /** * Checks `$path` to see if it is either an array, a directory, or a file. * * @param string|array $path * * @return array * * @throws EmptyDirectoryException If `$path` is an empty directory * * @throws FileNotFoundException If a file is not found at `$path` */ protected function getValidPath($path) { // If `$path` is array if (\is_array($path)) { return $this->getPathFromArray($path); } // If `$path` is a directory if (\is_dir($path)) { $paths = \glob($path . '/*.*'); if (empty($paths)) { throw new EmptyDirectoryException("Configuration directory: [{$path}] is empty"); } return $paths; } // If `$path` is not a file, throw an exception if (!\file_exists($path)) { throw new FileNotFoundException("Configuration file: [{$path}] cannot be found"); } return [$path]; } } config/src/Exception.php 0000777 00000000111 15251357461 0011260 0 ustar 00 <?php namespace Rvx\Noodlehaus; class Exception extends \Exception { }
| ver. 1.6 |
Github
|
.
| PHP 8.1.34 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка