Update Composer, update everything

This commit is contained in:
Oliver Davies 2018-11-23 12:29:20 +00:00
parent ea3e94409f
commit dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions

View file

@ -0,0 +1,2 @@
composer.lock
vendor

View file

@ -0,0 +1,13 @@
language: php
php:
- 5.3
- 5.4
- 5.5
- 5.6
before_script:
- wget -nc http://getcomposer.org/composer.phar
- php composer.phar install --dev
script: phpunit --coverage-text

19
vendor/dflydev/dot-access-data/LICENSE vendored Normal file
View file

@ -0,0 +1,19 @@
Copyright (c) 2012 Dragonfly Development Inc.
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.

118
vendor/dflydev/dot-access-data/README.md vendored Normal file
View file

@ -0,0 +1,118 @@
Dot Access Data
===============
Given a deep data structure, access data by dot notation.
Requirements
------------
* PHP (5.3+)
Usage
-----
Abstract example:
```php
use Dflydev\DotAccessData\Data;
$data = new Data;
$data->set('a.b.c', 'C');
$data->set('a.b.d', 'D1');
$data->append('a.b.d', 'D2');
$data->set('a.b.e', array('E0', 'E1', 'E2'));
// C
$data->get('a.b.c');
// array('D1', 'D2')
$data->get('a.b.d');
// array('E0', 'E1', 'E2')
$data->get('a.b.e');
// true
$data->has('a.b.c');
// false
$data->has('a.b.d.j');
```
A more concrete example:
```php
use Dflydev\DotAccessData\Data;
$data = new Data(array(
'hosts' => array(
'hewey' => array(
'username' => 'hman',
'password' => 'HPASS',
'roles' => array('web'),
),
'dewey' => array(
'username' => 'dman',
'password' => 'D---S',
'roles' => array('web', 'db'),
'nick' => 'dewey dman'
),
'lewey' => array(
'username' => 'lman',
'password' => 'LP@$$',
'roles' => array('db'),
),
)
));
// hman
$username = $data->get('hosts.hewey.username');
// HPASS
$password = $data->get('hosts.hewey.password');
// array('web')
$roles = $data->get('hosts.hewey.roles');
// dewey dman
$nick = $data->get('hosts.dewey.nick');
// Unknown
$nick = $data->get('hosts.lewey.nick', 'Unknown');
// DataInterface instance
$dewey = $data->getData('hosts.dewey');
// dman
$username = $dewey->get('username');
// D---S
$password = $dewey->get('password');
// array('web', 'db')
$roles = $dewey->get('roles');
// No more lewey
$data->remove('hosts.lewey');
// Add DB to hewey's roles
$data->append('hosts.hewey.roles', 'db');
$data->set('hosts.april', array(
'username' => 'aman',
'password' => '@---S',
'roles' => array('web'),
));
// Check if a key exists (true to this case)
$hasKey = $data->has('hosts.dewey.username');
```
License
-------
This library is licensed under the New BSD License - see the LICENSE file
for details.
Community
---------
If you have questions or want to help out, join us in the
[#dflydev](irc://irc.freenode.net/#dflydev) channel on irc.freenode.net.

View file

@ -0,0 +1,38 @@
{
"name": "dflydev/dot-access-data",
"type": "library",
"description": "Given a deep data structure, access data by dot notation.",
"homepage": "https://github.com/dflydev/dflydev-dot-access-data",
"keywords": ["dot", "access", "data", "notation"],
"license": "MIT",
"authors": [
{
"name": "Dragonfly Development Inc.",
"email": "info@dflydev.com",
"homepage": "http://dflydev.com"
},
{
"name": "Beau Simensen",
"email": "beau@dflydev.com",
"homepage": "http://beausimensen.com"
},
{
"name": "Carlos Frutos",
"email": "carlos@kiwing.it",
"homepage": "https://github.com/cfrutos"
}
],
"require": {
"php": ">=5.3.2"
},
"autoload": {
"psr-0": {
"Dflydev\\DotAccessData": "src"
}
},
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
}
}

