Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/interact.../vendor/hassankh.../config/src
File: Config.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Noodlehaus;
[2] Fix | Delete
[3] Fix | Delete
use Noodlehaus\Exception\FileNotFoundException;
[4] Fix | Delete
use Noodlehaus\Exception\UnsupportedFormatException;
[5] Fix | Delete
use Noodlehaus\Exception\EmptyDirectoryException;
[6] Fix | Delete
use Noodlehaus\Parser\ParserInterface;
[7] Fix | Delete
use Noodlehaus\Writer\WriterInterface;
[8] Fix | Delete
[9] Fix | Delete
/**
[10] Fix | Delete
* Configuration reader and writer for PHP.
[11] Fix | Delete
*
[12] Fix | Delete
* @package Config
[13] Fix | Delete
* @author Jesus A. Domingo <jesus.domingo@gmail.com>
[14] Fix | Delete
* @author Hassan Khan <contact@hassankhan.me>
[15] Fix | Delete
* @author Filip Š <projects@filips.si>
[16] Fix | Delete
* @link https://github.com/noodlehaus/config
[17] Fix | Delete
* @license MIT
[18] Fix | Delete
*/
[19] Fix | Delete
class Config extends AbstractConfig
[20] Fix | Delete
{
[21] Fix | Delete
/**
[22] Fix | Delete
* All formats supported by Config.
[23] Fix | Delete
*
[24] Fix | Delete
* @var array
[25] Fix | Delete
*/
[26] Fix | Delete
protected $supportedParsers = [
[27] Fix | Delete
'Noodlehaus\Parser\Php',
[28] Fix | Delete
'Noodlehaus\Parser\Ini',
[29] Fix | Delete
'Noodlehaus\Parser\Json',
[30] Fix | Delete
'Noodlehaus\Parser\Xml',
[31] Fix | Delete
'Noodlehaus\Parser\Yaml',
[32] Fix | Delete
'Noodlehaus\Parser\Properties',
[33] Fix | Delete
'Noodlehaus\Parser\Serialize'
[34] Fix | Delete
];
[35] Fix | Delete
[36] Fix | Delete
/**
[37] Fix | Delete
* All formats supported by Config.
[38] Fix | Delete
*
[39] Fix | Delete
* @var array
[40] Fix | Delete
*/
[41] Fix | Delete
protected $supportedWriters = [
[42] Fix | Delete
'Noodlehaus\Writer\Ini',
[43] Fix | Delete
'Noodlehaus\Writer\Json',
[44] Fix | Delete
'Noodlehaus\Writer\Xml',
[45] Fix | Delete
'Noodlehaus\Writer\Yaml',
[46] Fix | Delete
'Noodlehaus\Writer\Properties',
[47] Fix | Delete
'Noodlehaus\Writer\Serialize'
[48] Fix | Delete
];
[49] Fix | Delete
[50] Fix | Delete
/**
[51] Fix | Delete
* Static method for loading a Config instance.
[52] Fix | Delete
*
[53] Fix | Delete
* @param string|array $values Filenames or string with configuration
[54] Fix | Delete
* @param ParserInterface $parser Configuration parser
[55] Fix | Delete
* @param bool $string Enable loading from string
[56] Fix | Delete
*
[57] Fix | Delete
* @return Config
[58] Fix | Delete
*/
[59] Fix | Delete
public static function load($values, $parser = null, $string = false)
[60] Fix | Delete
{
[61] Fix | Delete
return new static($values, $parser, $string);
[62] Fix | Delete
}
[63] Fix | Delete
[64] Fix | Delete
/**
[65] Fix | Delete
* Loads a Config instance.
[66] Fix | Delete
*
[67] Fix | Delete
* @param string|array $values Filenames or string with configuration
[68] Fix | Delete
* @param ParserInterface $parser Configuration parser
[69] Fix | Delete
* @param bool $string Enable loading from string
[70] Fix | Delete
*/
[71] Fix | Delete
public function __construct($values, ParserInterface $parser = null, $string = false)
[72] Fix | Delete
{
[73] Fix | Delete
if ($string === true) {
[74] Fix | Delete
$this->loadFromString($values, $parser);
[75] Fix | Delete
} else {
[76] Fix | Delete
$this->loadFromFile($values, $parser);
[77] Fix | Delete
}
[78] Fix | Delete
[79] Fix | Delete
parent::__construct($this->data);
[80] Fix | Delete
}
[81] Fix | Delete
[82] Fix | Delete
/**
[83] Fix | Delete
* Loads configuration from file.
[84] Fix | Delete
*
[85] Fix | Delete
* @param string|array $path Filenames or directories with configuration
[86] Fix | Delete
* @param ParserInterface $parser Configuration parser
[87] Fix | Delete
*
[88] Fix | Delete
* @throws EmptyDirectoryException If `$path` is an empty directory
[89] Fix | Delete
*/
[90] Fix | Delete
protected function loadFromFile($path, ParserInterface $parser = null)
[91] Fix | Delete
{
[92] Fix | Delete
$paths = $this->getValidPath($path);
[93] Fix | Delete
$this->data = [];
[94] Fix | Delete
[95] Fix | Delete
foreach ($paths as $path) {
[96] Fix | Delete
if ($parser === null) {
[97] Fix | Delete
// Get file information
[98] Fix | Delete
$info = pathinfo($path);
[99] Fix | Delete
$parts = explode('.', $info['basename']);
[100] Fix | Delete
$extension = array_pop($parts);
[101] Fix | Delete
[102] Fix | Delete
// Skip the `dist` extension
[103] Fix | Delete
if ($extension === 'dist') {
[104] Fix | Delete
$extension = array_pop($parts);
[105] Fix | Delete
}
[106] Fix | Delete
[107] Fix | Delete
// Get file parser
[108] Fix | Delete
$parser = $this->getParser($extension);
[109] Fix | Delete
[110] Fix | Delete
// Try to load file
[111] Fix | Delete
$this->data = array_replace_recursive($this->data, $parser->parseFile($path));
[112] Fix | Delete
[113] Fix | Delete
// Clean parser
[114] Fix | Delete
$parser = null;
[115] Fix | Delete
} else {
[116] Fix | Delete
// Try to load file using specified parser
[117] Fix | Delete
$this->data = array_replace_recursive($this->data, $parser->parseFile($path));
[118] Fix | Delete
}
[119] Fix | Delete
}
[120] Fix | Delete
}
[121] Fix | Delete
[122] Fix | Delete
/**
[123] Fix | Delete
* Writes configuration to file.
[124] Fix | Delete
*
[125] Fix | Delete
* @param string $filename Filename to save configuration to
[126] Fix | Delete
* @param WriterInterface $writer Configuration writer
[127] Fix | Delete
*
[128] Fix | Delete
* @throws WriteException if the data could not be written to the file
[129] Fix | Delete
*/
[130] Fix | Delete
public function toFile($filename, WriterInterface $writer = null)
[131] Fix | Delete
{
[132] Fix | Delete
if ($writer === null) {
[133] Fix | Delete
// Get file information
[134] Fix | Delete
$info = pathinfo($filename);
[135] Fix | Delete
$parts = explode('.', $info['basename']);
[136] Fix | Delete
$extension = array_pop($parts);
[137] Fix | Delete
[138] Fix | Delete
// Skip the `dist` extension
[139] Fix | Delete
if ($extension === 'dist') {
[140] Fix | Delete
$extension = array_pop($parts);
[141] Fix | Delete
}
[142] Fix | Delete
[143] Fix | Delete
// Get file writer
[144] Fix | Delete
$writer = $this->getWriter($extension);
[145] Fix | Delete
[146] Fix | Delete
// Try to save file
[147] Fix | Delete
$writer->toFile($this->all(), $filename);
[148] Fix | Delete
[149] Fix | Delete
// Clean writer
[150] Fix | Delete
$writer = null;
[151] Fix | Delete
} else {
[152] Fix | Delete
// Try to load file using specified writer
[153] Fix | Delete
$writer->toFile($this->all(), $filename);
[154] Fix | Delete
}
[155] Fix | Delete
}
[156] Fix | Delete
[157] Fix | Delete
/**
[158] Fix | Delete
* Loads configuration from string.
[159] Fix | Delete
*
[160] Fix | Delete
* @param string $configuration String with configuration
[161] Fix | Delete
* @param ParserInterface $parser Configuration parser
[162] Fix | Delete
*/
[163] Fix | Delete
protected function loadFromString($configuration, ParserInterface $parser)
[164] Fix | Delete
{
[165] Fix | Delete
$this->data = [];
[166] Fix | Delete
[167] Fix | Delete
// Try to parse string
[168] Fix | Delete
$this->data = array_replace_recursive($this->data, $parser->parseString($configuration));
[169] Fix | Delete
}
[170] Fix | Delete
[171] Fix | Delete
/**
[172] Fix | Delete
* Writes configuration to string.
[173] Fix | Delete
*
[174] Fix | Delete
* @param WriterInterface $writer Configuration writer
[175] Fix | Delete
* @param boolean $pretty Encode pretty
[176] Fix | Delete
*/
[177] Fix | Delete
public function toString(WriterInterface $writer, $pretty = true)
[178] Fix | Delete
{
[179] Fix | Delete
return $writer->toString($this->all(), $pretty);
[180] Fix | Delete
}
[181] Fix | Delete
[182] Fix | Delete
/**
[183] Fix | Delete
* Gets a parser for a given file extension.
[184] Fix | Delete
*
[185] Fix | Delete
* @param string $extension
[186] Fix | Delete
*
[187] Fix | Delete
* @return Noodlehaus\Parser\ParserInterface
[188] Fix | Delete
*
[189] Fix | Delete
* @throws UnsupportedFormatException If `$extension` is an unsupported file format
[190] Fix | Delete
*/
[191] Fix | Delete
protected function getParser($extension)
[192] Fix | Delete
{
[193] Fix | Delete
foreach ($this->supportedParsers as $parser) {
[194] Fix | Delete
if (in_array($extension, $parser::getSupportedExtensions())) {
[195] Fix | Delete
return new $parser();
[196] Fix | Delete
}
[197] Fix | Delete
}
[198] Fix | Delete
[199] Fix | Delete
// If none exist, then throw an exception
[200] Fix | Delete
throw new UnsupportedFormatException('Unsupported configuration format');
[201] Fix | Delete
}
[202] Fix | Delete
[203] Fix | Delete
/**
[204] Fix | Delete
* Gets a writer for a given file extension.
[205] Fix | Delete
*
[206] Fix | Delete
* @param string $extension
[207] Fix | Delete
*
[208] Fix | Delete
* @return Noodlehaus\Writer\WriterInterface
[209] Fix | Delete
*
[210] Fix | Delete
* @throws UnsupportedFormatException If `$extension` is an unsupported file format
[211] Fix | Delete
*/
[212] Fix | Delete
protected function getWriter($extension)
[213] Fix | Delete
{
[214] Fix | Delete
foreach ($this->supportedWriters as $writer) {
[215] Fix | Delete
if (in_array($extension, $writer::getSupportedExtensions())) {
[216] Fix | Delete
return new $writer();
[217] Fix | Delete
}
[218] Fix | Delete
}
[219] Fix | Delete
[220] Fix | Delete
// If none exist, then throw an exception
[221] Fix | Delete
throw new UnsupportedFormatException('Unsupported configuration format'.$extension);
[222] Fix | Delete
}
[223] Fix | Delete
[224] Fix | Delete
/**
[225] Fix | Delete
* Gets an array of paths
[226] Fix | Delete
*
[227] Fix | Delete
* @param array $path
[228] Fix | Delete
*
[229] Fix | Delete
* @return array
[230] Fix | Delete
*
[231] Fix | Delete
* @throws FileNotFoundException If a file is not found at `$path`
[232] Fix | Delete
*/
[233] Fix | Delete
protected function getPathFromArray($path)
[234] Fix | Delete
{
[235] Fix | Delete
$paths = [];
[236] Fix | Delete
[237] Fix | Delete
foreach ($path as $unverifiedPath) {
[238] Fix | Delete
try {
[239] Fix | Delete
// Check if `$unverifiedPath` is optional
[240] Fix | Delete
// If it exists, then it's added to the list
[241] Fix | Delete
// If it doesn't, it throws an exception which we catch
[242] Fix | Delete
if ($unverifiedPath[0] !== '?') {
[243] Fix | Delete
$paths = array_merge($paths, $this->getValidPath($unverifiedPath));
[244] Fix | Delete
continue;
[245] Fix | Delete
}
[246] Fix | Delete
[247] Fix | Delete
$optionalPath = ltrim($unverifiedPath, '?');
[248] Fix | Delete
$paths = array_merge($paths, $this->getValidPath($optionalPath));
[249] Fix | Delete
} catch (FileNotFoundException $e) {
[250] Fix | Delete
// If `$unverifiedPath` is optional, then skip it
[251] Fix | Delete
if ($unverifiedPath[0] === '?') {
[252] Fix | Delete
continue;
[253] Fix | Delete
}
[254] Fix | Delete
[255] Fix | Delete
// Otherwise rethrow the exception
[256] Fix | Delete
throw $e;
[257] Fix | Delete
}
[258] Fix | Delete
}
[259] Fix | Delete
[260] Fix | Delete
return $paths;
[261] Fix | Delete
}
[262] Fix | Delete
[263] Fix | Delete
/**
[264] Fix | Delete
* Checks `$path` to see if it is either an array, a directory, or a file.
[265] Fix | Delete
*
[266] Fix | Delete
* @param string|array $path
[267] Fix | Delete
*
[268] Fix | Delete
* @return array
[269] Fix | Delete
*
[270] Fix | Delete
* @throws EmptyDirectoryException If `$path` is an empty directory
[271] Fix | Delete
*
[272] Fix | Delete
* @throws FileNotFoundException If a file is not found at `$path`
[273] Fix | Delete
*/
[274] Fix | Delete
protected function getValidPath($path)
[275] Fix | Delete
{
[276] Fix | Delete
// If `$path` is array
[277] Fix | Delete
if (is_array($path)) {
[278] Fix | Delete
return $this->getPathFromArray($path);
[279] Fix | Delete
}
[280] Fix | Delete
[281] Fix | Delete
// If `$path` is a directory
[282] Fix | Delete
if (is_dir($path)) {
[283] Fix | Delete
$paths = glob($path . '/*.*');
[284] Fix | Delete
if (empty($paths)) {
[285] Fix | Delete
throw new EmptyDirectoryException("Configuration directory: [$path] is empty");
[286] Fix | Delete
}
[287] Fix | Delete
[288] Fix | Delete
return $paths;
[289] Fix | Delete
}
[290] Fix | Delete
[291] Fix | Delete
// If `$path` is not a file, throw an exception
[292] Fix | Delete
if (!file_exists($path)) {
[293] Fix | Delete
throw new FileNotFoundException("Configuration file: [$path] cannot be found");
[294] Fix | Delete
}
[295] Fix | Delete
[296] Fix | Delete
return [$path];
[297] Fix | Delete
}
[298] Fix | Delete
}
[299] Fix | Delete
[300] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function