Added vendor/ directory for Composer's installed files

This commit is contained in:
Ascendings
2015-08-30 12:33:20 -04:00
parent 45df179c49
commit b66a773ed8
1162 changed files with 112457 additions and 0 deletions

99
vendor/hassankhan/config/CHANGELOG.md vendored Executable file
View File

@ -0,0 +1,99 @@
# Changelog
All notable changes to `Config` will be documented in this file
## 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

32
vendor/hassankhan/config/CONTRIBUTING.md vendored Executable file
View File

@ -0,0 +1,32 @@
# 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**!

8
vendor/hassankhan/config/LICENSE.md vendored Executable file
View File

@ -0,0 +1,8 @@
The MIT License (MIT)
Copyright © 2015 Jesus A. Domingo <jesus.domingo@gmail.com>
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.

36
vendor/hassankhan/config/composer.json vendored Executable file
View File

@ -0,0 +1,36 @@
{
"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": ">=5.3.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"scrutinizer/ocular": "~1.1",
"squizlabs/php_codesniffer": "~2.2"
},
"suggest": {
"symfony/yaml": "~2.5"
},
"autoload": {
"psr-4": {
"Noodlehaus\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Noodlehaus\\Test\\": "tests"
}
}
}

View File

@ -0,0 +1,159 @@
<?php
namespace Noodlehaus;
use ArrayAccess;
/**
* 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
{
/**
* Stores the configuration data
*
* @var array|null
*/
protected $data = null;
/**
* Caches the configuration data
*
* @var array
*/
protected $cache = array();
/**
* Constructor method and sets default options, if any
*
* @param array $data
*/
public function __construct($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 array();
}
/**
* ConfigInterface Methods
*/
/**
* {@inheritDoc}
*/
public function get($key, $default = null)
{
// Check if already cached
if (isset($this->cache[$key])) {
return $this->cache[$key];
}
$segs = explode('.', $key);
$root = $this->data;
// nested case
foreach ($segs as $part) {
if (isset($root[$part])) {
$root = $root[$part];
continue;
} else {
$root = $default;
break;
}
}
// whatever we have is what we needed
return ($this->cache[$key] = $root);
}
/**
* {@inheritDoc}
*/
public function set($key, $value)
{
$segs = explode('.', $key);
$root = &$this->data;
// Look for the key, creating nested keys if needed
while ($part = array_shift($segs)) {
if (!isset($root[$part]) && count($segs)) {
$root[$part] = array();
}
$root = &$root[$part];
}
// Assign value at target node
$this->cache[$key] = $root = $value;
}
/**
* ArrayAccess Methods
*/
/**
* Gets a value using the offset as a key
*
* @param string $offset
*
* @return mixed
*/
public function offsetGet($offset)
{
return $this->get($offset);
}
/**
* Checks if a key exists
*
* @param string $offset
*
* @return bool
*/
public function offsetExists($offset)
{
return !is_null($this->get($offset));
}
/**
* Sets a value using the offset as a key
*
* @param string $offset
* @param mixed $value
*
* @return void
*/
public function offsetSet($offset, $value)
{
$this->set($offset, $value);
}
/**
* Deletes a key and its value
*
* @param string $offset
*
* @return void
*/
public function offsetUnset($offset)
{
$this->set($offset, null);
}
}

157
vendor/hassankhan/config/src/Config.php vendored Executable file
View File

@ -0,0 +1,157 @@
<?php
namespace Noodlehaus;
use Noodlehaus\Exception\FileNotFoundException;
use Noodlehaus\Exception\UnsupportedFormatException;
use Noodlehaus\Exception\EmptyDirectoryException;
/**
* Config
*
* @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 Config extends AbstractConfig
{
/**
* All file formats supported by Config
*
* @var array
*/
private $supportedFileParsers = array(
'Noodlehaus\FileParser\Php',
'Noodlehaus\FileParser\Ini',
'Noodlehaus\FileParser\Json',
'Noodlehaus\FileParser\Xml',
'Noodlehaus\FileParser\Yaml'
);
/**
* Static method for loading a Config instance.
*
* @param string|array $path
*
* @return Config
*/
public static function load($path)
{
return new static($path);
}
/**
* Loads a supported configuration file format.
*
* @param string|array $path
*
* @throws EmptyDirectoryException If `$path` is an empty directory
*/
public function __construct($path)
{
$paths = $this->getValidPath($path);
$this->data = array();
foreach ($paths as $path) {
// Get file information
$info = pathinfo($path);
$extension = isset($info['extension']) ? $info['extension'] : '';
$parser = $this->getParser($extension);
// Try and load file
$this->data = array_replace_recursive($this->data, $parser->parse($path));
}
parent::__construct($this->data);
}
/**
* Gets a parser for a given file extension
*
* @param string $extension
*
* @return Noodlehaus\File\FileInterface
*
* @throws UnsupportedFormatException If `$path` is an unsupported file format
*/
private function getParser($extension)
{
$parser = null;
foreach ($this->supportedFileParsers as $fileParser) {
$tempParser = new $fileParser;
if (in_array($extension, $tempParser->getSupportedExtensions($extension))) {
$parser = $tempParser;
continue;
}
}
// If none exist, then throw an exception
if ($parser === null) {
throw new UnsupportedFormatException('Unsupported configuration format');
}
return $parser;
}
/**
* 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`
*/
private function getValidPath($path)
{
// If `$path` is array
if (is_array($path)) {
$paths = array();
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;
}
// 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 array($path);
}
}

View File

@ -0,0 +1,38 @@
<?php
namespace 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);
}

View File

@ -0,0 +1,9 @@
<?php
namespace Noodlehaus\Exception;
use Exception;
class EmptyDirectoryException extends Exception
{
}

View File

@ -0,0 +1,9 @@
<?php
namespace Noodlehaus\Exception;
use Exception;
class FileNotFoundException extends Exception
{
}

View File

@ -0,0 +1,20 @@
<?php
namespace Noodlehaus\Exception;
use ErrorException;
class ParseException extends ErrorException
{
public function __construct(array $error)
{
$message = $error['message'];
$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);
}
}

View File

@ -0,0 +1,9 @@
<?php
namespace Noodlehaus\Exception;
use Exception;
class UnsupportedFormatException extends Exception
{
}

View 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;
}
}

View 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();
}

View 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');
}
}

View 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');
}
}

View 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');
}
}

View 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');
}
}

View 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');
}
}