View file

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true" bootstrap="tests/bootstrap.php">
<testsuites>
<testsuite name="Dot Access Data Test Suite">
<directory>./tests/Dflydev/DotAccessData</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./src/Dflydev/DotAccessData/</directory>
</whitelist>
</filter>
</phpunit>

View file

@ -0,0 +1,220 @@
<?php
/*
* This file is a part of dflydev/dot-access-data.
*
* (c) Dragonfly Development Inc.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Dflydev\DotAccessData;
class Data implements DataInterface
{
/**
* Internal representation of data data
*
* @var array
*/
protected $data;
/**
* Constructor
*
* @param array|null $data
*/
public function __construct(array $data = null)
{
$this->data = $data ?: array();
}
/**
* {@inheritdoc}
*/
public function append($key, $value = null)
{
if (0 == strlen($key)) {
throw new \RuntimeException("Key cannot be an empty string");
}
$currentValue =& $this->data;
$keyPath = explode('.', $key);
if (1 == count($keyPath)) {
if (!isset($currentValue[$key])) {
$currentValue[$key] = array();
}
if (!is_array($currentValue[$key])) {
// Promote this key to an array.
// TODO: Is this really what we want to do?
$currentValue[$key] = array($currentValue[$key]);
}
$currentValue[$key][] = $value;
return;
}
$endKey = array_pop($keyPath);
for ( $i = 0; $i < count($keyPath); $i++ ) {
$currentKey =& $keyPath[$i];
if ( ! isset($currentValue[$currentKey]) ) {
$currentValue[$currentKey] = array();
}
$currentValue =& $currentValue[$currentKey];
}
if (!isset($currentValue[$endKey])) {
$currentValue[$endKey] = array();
}
if (!is_array($currentValue[$endKey])) {
$currentValue[$endKey] = array($currentValue[$endKey]);
}
// Promote this key to an array.
// TODO: Is this really what we want to do?
$currentValue[$endKey][] = $value;
}
/**
* {@inheritdoc}
*/
public function set($key, $value = null)
{
if (0 == strlen($key)) {
throw new \RuntimeException("Key cannot be an empty string");
}
$currentValue =& $this->data;
$keyPath = explode('.', $key);
if (1 == count($keyPath)) {
$currentValue[$key] = $value;
return;
}
$endKey = array_pop($keyPath);
for ( $i = 0; $i < count($keyPath); $i++ ) {
$currentKey =& $keyPath[$i];
if (!isset($currentValue[$currentKey])) {
$currentValue[$currentKey] = array();
}
if (!is_array($currentValue[$currentKey])) {
throw new \RuntimeException("Key path at $currentKey of $key cannot be indexed into (is not an array)");
}
$currentValue =& $currentValue[$currentKey];
}
$currentValue[$endKey] = $value;
}
/**
* {@inheritdoc}
*/
public function remove($key)
{
if (0 == strlen($key)) {
throw new \RuntimeException("Key cannot be an empty string");
}
$currentValue =& $this->data;
$keyPath = explode('.', $key);
if (1 == count($keyPath)) {
unset($currentValue[$key]);
return;
}
$endKey = array_pop($keyPath);
for ( $i = 0; $i < count($keyPath); $i++ ) {
$currentKey =& $keyPath[$i];
if (!isset($currentValue[$currentKey])) {
return;
}
$currentValue =& $currentValue[$currentKey];
}
unset($currentValue[$endKey]);
}
/**
* {@inheritdoc}
*/
public function get($key, $default = null)
{
$currentValue = $this->data;
$keyPath = explode('.', $key);
for ( $i = 0; $i < count($keyPath); $i++ ) {
$currentKey = $keyPath[$i];
if (!isset($currentValue[$currentKey]) ) {
return $default;
}
if (!is_array($currentValue)) {
return $default;
}
$currentValue = $currentValue[$currentKey];
}
return $currentValue === null ? $default : $currentValue;
}
/**
* {@inheritdoc}
*/
public function has($key)
{
$currentValue = &$this->data;
$keyPath = explode('.', $key);
for ( $i = 0; $i < count($keyPath); $i++ ) {
$currentKey = $keyPath[$i];
if (
!is_array($currentValue) ||
!array_key_exists($currentKey, $currentValue)
) {
return false;
}
$currentValue = &$currentValue[$currentKey];
}
return true;
}
/**
* {@inheritdoc}
*/
public function getData($key)
{
$value = $this->get($key);
if (is_array($value) && Util::isAssoc($value)) {
return new Data($value);
}
throw new \RuntimeException("Value at '$key' could not be represented as a DataInterface");
}
/**
* {@inheritdoc}
*/
public function import(array $data, $clobber = true)
{
$this->data = Util::mergeAssocArray($this->data, $data, $clobber);
}
/**
* {@inheritdoc}
*/
public function importData(DataInterface $data, $clobber = true)
{
$this->import($data->export(), $clobber);
}
/**
* {@inheritdoc}
*/
public function export()
{
return $this->data;
}
}

