Added vendor/ directory for Composer's installed files
This commit is contained in:
28
vendor/hassankhan/config/src/FileParser/AbstractFileParser.php
vendored
Executable file
28
vendor/hassankhan/config/src/FileParser/AbstractFileParser.php
vendored
Executable file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Noodlehaus\FileParser;
|
||||
|
||||
/**
|
||||
* Abstract file parser
|
||||
*
|
||||
* @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 AbstractFileParser implements FileParserInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Path to the config file
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $path;
|
||||
|
||||
public function __construct($path)
|
||||
{
|
||||
$this->path = $path;
|
||||
}
|
||||
}
|
31
vendor/hassankhan/config/src/FileParser/FileParserInterface.php
vendored
Executable file
31
vendor/hassankhan/config/src/FileParser/FileParserInterface.php
vendored
Executable file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Noodlehaus\FileParser;
|
||||
|
||||
/**
|
||||
* Config file parser 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 FileParserInterface
|
||||
{
|
||||
/**
|
||||
* Parses a file from `$path` and gets its contents as an array
|
||||
*
|
||||
* @param string $path
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function parse($path);
|
||||
|
||||
/**
|
||||
* Returns an array of allowed file extensions for this parser
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSupportedExtensions();
|
||||
}
|
43
vendor/hassankhan/config/src/FileParser/Ini.php
vendored
Executable file
43
vendor/hassankhan/config/src/FileParser/Ini.php
vendored
Executable file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Noodlehaus\FileParser;
|
||||
|
||||
use Noodlehaus\Exception\ParseException;
|
||||
|
||||
/**
|
||||
* INI file parser
|
||||
*
|
||||
* @package Config
|
||||
* @author Jesus A. Domingo <jesus.domingo@gmail.com>
|
||||
* @author Hassan Khan <contact@hassankhan.me>
|
||||
* @link https://github.com/noodlehaus/config
|
||||
* @license MIT
|
||||
*/
|
||||
class Ini implements FileParserInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* Parses an INI file as an array
|
||||
*
|
||||
* @throws ParseException If there is an error parsing the INI file
|
||||
*/
|
||||
public function parse($path)
|
||||
{
|
||||
$data = @parse_ini_file($path, true);
|
||||
|
||||
if (!$data) {
|
||||
$error = error_get_last();
|
||||
throw new ParseException($error);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getSupportedExtensions()
|
||||
{
|
||||
return array('ini');
|
||||
}
|
||||
}
|
53
vendor/hassankhan/config/src/FileParser/Json.php
vendored
Executable file
53
vendor/hassankhan/config/src/FileParser/Json.php
vendored
Executable file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Noodlehaus\FileParser;
|
||||
|
||||
use Noodlehaus\Exception\ParseException;
|
||||
|
||||
/**
|
||||
* JSON file parser
|
||||
*
|
||||
* @package Config
|
||||
* @author Jesus A. Domingo <jesus.domingo@gmail.com>
|
||||
* @author Hassan Khan <contact@hassankhan.me>
|
||||
* @link https://github.com/noodlehaus/config
|
||||
* @license MIT
|
||||
*/
|
||||
class Json implements FileParserInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* Loads a JSON file as an array
|
||||
*
|
||||
* @throws ParseException If there is an error parsing the JSON file
|
||||
*/
|
||||
public function parse($path)
|
||||
{
|
||||
$data = json_decode(file_get_contents($path), true);
|
||||
|
||||
if (function_exists('json_last_error_msg')) {
|
||||
$error_message = json_last_error_msg();
|
||||
} else {
|
||||
$error_message = 'Syntax error';
|
||||
}
|
||||
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
$error = array(
|
||||
'message' => $error_message,
|
||||
'type' => json_last_error(),
|
||||
'file' => $path,
|
||||
);
|
||||
throw new ParseException($error);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getSupportedExtensions()
|
||||
{
|
||||
return array('json');
|
||||
}
|
||||
}
|
61
vendor/hassankhan/config/src/FileParser/Php.php
vendored
Executable file
61
vendor/hassankhan/config/src/FileParser/Php.php
vendored
Executable file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace Noodlehaus\FileParser;
|
||||
|
||||
use Exception;
|
||||
use Noodlehaus\Exception\ParseException;
|
||||
use Noodlehaus\Exception\UnsupportedFormatException;
|
||||
|
||||
/**
|
||||
* PHP file parser
|
||||
*
|
||||
* @package Config
|
||||
* @author Jesus A. Domingo <jesus.domingo@gmail.com>
|
||||
* @author Hassan Khan <contact@hassankhan.me>
|
||||
* @link https://github.com/noodlehaus/config
|
||||
* @license MIT
|
||||
*/
|
||||
class Php implements FileParserInterface
|
||||
{
|
||||
/**
|
||||
* {@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 parse($path)
|
||||
{
|
||||
// Require the file, if it throws an exception, rethrow it
|
||||
try {
|
||||
$temp = require $path;
|
||||
} catch (Exception $exception) {
|
||||
throw new ParseException(
|
||||
array(
|
||||
'message' => 'PHP file threw an exception',
|
||||
'exception' => $exception,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// If we have a callable, run it and expect an array back
|
||||
if (is_callable($temp)) {
|
||||
$temp = call_user_func($temp);
|
||||
}
|
||||
|
||||
// Check for array, if its anything else, throw an exception
|
||||
if (!$temp || !is_array($temp)) {
|
||||
throw new UnsupportedFormatException('PHP file does not return an array');
|
||||
}
|
||||
|
||||
return $temp;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getSupportedExtensions()
|
||||
{
|
||||
return array('php');
|
||||
}
|
||||
}
|
55
vendor/hassankhan/config/src/FileParser/Xml.php
vendored
Executable file
55
vendor/hassankhan/config/src/FileParser/Xml.php
vendored
Executable file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace Noodlehaus\FileParser;
|
||||
|
||||
use Noodlehaus\Exception\ParseException;
|
||||
|
||||
/**
|
||||
* XML file parser
|
||||
*
|
||||
* @package Config
|
||||
* @author Jesus A. Domingo <jesus.domingo@gmail.com>
|
||||
* @author Hassan Khan <contact@hassankhan.me>
|
||||
* @link https://github.com/noodlehaus/config
|
||||
* @license MIT
|
||||
*/
|
||||
class Xml implements FileParserInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* Parses an XML file as an array
|
||||
*
|
||||
* @throws ParseException If there is an error parsing the XML file
|
||||
*/
|
||||
public function parse($path)
|
||||
{
|
||||
libxml_use_internal_errors(true);
|
||||
|
||||
$data = simplexml_load_file($path, null, LIBXML_NOERROR);
|
||||
|
||||
if ($data === false) {
|
||||
$errors = libxml_get_errors();
|
||||
$latestError = array_pop($errors);
|
||||
$error = array(
|
||||
'message' => $latestError->message,
|
||||
'type' => $latestError->level,
|
||||
'code' => $latestError->code,
|
||||
'file' => $latestError->file,
|
||||
'line' => $latestError->line,
|
||||
);
|
||||
throw new ParseException($error);
|
||||
}
|
||||
|
||||
$data = json_decode(json_encode($data), true);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getSupportedExtensions()
|
||||
{
|
||||
return array('xml');
|
||||
}
|
||||
}
|
49
vendor/hassankhan/config/src/FileParser/Yaml.php
vendored
Executable file
49
vendor/hassankhan/config/src/FileParser/Yaml.php
vendored
Executable file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Noodlehaus\FileParser;
|
||||
|
||||
use Exception;
|
||||
use Symfony\Component\Yaml\Yaml as YamlParser;
|
||||
use Noodlehaus\Exception\ParseException;
|
||||
|
||||
/**
|
||||
* YAML file parser
|
||||
*
|
||||
* @package Config
|
||||
* @author Jesus A. Domingo <jesus.domingo@gmail.com>
|
||||
* @author Hassan Khan <contact@hassankhan.me>
|
||||
* @link https://github.com/noodlehaus/config
|
||||
* @license MIT
|
||||
*/
|
||||
class Yaml implements FileParserInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* Loads a YAML/YML file as an array
|
||||
*
|
||||
* @throws ParseException If If there is an error parsing the YAML file
|
||||
*/
|
||||
public function parse($path)
|
||||
{
|
||||
try {
|
||||
$data = YamlParser::parse($path);
|
||||
} catch (Exception $exception) {
|
||||
throw new ParseException(
|
||||
array(
|
||||
'message' => 'Error parsing YAML file',
|
||||
'exception' => $exception,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getSupportedExtensions()
|
||||
{
|
||||
return array('yaml', 'yml');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user