Skip to content

Commit

Permalink
Drop PHP 5.5 support
Browse files Browse the repository at this point in the history
  • Loading branch information
olvlvl committed Mar 12, 2016
1 parent f90d6d7 commit a05317c
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 57 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ sudo: false
language: php

php:
- 5.5
- 5.6
- 7.0
- hhvm
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"minimum-stability": "dev",

"require": {
"php": ">=5.5.0",
"php": ">=5.6.0",
"ext-pdo": "*",
"icanboogie/prototype": "^2.3",
"icanboogie/inflector": "^1.4",
Expand Down
4 changes: 3 additions & 1 deletion lib/ActiveRecord/ActiveRecordClassNotValid.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

use ICanBoogie\Accessor\AccessorTrait;

use function ICanBoogie\format;

/**
* Exception thrown when the ActiveRecord class is not valid.
*
Expand Down Expand Up @@ -57,7 +59,7 @@ public function __construct($class, $message = null, $code = 500, \Exception $pr
*/
protected function format_message($class)
{
return \ICanBoogie\format("ActiveRecord class is not valid: %class", [
return format("ActiveRecord class is not valid: %class", [

'class' => $class

Expand Down
4 changes: 3 additions & 1 deletion lib/ActiveRecord/BelongsToRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use ICanBoogie\ActiveRecord;
use ICanBoogie\Prototype;

use function ICanBoogie\singularize;

/**
* Representation of the one-to-one relation.
*/
Expand Down Expand Up @@ -80,6 +82,6 @@ protected function alter_prototype(Prototype $prototype, $property)
*/
protected function resolve_property_name($related)
{
return \ICanBoogie\singularize(parent::resolve_property_name($related));
return singularize(parent::resolve_property_name($related));
}
}
4 changes: 3 additions & 1 deletion lib/ActiveRecord/ConnectionAlreadyEstablished.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

use ICanBoogie\Accessor\AccessorTrait;

use function ICanBoogie\format;

/**
* Exception thrown in attempt to set the definition of an already established connection.
*
Expand Down Expand Up @@ -56,7 +58,7 @@ public function __construct($id, $code = 500, \Exception $previous = null)
*/
protected function format_message($id)
{
return \ICanBoogie\format("Connection already established: %id.", [
return format("Connection already established: %id.", [

'id' => $id

Expand Down
4 changes: 3 additions & 1 deletion lib/ActiveRecord/ConnectionNotDefined.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

use ICanBoogie\Accessor\AccessorTrait;

use function ICanBoogie\format;

/**
* Exception thrown in attempt to obtain a connection that is not defined.
*
Expand Down Expand Up @@ -53,7 +55,7 @@ public function __construct($id, $code = 500, \Exception $previous = null)
*/
protected function format_message($id)
{
return \ICanBoogie\format("Connection not defined: %id.", [
return format("Connection not defined: %id.", [

'id' => $id

Expand Down
4 changes: 3 additions & 1 deletion lib/ActiveRecord/HasManyRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

use ICanBoogie\ActiveRecord;

use function ICanBoogie\pluralize;

/**
* Representation of the one-to-many relation.
*/
Expand All @@ -34,6 +36,6 @@ public function __invoke(ActiveRecord $record)

protected function resolve_property_name($related)
{
return \ICanBoogie\pluralize(parent::resolve_property_name($related));
return pluralize(parent::resolve_property_name($related));
}
}
25 changes: 20 additions & 5 deletions lib/ActiveRecord/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* @method ActiveRecord one() one() The method is forwarded to {@link Query::one}.
* @method ActiveRecord new() new(array $properties = []) Instantiate a new record.
*
* @method Model belongs_to() belongs_to($definition) Add a _belongs_to_ relation.
* @method Model belongs_to() belongs_to(...$args) Adds a _belongs_to_ relation.
* @method Model has_many() has_many($related, $options = []) Adds a _has_many_ relation.
*
* @property-read Model|null $parent Parent model.
Expand Down Expand Up @@ -163,6 +163,21 @@ public function __construct(ModelCollection $models, array $attributes)
$this->resolve_relations();
}

// @codeCoverageIgnoreStart
public function __debugInfo()
{
return [

'id' => $this->id,
'name' => "$this->name ($this->unprefixed_name)",
'parent' => $this->parent ? $this->parent->id . " of " . get_class($this->parent) : null,
'parent_model' => $this->parent_model ? $this->parent_model->id . " of " . get_class($this->parent_model) : null,
'relations' => $this->relations

];
}
// @codeCoverageIgnoreEnd

/**
* Resolves constructor attributes.
*
Expand Down Expand Up @@ -259,7 +274,7 @@ public function __call($method, $arguments)
{
if ($method == 'new')
{
return call_user_func_array([ $this, 'new_record' ], $arguments);
return $this->new_record(...$arguments);
}

if (is_callable([ Query::class, $method ])
Expand All @@ -268,12 +283,12 @@ public function __call($method, $arguments)
{
$query = new Query($this);

return call_user_func_array([ $query, $method ], $arguments);
return $query->$method(...$arguments);
}

if (is_callable([ RelationCollection::class, $method ]))
{
return call_user_func_array([ $this->relations, $method ], $arguments);
return $this->relations->$method(...$arguments);
}

return parent::__call($method, $arguments);
Expand Down Expand Up @@ -542,7 +557,7 @@ public function scope($scope_name, array $scope_args = [])
{
try
{
return call_user_func_array([ $this, 'scope_' . $scope_name ], $scope_args);
return $this->{ 'scope_' . $scope_name}(...$scope_args);
}
catch (MethodNotDefined $e)
{
Expand Down
62 changes: 26 additions & 36 deletions lib/ActiveRecord/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public function __call($method, $arguments)
{
if ($method === 'and')
{
return call_user_func_array([ $this, 'where' ], $arguments);
return $this->where(...$arguments);
}

if (strpos($method, 'filter_by_') === 0)
Expand Down Expand Up @@ -687,13 +687,14 @@ private function render_join_on($column, $as, Query $query)
*
* {@link \DateTime} conditions are converted to strings.
*
* @param $conditions_and_args
*
* @return array An array made of the condition string and its arguments.
*/
private function deferred_parse_conditions()
private function deferred_parse_conditions(...$conditions_and_args)
{
$args = debug_backtrace(0, 2)[1]['args'];

$conditions = array_shift($args);
$conditions = array_shift($conditions_and_args);
$args = $conditions_and_args;

if (is_array($conditions))
{
Expand Down Expand Up @@ -832,15 +833,13 @@ private function dynamic_filter($filter, array $conditions_args = [])
*
* This will return the orders with the `order_count` different than 2.
*
* @param mixed $conditions
* @param mixed $conditions_args
* @param mixed $_ [optional]
* @param mixed ...$conditions_and_args
*
* @return Query
*/
public function where($conditions, $conditions_args = null, $_ = null)
public function where(...$conditions_and_args)
{
list($conditions, $conditions_args) = $this->deferred_parse_conditions();
list($conditions, $conditions_args) = $this->deferred_parse_conditions(...$conditions_and_args);

if ($conditions)
{
Expand Down Expand Up @@ -888,19 +887,13 @@ public function group($group)
/**
* Defines the `HAVING` clause.
*
* @param mixed $conditions
* @param mixed $conditions_args
* @param mixed ...$conditions_and_args
*
* @return Query
*/
public function having($conditions, $conditions_args = null)
public function having(...$conditions_and_args)
{
if (!$this->group)
{
throw new \LogicException("having() cannot be used without invoking group() first.");
}

list($having, $having_args) = $this->deferred_parse_conditions();
list($having, $having_args) = $this->deferred_parse_conditions(...$conditions_and_args);

$this->having = $having;
$this->having_args = $having_args;
Expand Down Expand Up @@ -1014,17 +1007,17 @@ public function query()
*/

/**
* Resolves fetch mode from backtrace.
* Resolves fetch mode.
*
* @param mixed ...$mode
*
* @return array
*/
private function resolve_fetch_mode()
private function resolve_fetch_mode(...$mode)
{
$trace = debug_backtrace(0, 2);

if ($trace[1]['args'])
if ($mode)
{
$args = $trace[1]['args'];
$args = $mode;
}
else if ($this->mode)
{
Expand All @@ -1049,16 +1042,13 @@ private function resolve_fetch_mode()
/**
* Execute the query and returns an array of records.
*
* @param mixed $_ [optional]
* @param mixed ...$mode Fetch mode.
*
* @return array
*/
public function all($_ = null)
public function all(...$mode)
{
$statement = $this->query();
$args = $this->resolve_fetch_mode();

return call_user_func_array([ $statement, 'fetchAll' ], $args);
return $this->query()->fetchAll(...$this->resolve_fetch_mode(...$mode));
}

/**
Expand All @@ -1074,30 +1064,30 @@ protected function get_all()
/**
* Return the first result of the query and close the cursor.
*
* @param $_ [optional] Fetch mode.
* @param mixed ...$mode Fetch node.
*
* @return mixed The return value of this function on success depends on the fetch mode. In
* all cases, FALSE is returned on failure.
*/
public function one($_ = null)
public function one(...$mode)
{
$query = clone $this;
$query->limit = 1;
$statement = $query->query();
$args = $query->resolve_fetch_mode();
$args = $query->resolve_fetch_mode(...$mode);

if (count($args) > 1 && $args[0] == \PDO::FETCH_CLASS)
{
array_shift($args);

$rc = call_user_func_array([ $statement, 'fetchObject' ], $args);
$rc = $statement->fetchObject(...$args);

$statement->closeCursor();

return $rc;
}

return call_user_func_array([ $statement, 'one' ], $args);
return $statement->one(...$args);
}

/**
Expand Down
17 changes: 9 additions & 8 deletions lib/ActiveRecord/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,9 @@ public function execute($args = [])
*
* @see http://www.php.net/manual/en/pdostatement.setfetchmode.php
*/
public function mode($mode)
public function mode(...$mode)
{
$mode = func_get_args();

if (!call_user_func_array([ $this, 'setFetchMode' ], $mode))
if (!$this->setFetchMode(...$mode))
{
throw new UnableToSetFetchMode($mode);
}
Expand All @@ -145,8 +143,7 @@ public function mode($mode)
*/
public function one($fetch_style = \PDO::FETCH_BOTH, $cursor_orientation = \PDO::FETCH_ORI_NEXT, $cursor_offset = 0)
{
$args = func_get_args();
$rc = call_user_func_array([ $this, 'fetch' ], $args);
$rc = $this->fetch(...func_get_args());

$this->closeCursor();

Expand Down Expand Up @@ -195,10 +192,14 @@ protected function get_rc()

/**
* Alias for {@link \PDOStatement::fetchAll()}
*
* @param mixed $mode
*
* @return array
*/
public function all($fetch_style = null, $column_index = null, array $ctor_args = null)
public function all(...$mode)
{
return call_user_func_array([ $this, 'fetchAll' ], func_get_args());
return $this->fetchAll(...$mode);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion lib/ActiveRecord/UnableToSetFetchMode.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

use ICanBoogie\Accessor\AccessorTrait;

use function ICanBoogie\format;

/**
* Exception thrown when the fetch mode of a statement fails to be set.
*
Expand Down Expand Up @@ -54,6 +56,6 @@ public function __construct($mode, $message = null, $code = 500, \Exception $pre
*/
protected function format_message($mode)
{
return \ICanBoogie\format("Unable to set fetch mode: %mode", [ 'mode' => $mode ]);
return format("Unable to set fetch mode: %mode", [ 'mode' => $mode ]);
}
}

0 comments on commit a05317c

Please sign in to comment.