View file

@ -0,0 +1,89 @@
<?php
/*
* This file is a part of dflydev/dot-access-data.
*
* (c) Dragonfly Development Inc.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Dflydev\DotAccessData;
interface DataInterface
{
/**
* Append a value to a key (assumes key refers to an array value)
*
* @param string $key
* @param mixed $value
*/
public function append($key, $value = null);
/**
* Set a value for a key
*
* @param string $key
* @param mixed $value
*/
public function set($key, $value = null);
/**
* Remove a key
*
* @param string $key
*/
public function remove($key);
/**
* Get the raw value for a key
*
* @param string $key
* @param mixed $default
*
* @return mixed
*/
public function get($key, $default = null);
/**
* Check if the key exists
*
* @param string $key
*
* @return bool
*/
public function has($key);
/**
* Get a data instance for a key
*
* @param string $key
*
* @return DataInterface
*/
public function getData($key);
/**
* Import data into existing data
*
* @param array $data
* @param bool $clobber
*/
public function import(array $data, $clobber = true);
/**
* Import data from an external data into existing data
*
* @param DataInterface $data
* @param bool $clobber
*/
public function importData(DataInterface $data, $clobber = true);
/**
* Export data as raw data
*
* @return array
*/
public function export();
}

View file

@ -0,0 +1,54 @@
<?php
/*
* This file is a part of dflydev/dot-access-data.
*
* (c) Dragonfly Development Inc.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Dflydev\DotAccessData;
class Util
{
/**
* Test if array is an associative array
*
* Note that this function will return true if an array is empty. Meaning
* empty arrays will be treated as if they are associative arrays.
*
* @param array $arr
*
* @return boolean
*/
public static function isAssoc(array $arr)
{
return (is_array($arr) && (!count($arr) || count(array_filter(array_keys($arr),'is_string')) == count($arr)));
}
/**
* Merge contents from one associtative array to another
*
* @param array $to
* @param array $from
* @param bool $clobber
*/
public static function mergeAssocArray($to, $from, $clobber = true)
{
if ( is_array($from) ) {
foreach ($from as $k => $v) {
if (!isset($to[$k])) {
$to[$k] = $v;
} else {
$to[$k] = self::mergeAssocArray($to[$k], $v, $clobber);
}
}
return $to;
}
return $clobber ? $from : $to;
}
}

View file

