Compatibility with PHP5.3: Changing [] syntax to array()

This commit is contained in:
Pablo Lopez Torres 2014-09-04 18:33:45 +02:00
parent 42d2c2d1f0
commit 581ad939e6
6 changed files with 19 additions and 18 deletions

View File

@ -2,6 +2,7 @@ language: php
script: phpunit script: phpunit
php: php:
- 5.3
- 5.4 - 5.4
- 5.5 - 5.5

View File

@ -64,9 +64,9 @@ class BaseHTTP
$c->children[] = $this; $c->children[] = $this;
} }
protected function getCurl($url, array $args = []) protected function getCurl($url, array $args = array())
{ {
$args = array_merge($args, ['u' => $this->user, 'p' => $this->pass]); $args = array_merge($args, array('u' => $this->user, 'p' => $this->pass));
$url = "http://{$this->host}:{$this->port}/{$this->base}{$url}"; $url = "http://{$this->host}:{$this->port}/{$this->base}{$url}";
$url .= "?" . http_build_query($args); $url .= "?" . http_build_query($args);
$ch = curl_init($url); $ch = curl_init($url);
@ -89,9 +89,9 @@ class BaseHTTP
protected function delete($url) protected function delete($url)
{ {
$ch = $this->getCurl($url); $ch = $this->getCurl($url);
curl_setopt_array($ch, [ curl_setopt_array($ch, array(
CURLOPT_CUSTOMREQUEST => "DELETE", CURLOPT_CUSTOMREQUEST => "DELETE",
]); ));
return $this->execCurl($ch); return $this->execCurl($ch);
} }
@ -119,19 +119,19 @@ class BaseHTTP
throw new \InvalidArgumentException("Expecting s, m or u as time precision"); throw new \InvalidArgumentException("Expecting s, m or u as time precision");
} }
protected function get($url, array $args = []) protected function get($url, array $args = array())
{ {
$ch = $this->getCurl($url, $args); $ch = $this->getCurl($url, $args);
return $this->execCurl($ch, true); return $this->execCurl($ch, true);
} }
protected function post($url, array $body, array $args = []) protected function post($url, array $body, array $args = array())
{ {
$ch = $this->getCurl($url, $args); $ch = $this->getCurl($url, $args);
curl_setopt_array($ch, [ curl_setopt_array($ch, array(
CURLOPT_POST => 1, CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => json_encode($body), CURLOPT_POSTFIELDS => json_encode($body),
]); ));
return $this->execCurl($ch); return $this->execCurl($ch);
} }

View File

@ -59,7 +59,7 @@ class Client extends BaseHTTP
public function createDatabase($name) public function createDatabase($name)
{ {
$this->post('db', ['name' => $name]); $this->post('db', array('name' => $name));
return new DB($this, $name); return new DB($this, $name);
} }

View File

@ -43,7 +43,7 @@ class Cursor extends ArrayIterator
{ {
public function __construct(array $resultset) public function __construct(array $resultset)
{ {
$rows = []; $rows = array();
foreach ($resultset as $set) { foreach ($resultset as $set) {
foreach ($set['points'] as $row) { foreach ($set['points'] as $row) {
$row = (object)array_combine($set['columns'], $row); $row = (object)array_combine($set['columns'], $row);

View File

@ -62,17 +62,17 @@ class DB extends BaseHTTP
public function insert($name, array $data) public function insert($name, array $data)
{ {
$points = []; $points = array();
$first = current($data); $first = current($data);
if (!is_array($first)) { if (!is_array($first)) {
return $this->insert($name, [$data]); return $this->insert($name, array($data));
} }
$columns = array_keys($first); $columns = array_keys($first);
foreach ($data as $value) { foreach ($data as $value) {
$points[] = array_values($value); $points[] = array_values($value);
} }
$body = compact('name', 'columns', 'points'); $body = compact('name', 'columns', 'points');
return $this->post('series', [$body], ['time_precision' => $this->timePrecision]); return $this->post('series', array($body), array('time_precision' => $this->timePrecision));
} }
public function first($sql) public function first($sql)
@ -82,7 +82,7 @@ class DB extends BaseHTTP
public function query($sql) public function query($sql)
{ {
return new Cursor($this->get('series', ['q' => $sql, 'time_precision' => $this->timePrecision])); return new Cursor($this->get('series', array('q' => $sql, 'time_precision' => $this->timePrecision)));
} }
public function createUser($name, $password) public function createUser($name, $password)

View File

@ -69,7 +69,7 @@ class DBTest extends \PHPUnit_Framework_TestCase
public function testInvalidTimePrecision() public function testInvalidTimePrecision()
{ {
$client = new Client; $client = new Client;
$client->SetTimePrecision([]); $client->SetTimePrecision(array());
} }
public function testQuery() public function testQuery()
@ -78,9 +78,9 @@ class DBTest extends \PHPUnit_Framework_TestCase
$db = $client->createDatabase("test_xxx"); $db = $client->createDatabase("test_xxx");
$db->createUser("root", "root"); $db->createUser("root", "root");
$db->insert("foobar", ['type' => '/foobar', 'karma' => 10]); $db->insert("foobar", array('type' => '/foobar', 'karma' => 10));
$db->insert("foobar", ['type' => '/foobar', 'karma' => 20]); $db->insert("foobar", array('type' => '/foobar', 'karma' => 20));
$db->insert("foobar", ['type' => '/barfoo', 'karma' => 30]); $db->insert("foobar", array('type' => '/barfoo', 'karma' => 30));
$this->assertEquals($db->first("SELECT max(karma) FROM foobar")->max, 30); $this->assertEquals($db->first("SELECT max(karma) FROM foobar")->max, 30);
$this->assertEquals($db->first("SELECT min(karma) FROM foobar")->min, 10); $this->assertEquals($db->first("SELECT min(karma) FROM foobar")->min, 10);