Fix #254: CaseInsensitiveArray not found.

This commit is contained in:
Zach Borboa
2015-10-20 21:54:53 -07:00
parent d49186ae30
commit d69cded020
8 changed files with 92 additions and 89 deletions
+73
View File
@@ -0,0 +1,73 @@
<?php
namespace Curl;
class CaseInsensitiveArray implements \ArrayAccess, \Countable, \Iterator
{
private $container = array();
public function offsetSet($offset, $value)
{
if ($offset === null) {
$this->container[] = $value;
} else {
$index = array_search(strtolower($offset), array_keys(array_change_key_case($this->container, CASE_LOWER)));
if (!($index === false)) {
$keys = array_keys($this->container);
unset($this->container[$keys[$index]]);
}
$this->container[$offset] = $value;
}
}
public function offsetExists($offset)
{
return array_key_exists(strtolower($offset), array_change_key_case($this->container, CASE_LOWER));
}
public function offsetUnset($offset)
{
unset($this->container[$offset]);
}
public function offsetGet($offset)
{
$index = array_search(strtolower($offset), array_keys(array_change_key_case($this->container, CASE_LOWER)));
if ($index === false) {
return null;
}
$values = array_values($this->container);
return $values[$index];
}
public function count()
{
return count($this->container);
}
public function current()
{
return current($this->container);
}
public function next()
{
return next($this->container);
}
public function key()
{
return key($this->container);
}
public function valid()
{
return !($this->current() === false);
}
public function rewind()
{
reset($this->container);
}
}
+1 -71
View File
@@ -4,7 +4,7 @@ namespace Curl;
class Curl
{
const VERSION = '4.8.0';
const VERSION = '4.8.1';
const DEFAULT_TIMEOUT = 30;
public $curl;
@@ -997,73 +997,3 @@ class Curl
return (bool)count(array_filter($array, 'is_array'));
}
}
class CaseInsensitiveArray implements \ArrayAccess, \Countable, \Iterator
{
private $container = array();
public function offsetSet($offset, $value)
{
if ($offset === null) {
$this->container[] = $value;
} else {
$index = array_search(strtolower($offset), array_keys(array_change_key_case($this->container, CASE_LOWER)));
if (!($index === false)) {
$keys = array_keys($this->container);
unset($this->container[$keys[$index]]);
}
$this->container[$offset] = $value;
}
}
public function offsetExists($offset)
{
return array_key_exists(strtolower($offset), array_change_key_case($this->container, CASE_LOWER));
}
public function offsetUnset($offset)
{
unset($this->container[$offset]);
}
public function offsetGet($offset)
{
$index = array_search(strtolower($offset), array_keys(array_change_key_case($this->container, CASE_LOWER)));
if ($index === false) {
return null;
}
$values = array_values($this->container);
return $values[$index];
}
public function count()
{
return count($this->container);
}
public function current()
{
return current($this->container);
}
public function next()
{
return next($this->container);
}
public function key()
{
return key($this->container);
}
public function valid()
{
return !($this->current() === false);
}
public function rewind()
{
reset($this->container);
}
}
-2
View File
@@ -1,6 +1,4 @@
<?php
require '../src/Curl/Curl.php';
require 'Helper.php';
use \Curl\Curl;
use \Curl\CaseInsensitiveArray;
@@ -1,5 +1,4 @@
<?php
require '../src/Curl/MultiCurl.php';
use \Curl\MultiCurl;
use \Helper\Test;
+1 -1
View File
@@ -1,5 +1,5 @@
<?php
require 'Helper.php';
require_once 'Helper.php';
use \Helper\Test;
+4
View File
@@ -1,4 +1,8 @@
echo "TRAVIS_PHP_VERSION: ${TRAVIS_PHP_VERSION}"
composer self-update
composer install --prefer-source --no-interaction
if [[ "${TRAVIS_PHP_VERSION}" == "5.3" ]]; then
sudo add-apt-repository -y ppa:nginx/development
sudo apt-get update
+6 -7
View File
@@ -1,8 +1,7 @@
<phpunit>
<testsuite name="PHPCurlClass">
<directory>.</directory>
</testsuite>
<logging>
<log type="coverage-text" target="php://stdout" showUncoveredFiles="false" />
</logging>
<phpunit bootstrap="../vendor/autoload.php" colors="true">
<testsuites>
<testsuite name="PHPCurlClass">
<directory suffix=".php">./PHPCurlClass/</directory>
</testsuite>
</testsuites>
</phpunit>
+7 -7
View File
@@ -1,21 +1,21 @@
# Check syntax in php files.
find . -type "f" -iname "*.php" -exec php -l {} \;
find . -type "f" -iname "*.php" ! -path "*/vendor/*" -exec php -l {} \;
# Run tests.
cd tests && phpunit --configuration phpunit.xml
phpunit --configuration tests/phpunit.xml
if [[ "${?}" -ne 0 ]]; then
exit 1
fi
# Enforce line ending consistency in php files.
crlf_file=$(find . -type "f" -iname "*.php" -exec grep --files-with-matches $'\r' {} \;)
crlf_file=$(find . -type "f" -iname "*.php" ! -path "*/vendor/*" -exec grep --files-with-matches $'\r' {} \;)
if [[ ! -z "${crlf_file}" ]]; then
echo "${crlf_file}" | perl -pe 's/(.*)/CRLF line terminators found in \1/'
exit 1
fi
# Enforce indentation character consistency in php files.
tab_char=$(find . -type "f" -iname "*.php" -exec grep --line-number -H --perl-regexp "\t" {} \;)
tab_char=$(find . -type "f" -iname "*.php" ! -path "*/vendor/*" -exec grep --line-number -H --perl-regexp "\t" {} \;)
if [[ ! -z "${tab_char}" ]]; then
echo -e "${tab_char}" | perl -pe 's/^(.*)$/Tab character found in \1/'
exit 1
@@ -50,7 +50,7 @@ EOF
# Skip hhvm "Notice: File could not be loaded: ..."
if [[ "${TRAVIS_PHP_VERSION}" != "hhvm" ]]; then
export -f "find_invalid_indentation"
invalid_indentation=$(find . -type "f" -iname "*.php" -exec bash -c 'find_invalid_indentation "{}"' \;)
invalid_indentation=$(find . -type "f" -iname "*.php" ! -path "*/vendor/*" -exec bash -c 'find_invalid_indentation "{}"' \;)
if [[ ! -z "${invalid_indentation}" ]]; then
echo "${invalid_indentation}"
exit 1
@@ -58,14 +58,14 @@ if [[ "${TRAVIS_PHP_VERSION}" != "hhvm" ]]; then
fi
# Prohibit trailing whitespace in php files.
trailing_whitespace=$(find . -type "f" -iname "*.php" -exec egrep --line-number -H " +$" {} \;)
trailing_whitespace=$(find . -type "f" -iname "*.php" ! -path "*/vendor/*" -exec egrep --line-number -H " +$" {} \;)
if [[ ! -z "${trailing_whitespace}" ]]; then
echo -e "${trailing_whitespace}" | perl -pe 's/^(.*)$/Trailing whitespace found in \1/'
exit 1
fi
# Prohibit long lines in php files.
long_lines=$(find . -type "f" -iname "*.php" -exec awk '{print FILENAME":"NR" "length}' {} \; | awk '$2 > 120')
long_lines=$(find . -type "f" -iname "*.php" ! -path "*/vendor/*" -exec awk '{print FILENAME":"NR" "length}' {} \; | awk '$2 > 120')
if [[ ! -z "${long_lines}" ]]; then
echo -e "${long_lines}" | perl -pe 's/^(.*)$/Long lines found in \1/'
exit 1