@ -0,0 +1,205 @@
<?php
/*
* This file is a part of dflydev/dot-access-data.
*
* (c) Dragonfly Development Inc.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Dflydev\DotAccessData;
class DataTest extends \PHPUnit_Framework_TestCase
{
protected function getSampleData()
{
return array(
'a' => 'A',
'b' => array(
'b' => 'B',
'c' => array('C1', 'C2', 'C3'),
'd' => array(
'd1' => 'D1',
'd2' => 'D2',
'd3' => 'D3',
),
),
'c' => array('c1', 'c2', 'c3'),
'f' => array(
'g' => array(
'h' => 'FGH',
),
),
'h' => array(
'i' => 'I',
),
'i' => array(
'j' => 'J',
),
);
}
protected function runSampleDataTests(DataInterface $data)
{
$this->assertEquals('A', $data->get('a'));
$this->assertEquals('B', $data->get('b.b'));
$this->assertEquals(array('C1', 'C2', 'C3'), $data->get('b.c'));
$this->assertEquals('D3', $data->get('b.d.d3'));
$this->assertEquals(array('c1', 'c2', 'c3'), $data->get('c'));
$this->assertNull($data->get('foo'), 'Foo should not exist');
$this->assertNull($data->get('f.g.h.i'));
$this->assertEquals($data->get('foo', 'default-value-1'), 'default-value-1', 'Return default value');
$this->assertEquals($data->get('f.g.h.i', 'default-value-2'), 'default-value-2');
}
public function testAppend()
{
$data = new Data($this->getSampleData());
$data->append('a', 'B');
$data->append('c', 'c4');
$data->append('b.c', 'C4');
$data->append('b.d.d3', 'D3b');
$data->append('b.d.d4', 'D');
$data->append('e', 'E');
$data->append('f.a', 'b');
$data->append('h.i', 'I2');
$data->append('i.k.l', 'L');
$this->assertEquals(array('A', 'B'), $data->get('a'));
$this->assertEquals(array('c1', 'c2', 'c3', 'c4'), $data->get('c'));
$this->assertEquals(array('C1', 'C2', 'C3', 'C4'), $data->get('b.c'));
$this->assertEquals(array('D3', 'D3b'), $data->get('b.d.d3'));
$this->assertEquals(array('D'), $data->get('b.d.d4'));
$this->assertEquals(array('E'), $data->get('e'));
$this->assertEquals(array('b'), $data->get('f.a'));
$this->assertEquals(array('I', 'I2'), $data->get('h.i'));
$this->assertEquals(array('L'), $data->get('i.k.l'));
$this->setExpectedException('RuntimeException');
$data->append('', 'broken');
}
public function testSet()
{
$data = new Data;
$this->assertNull($data->get('a'));
$this->assertNull($data->get('b.c'));
$this->assertNull($data->get('d.e'));
$data->set('a', 'A');
$data->set('b.c', 'C');
$data->set('d.e', array('f' => 'F', 'g' => 'G',));
$this->assertEquals('A', $data->get('a'));
$this->assertEquals(array('c' => 'C'), $data->get('b'));
$this->assertEquals('C', $data->get('b.c'));
$this->assertEquals('F', $data->get('d.e.f'));
$this->assertEquals(array('e' => array('f' => 'F', 'g' => 'G',)), $data->get('d'));
$this->setExpectedException('RuntimeException');
$data->set('', 'broken');
}
public function testSetClobberStringInPath()
{
$data = new Data;
$data->set('a.b.c', 'Should not be able to write to a.b.c.d.e');
$this->setExpectedException('RuntimeException');
$data->set('a.b.c.d.e', 'broken');
}
public function testRemove()
{
$data = new Data($this->getSampleData());
$data->remove('a');
$data->remove('b.c');
$data->remove('b.d.d3');
$data->remove('d');
$data->remove('d.e.f');
$data->remove('empty.path');
$this->assertNull($data->get('a'));
$this->assertNull($data->get('b.c'));
$this->assertNull($data->get('b.d.d3'));
$this->assertNull(null);
$this->assertEquals('D2', $data->get('b.d.d2'));
$this->setExpectedException('RuntimeException');
$data->remove('', 'broken');
}
public function testGet()
{
$data = new Data($this->getSampleData());
$this->runSampleDataTests($data);
}
public function testHas()
{
$data = new Data($this->getSampleData());
foreach (
array('a', 'i', 'b.d', 'f.g.h', 'h.i', 'b.d.d1') as $existentKey
) {
$this->assertTrue($data->has($existentKey));
}
foreach (
array('p', 'b.b1', 'b.c.C1', 'h.i.I', 'b.d.d1.D1') as $notExistentKey
) {
$this->assertFalse($data->has($notExistentKey));
}
}
public function testGetData()
{
$wrappedData = new Data(array(
'wrapped' => array(
'sampleData' => $this->getSampleData()
),
));
$data = $wrappedData->getData('wrapped.sampleData');
$this->runSampleDataTests($data);
$this->setExpectedException('RuntimeException');
$data = $wrappedData->getData('wrapped.sampleData.a');
}
public function testImport()
{
$data = new Data();
$data->import($this->getSampleData());
$this->runSampleDataTests($data);
}
public function testImportData()
{
$data = new Data();
$data->importData(new Data($this->getSampleData()));
$this->runSampleDataTests($data);
}
public function testExport()
{
$data = new Data($this->getSampleData());
$this->assertEquals($this->getSampleData(), $data->export());
}
}

View file

@ -0,0 +1,121 @@
<?php
/*
* This file is a part of dflydev/dot-access-data.
*
* (c) Dragonfly Development Inc.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Dflydev\DotAccessData;
class UtilTest extends \PHPUnit_Framework_TestCase
{
public function testIsAssoc()
{
$this->assertTrue(Util::isAssoc(array('a' => 'A',)));
$this->assertTrue(Util::isAssoc(array()));
$this->assertFalse(Util::isAssoc(array(1 => 'One',)));
}
/**
* @dataProvider mergeAssocArrayProvider
*/
public function testMergeAssocArray($message, $to, $from, $clobber, $expectedResult)
{
$result = Util::mergeAssocArray($to, $from, $clobber);
$this->assertEquals($expectedResult, $result, $message);
}
public function mergeAssocArrayProvider()
{
return array(
array(
'Clobber should replace to value with from value for strings (shallow)',
// to
array('a' => 'A'),
// from
array('a' => 'B'),
// clobber
true,
// expected result
array('a' => 'B'),
),
array(
'Clobber should replace to value with from value for strings (deep)',
// to
array('a' => array('b' => 'B',),),
// from
array('a' => array('b' => 'C',),),
// clobber
true,
// expected result
array('a' => array('b' => 'C',),),
),
array(
'Clobber should NOTreplace to value with from value for strings (shallow)',
// to
array('a' => 'A'),
// from
array('a' => 'B'),
// clobber
false,
// expected result
array('a' => 'A'),
),
array(
'Clobber should NOT replace to value with from value for strings (deep)',
// to
array('a' => array('b' => 'B',),),
// from
array('a' => array('b' => 'C',),),
// clobber
false,
// expected result
array('a' => array('b' => 'B',),),
),
array(
'Associative arrays should be combined',
// to
array('a' => array('b' => 'B',),),
// from
array('a' => array('c' => 'C',),),
// clobber
null,
// expected result
array('a' => array('b' => 'B', 'c' => 'C',),),
),
array(
'Arrays should be replaced (with clobber enabled)',
// to
array('a' => array('b', 'c',)),
// from
array('a' => array('B', 'C',),),
// clobber
true,
// expected result
array('a' => array('B', 'C',),),
),
array(
'Arrays should be NOT replaced (with clobber disabled)',
// to
array('a' => array('b', 'c',)),
// from
array('a' => array('B', 'C',),),
// clobber
false,
// expected result
array('a' => array('b', 'c',),),
),
);
}
}

View file

@ -0,0 +1,13 @@
<?php
/*
* This file is a part of dflydev/dot-access-data.
*
* (c) Dragonfly Development Inc.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
$loader = require dirname(__DIR__).'/vendor/autoload.php';