Finished add non array_* functions

This commit is contained in:
R. Eric Wheeler 2016-07-21 14:56:56 -07:00
parent 57310f3d26
commit 150ed44033
7 changed files with 1394 additions and 405 deletions

View File

@ -15,4 +15,9 @@ matrix:
before_script:
- composer install --dev
script: phpunit --coverage-text
script:
- mkdir -p build/logs
- php vendor/bin/phpunit -c phpunit.xml.dist
after_success:
- travis_retry php vendor/bin/coveralls -v

View File

@ -1,4 +1,5 @@
# ArrayObjectArray [![Build Status](https://travis-ci.org/sikofitt/array-object-array.svg?branch=master)](https://travis-ci.org/sikofitt/array-object-array)
# ArrayObjectArray [![Build Status](https://travis-ci.org/sikofitt/array-object-array.svg?branch=master)](https://travis-ci.org/sikofitt/array-object-array) [![Coverage Status](https://coveralls.io/repos/github/sikofitt/array-object-array/badge.svg?branch=master)](https://coveralls.io/github/sikofitt/array-object-array?branch=master)
This is an incredibly simple class extension of `\ArrayObject` to provide
array functions use the magic `__call` method. I no longer like writing this

View File

@ -1,22 +1,26 @@
{
"name": "sikofitt/array-object-array",
"description": "ArrayObject class that implements array functions through __call",
"keywords": ["array", "object", "php", "magic", "call"],
"type": "library",
"require": {
"php": ">=5.3.29",
"php": ">=5.3",
"symfony/polyfill-php54": "^1.2",
"symfony/polyfill-php55": "^1.2",
"symfony/polyfill-php56": "^1.2"
},
"require-dev": {
"phpunit/phpunit": "*",
"phpunit/php-code-coverage": "*"
"phpunit/phpunit": "~4.8",
"phpunit/php-code-coverage": "~2.2",
"satooshi/php-coveralls": "^1.0"
},
"license": "MIT",
"authors": [
{
"name": "sikofitt",
"email": "sikofitt@gmail.com"
"email": "sikofitt@gmail.com",
"homepage": "http://rewiv.com",
"role": "developer"
}
],
"autoload": {

536
composer.lock generated
View File

@ -4,8 +4,8 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "5da3f055fabd5e44bb25a547d0aea8de",
"content-hash": "623968123c52d5ef08b66b52671f3c04",
"hash": "e783c69d217d2ee4cd8d84375554030d",
"content-hash": "a03a3e83bc124fad42d5a75c770dc38a",
"packages": [
{
"name": "ircmaxell/password-compat",
@ -327,6 +327,102 @@
],
"time": "2015-06-14 21:17:01"
},
{
"name": "guzzle/guzzle",
"version": "v3.9.3",
"source": {
"type": "git",
"url": "https://github.com/guzzle/guzzle3.git",
"reference": "0645b70d953bc1c067bbc8d5bc53194706b628d9"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/guzzle3/zipball/0645b70d953bc1c067bbc8d5bc53194706b628d9",
"reference": "0645b70d953bc1c067bbc8d5bc53194706b628d9",
"shasum": ""
},
"require": {
"ext-curl": "*",
"php": ">=5.3.3",
"symfony/event-dispatcher": "~2.1"
},
"replace": {
"guzzle/batch": "self.version",
"guzzle/cache": "self.version",
"guzzle/common": "self.version",
"guzzle/http": "self.version",
"guzzle/inflection": "self.version",
"guzzle/iterator": "self.version",
"guzzle/log": "self.version",
"guzzle/parser": "self.version",
"guzzle/plugin": "self.version",
"guzzle/plugin-async": "self.version",
"guzzle/plugin-backoff": "self.version",
"guzzle/plugin-cache": "self.version",
"guzzle/plugin-cookie": "self.version",
"guzzle/plugin-curlauth": "self.version",
"guzzle/plugin-error-response": "self.version",
"guzzle/plugin-history": "self.version",
"guzzle/plugin-log": "self.version",
"guzzle/plugin-md5": "self.version",
"guzzle/plugin-mock": "self.version",
"guzzle/plugin-oauth": "self.version",
"guzzle/service": "self.version",
"guzzle/stream": "self.version"
},
"require-dev": {
"doctrine/cache": "~1.3",
"monolog/monolog": "~1.0",
"phpunit/phpunit": "3.7.*",
"psr/log": "~1.0",
"symfony/class-loader": "~2.1",
"zendframework/zend-cache": "2.*,<2.3",
"zendframework/zend-log": "2.*,<2.3"
},
"suggest": {
"guzzlehttp/guzzle": "Guzzle 5 has moved to a new package name. The package you have installed, Guzzle 3, is deprecated."
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.9-dev"
}
},
"autoload": {
"psr-0": {
"Guzzle": "src/",
"Guzzle\\Tests": "tests/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
},
{
"name": "Guzzle Community",
"homepage": "https://github.com/guzzle/guzzle/contributors"
}
],
"description": "PHP HTTP client. This library is deprecated in favor of https://packagist.org/packages/guzzlehttp/guzzle",
"homepage": "http://guzzlephp.org/",
"keywords": [
"client",
"curl",
"framework",
"http",
"http client",
"rest",
"web service"
],
"abandoned": "guzzlehttp/guzzle",
"time": "2015-03-18 18:23:50"
},
{
"name": "phpdocumentor/reflection-docblock",
"version": "2.0.4",
@ -683,16 +779,16 @@
},
{
"name": "phpunit/phpunit",
"version": "4.8.26",
"version": "4.8.27",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "fc1d8cd5b5de11625979125c5639347896ac2c74"
"reference": "c062dddcb68e44b563f66ee319ddae2b5a322a90"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/fc1d8cd5b5de11625979125c5639347896ac2c74",
"reference": "fc1d8cd5b5de11625979125c5639347896ac2c74",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/c062dddcb68e44b563f66ee319ddae2b5a322a90",
"reference": "c062dddcb68e44b563f66ee319ddae2b5a322a90",
"shasum": ""
},
"require": {
@ -751,7 +847,7 @@
"testing",
"xunit"
],
"time": "2016-05-17 03:09:28"
"time": "2016-07-21 06:48:14"
},
{
"name": "phpunit/phpunit-mock-objects",
@ -809,6 +905,102 @@
],
"time": "2015-10-02 06:51:40"
},
{
"name": "psr/log",
"version": "1.0.0",
"source": {
"type": "git",
"url": "https://github.com/php-fig/log.git",
"reference": "fe0936ee26643249e916849d48e3a51d5f5e278b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/log/zipball/fe0936ee26643249e916849d48e3a51d5f5e278b",
"reference": "fe0936ee26643249e916849d48e3a51d5f5e278b",
"shasum": ""
},
"type": "library",
"autoload": {
"psr-0": {
"Psr\\Log\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
}
],
"description": "Common interface for logging libraries",
"keywords": [
"log",
"psr",
"psr-3"
],
"time": "2012-12-21 11:40:51"
},
{
"name": "satooshi/php-coveralls",
"version": "v1.0.1",
"source": {
"type": "git",
"url": "https://github.com/satooshi/php-coveralls.git",
"reference": "da51d304fe8622bf9a6da39a8446e7afd432115c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/satooshi/php-coveralls/zipball/da51d304fe8622bf9a6da39a8446e7afd432115c",
"reference": "da51d304fe8622bf9a6da39a8446e7afd432115c",
"shasum": ""
},
"require": {
"ext-json": "*",
"ext-simplexml": "*",
"guzzle/guzzle": "^2.8|^3.0",
"php": ">=5.3.3",
"psr/log": "^1.0",
"symfony/config": "^2.1|^3.0",
"symfony/console": "^2.1|^3.0",
"symfony/stopwatch": "^2.0|^3.0",
"symfony/yaml": "^2.0|^3.0"
},
"suggest": {
"symfony/http-kernel": "Allows Symfony integration"
},
"bin": [
"bin/coveralls"
],
"type": "library",
"autoload": {
"psr-4": {
"Satooshi\\": "src/Satooshi/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Kitamura Satoshi",
"email": "with.no.parachute@gmail.com",
"homepage": "https://www.facebook.com/satooshi.jp"
}
],
"description": "PHP client library for Coveralls API",
"homepage": "https://github.com/satooshi/php-coveralls",
"keywords": [
"ci",
"coverage",
"github",
"test"
],
"time": "2016-01-20 17:35:46"
},
{
"name": "sebastian/comparator",
"version": "1.2.0",
@ -1181,6 +1373,336 @@
"homepage": "https://github.com/sebastianbergmann/version",
"time": "2015-06-21 13:59:46"
},
{
"name": "symfony/config",
"version": "v2.8.8",
"source": {
"type": "git",
"url": "https://github.com/symfony/config.git",
"reference": "0926e69411eba491803dbafb9f1f233e2ced58d0"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/config/zipball/0926e69411eba491803dbafb9f1f233e2ced58d0",
"reference": "0926e69411eba491803dbafb9f1f233e2ced58d0",
"shasum": ""
},
"require": {
"php": ">=5.3.9",
"symfony/filesystem": "~2.3|~3.0.0"
},
"suggest": {
"symfony/yaml": "To use the yaml reference dumper"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.8-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Component\\Config\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony Config Component",
"homepage": "https://symfony.com",
"time": "2016-06-29 05:31:50"
},
{
"name": "symfony/console",
"version": "v2.8.8",
"source": {
"type": "git",
"url": "https://github.com/symfony/console.git",
"reference": "c392a6ec72f2122748032c2ad6870420561ffcfa"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/console/zipball/c392a6ec72f2122748032c2ad6870420561ffcfa",
"reference": "c392a6ec72f2122748032c2ad6870420561ffcfa",
"shasum": ""
},
"require": {
"php": ">=5.3.9",
"symfony/polyfill-mbstring": "~1.0"
},
"require-dev": {
"psr/log": "~1.0",
"symfony/event-dispatcher": "~2.1|~3.0.0",
"symfony/process": "~2.1|~3.0.0"
},
"suggest": {
"psr/log": "For using the console logger",
"symfony/event-dispatcher": "",
"symfony/process": ""
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.8-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Component\\Console\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony Console Component",
"homepage": "https://symfony.com",
"time": "2016-06-29 07:02:14"
},
{
"name": "symfony/event-dispatcher",
"version": "v2.8.8",
"source": {
"type": "git",
"url": "https://github.com/symfony/event-dispatcher.git",
"reference": "b180b70439dca70049b6b9b7e21d75e6e5d7aca9"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/b180b70439dca70049b6b9b7e21d75e6e5d7aca9",
"reference": "b180b70439dca70049b6b9b7e21d75e6e5d7aca9",
"shasum": ""
},
"require": {
"php": ">=5.3.9"
},
"require-dev": {
"psr/log": "~1.0",
"symfony/config": "~2.0,>=2.0.5|~3.0.0",
"symfony/dependency-injection": "~2.6|~3.0.0",
"symfony/expression-language": "~2.6|~3.0.0",
"symfony/stopwatch": "~2.3|~3.0.0"
},
"suggest": {
"symfony/dependency-injection": "",
"symfony/http-kernel": ""
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.8-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Component\\EventDispatcher\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony EventDispatcher Component",
"homepage": "https://symfony.com",
"time": "2016-06-29 05:29:29"
},
{
"name": "symfony/filesystem",
"version": "v2.8.8",
"source": {
"type": "git",
"url": "https://github.com/symfony/filesystem.git",
"reference": "7258ddd6f987053f21fa43d03430580ba54e6096"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/filesystem/zipball/7258ddd6f987053f21fa43d03430580ba54e6096",
"reference": "7258ddd6f987053f21fa43d03430580ba54e6096",
"shasum": ""
},
"require": {
"php": ">=5.3.9"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.8-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Component\\Filesystem\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony Filesystem Component",
"homepage": "https://symfony.com",
"time": "2016-06-29 05:31:50"
},
{
"name": "symfony/polyfill-mbstring",
"version": "v1.2.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-mbstring.git",
"reference": "dff51f72b0706335131b00a7f49606168c582594"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/dff51f72b0706335131b00a7f49606168c582594",
"reference": "dff51f72b0706335131b00a7f49606168c582594",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"suggest": {
"ext-mbstring": "For best performance"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.2-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Polyfill\\Mbstring\\": ""
},
"files": [
"bootstrap.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony polyfill for the Mbstring extension",
"homepage": "https://symfony.com",
"keywords": [
"compatibility",
"mbstring",
"polyfill",
"portable",
"shim"
],
"time": "2016-05-18 14:26:46"
},
{
"name": "symfony/stopwatch",
"version": "v2.8.8",
"source": {
"type": "git",
"url": "https://github.com/symfony/stopwatch.git",
"reference": "35bae476693150728b0eb51647faac82faf9aaca"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/stopwatch/zipball/35bae476693150728b0eb51647faac82faf9aaca",
"reference": "35bae476693150728b0eb51647faac82faf9aaca",
"shasum": ""
},
"require": {
"php": ">=5.3.9"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.8-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Component\\Stopwatch\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony Stopwatch Component",
"homepage": "https://symfony.com",
"time": "2016-06-29 05:29:29"
},
{
"name": "symfony/yaml",
"version": "v2.8.8",

View File

@ -14,6 +14,9 @@
verbose="true"
debug="true"
>
<logging>
<log type="coverage-clover" target="build/logs/clover.xml" />
</logging>
<testsuites>
<testsuite name="ArrayObjectArray tests">
<directory>./tests/Sikofitt</directory>

View File

@ -19,8 +19,133 @@ namespace Sikofitt\Utility;
*
* @package Sikofitt\Utility
*/
class ArrayObjectArray extends \ArrayObject
use Guzzle\Common\Exception\BadMethodCallException;
/**
* Class ArrayObjectArray
*
* @package Sikofitt\Utility
*/
class ArrayObjectArray extends \ArrayObject implements \IteratorAggregate
{
/**
* @var \ArrayIterator
*/
private $iterator;
/**
* ArrayObjectArray constructor.
*
* @param null $input
* @param int $flags
* @param string $iterator_class
*/
public function __construct(
$input = null,
$flags = 0,
$iterator_class = 'ArrayIterator'
) {
// SORT_FLAG_CASE and SORT_NATURAL were introduced in php 5.4
if (!defined('SORT_FLAG_CASE')) { define('SORT_FLAG_CASE', 8); } elseif(!defined('SORT_NATURAL')) { define('SORT_NATURAL', 6); }
// ARRAY_FILTER_USE_* flags were added in php 5.6
// along with a 3rd parameter to use them.
if (!defined('ARRAY_FILTER_USE_BOTH')) { define('ARRAY_FILTER_USE_BOTH', 1); } elseif (!defined('ARRAY_FILTER_USE_KEY')) { define('ARRAY_FILTER_USE_KEY', 2); }
parent::__construct($input, $flags, $iterator_class);
$this->iterator = $this->getIterator();
}
/**
* @param string $iterator_class
*/
public function setIteratorClass($iterator_class)
{
parent::setIteratorClass($iterator_class);
$this->iterator = $this->getIterator();
}
/**
*
*/
public function pos()
{
return pos($this->iterator);
}
/**
* @return mixed
*/
public function key()
{
return key($this->iterator);
}
/**
* @return mixed
*/
public function current()
{
return current($this->iterator);
}
/**
*
*/
public function next()
{
next($this->iterator);
}
/**
*
*/
public function reset()
{
reset($this->iterator);
}
/**
* @return bool
*/
public function valid()
{
return $this->iterator->valid();
}
/**
*
*/
public function prev()
{
prev($this->iterator);
}
/**
*
*/
public function end()
{
end($this->iterator);
}
public function each()
{
static $arrayCopy;
if(!$arrayCopy) {
$arrayCopy = $this->getArrayCopy();
}
return each($arrayCopy);
}
/**
* @param $needle
* @param bool $strict
*
* @return bool
*/
public function in_array($needle, $strict = false)
{
return in_array($needle, $this->getArrayCopy(), $strict);
}
/**
* @param $function
* @param $argv
@ -29,11 +154,14 @@ class ArrayObjectArray extends \ArrayObject
*/
public function __call($function, $argv)
{
if (!is_callable($function) || substr($function, 0, 6) !== 'array_') {
throw new \BadMethodCallException(__CLASS__ . '->' . $function);
if (0 !== strcasecmp($function, 'key_exists')) {
if (!is_callable($function) || substr($function, 0, 6) !== 'array_') {
throw new \BadMethodCallException(__CLASS__ . '->' . $function);
}
}
switch ($function) {
case 'array_key_exists':
case 'key_exists':
return call_user_func(
$function,
$argv[0],
@ -62,8 +190,8 @@ class ArrayObjectArray extends \ArrayObject
* We don't need to do anything here because this
* doesn't actually touch our array. Just returns one.
*
* @param int $startIndex
* @param int $num
* @param int $startIndex
* @param int $num
* @param mixed $value
*
* @return array
@ -74,4 +202,108 @@ class ArrayObjectArray extends \ArrayObject
{
return \array_fill($startIndex, $num, $value);
}
/**
* Alias of count
*
* @return int
*/
public function sizeof()
{
return $this->count();
}
/**
* @param null|int $sort_flags
*
* @return bool
*/
public function krsort($sort_flags = null)
{
$arrayCopy = $this->getArrayCopy();
if (@\krsort($arrayCopy, $sort_flags)) {
$this->exchangeArray($arrayCopy);
return true;
} else {
return false;
}
}
/**
* @param null|int $sort_flags
*
* @return bool
*/
public function rsort($sort_flags = null)
{
$arrayCopy = $this->getArrayCopy();
if(@\rsort($arrayCopy, $sort_flags))
{
$this->exchangeArray($arrayCopy);
return true;
} else {
return false;
}
}
/**
* @param null|int $sort_flags
*
* @return bool
*/
public function sort($sort_flags = null)
{
$arrayCopy = $this->getArrayCopy();
if(@\sort($arrayCopy, $sort_flags))
{
$this->exchangeArray($arrayCopy);
return true;
} else {
return false;
}
}
public function usort($callback)
{
if(!is_callable($callback))
{
throw new \BadFunctionCallException($callback);
}
$arrayCopy = $this->getArrayCopy();
if(true === $returnVal = @\usort($arrayCopy, $callback))
{
$this->exchangeArray($arrayCopy);
}
return $returnVal;
}
/**
* @param int $sort_flags
*
* @return bool
*/
public function arsort($sort_flags = SORT_REGULAR)
{
$arrayCopy = $this->getArrayCopy();
if (@\arsort($arrayCopy, $sort_flags)) {
$this->exchangeArray($arrayCopy);
return true;
} else {
return false;
}
}
/**
* @return bool
*/
public function shuffle()
{
$arrayCopy = $this->getArrayCopy();
if (true === $returnVal = shuffle($arrayCopy)) {
$this->exchangeArray($arrayCopy);
}
return $returnVal;
}
}

File diff suppressed because it is too large Load Diff