From 4c1764b861f096045b30cef71bc3f796dc94b182 Mon Sep 17 00:00:00 2001 From: Trevor Slocum Date: Wed, 29 Jun 2016 00:14:50 -0700 Subject: [PATCH] Update flatfile constructors for PHP7 compatibility - fixes #23 --- inc/flatfile/flatfile.php | 72 ++++++++++++++++++++++++++++----- inc/flatfile/flatfile_utils.php | 16 +++++++- 2 files changed, 77 insertions(+), 11 deletions(-) diff --git a/inc/flatfile/flatfile.php b/inc/flatfile/flatfile.php index dd4c931..078c281 100644 --- a/inc/flatfile/flatfile.php +++ b/inc/flatfile/flatfile.php @@ -76,10 +76,16 @@ class Flatfile { */ var $datadir; - function Flatfile() { + function __construct() { $this->schemata = array(); } + function Flatfile() { + if (version_compare(PHP_VERSION, '5.0.0', '<')) { + $this->__construct(); + } + } + /** * Get all rows from a table * @param string $tablename The table to get rows from @@ -427,10 +433,16 @@ class NotWhere extends WhereClause { * of the WhereClause object passed in when testing rows. * @param WhereClause $whereclause The WhereClause object to negate */ - function NotWhere($whereclause) { + function __construct($whereclause) { $this->clause = $whereclause; } + function NotWhere($whereclause) { + if (version_compare(PHP_VERSION, '5.0.0', '<')) { + $this->__construct($whereclause); + } + } + function testRow($row, $rowSchema = null) { return !$this->clause->testRow($row, $rowSchema); } @@ -480,13 +492,19 @@ class SimpleWhereClause extends WhereClause { * STRING_COMPARISON (default), NUMERIC COMPARISON or INTEGER_COMPARISON * */ - function SimpleWhereClause($field, $operator, $value, $compare_type = DEFAULT_COMPARISON) { + function __construct($field, $operator, $value, $compare_type = DEFAULT_COMPARISON) { $this->field = $field; $this->operator = $operator; $this->value = $value; $this->compare_type = $compare_type; } + function SimpleWhereClause($field, $operator, $value, $compare_type = DEFAULT_COMPARISON) { + if (version_compare(PHP_VERSION, '5.0.0', '<')) { + $this->__construct($field, $operator, $value, $compare_type); + } + } + function testRow($tablerow, $rowSchema = null) { if ($this->field < 0) return TRUE; @@ -536,11 +554,17 @@ class LikeWhereClause extends WhereClause { * wildcard, and is case insensitve. e.g. 'test%' will match 'TESTS' and 'Testing' */ - function LikeWhereClause($field, $value) { + function __construct($field, $value) { $this->field = $field; $this->regexp = '/^' . str_replace('%', '.*', preg_quote($value)) . '$/i'; } + function LikeWhereClause($field, $value) { + if (version_compare(PHP_VERSION, '5.0.0', '<')) { + $this->__construct($field, $value); + } + } + function testRow($tablerow, $rowSchema = NULL) { return preg_match($this->regexp, $tablerow[$this->field]); } @@ -570,12 +594,18 @@ class ListWhereClause extends WhereClause { * @param array $list List of items * @param string $compare_type Comparison type, string by default. */ - function ListWhereClause($field, $list, $compare_type = DEFAULT_COMPARISON) { + function __construct($field, $list, $compare_type = DEFAULT_COMPARISON) { $this->list = $list; $this->field = (int)$field; $this->compareAs = $compare_type; } + function ListWhereClause($field, $list, $compare_type = DEFAULT_COMPARISON) { + if (version_compare(PHP_VERSION, '5.0.0', '<')) { + $this->__construct($field, $list, $compare_type); + } + } + function testRow($tablerow, $rowSchema = null) { $func = $this->compareAs; if ($func == DEFAULT_COMPARISON) { @@ -639,9 +669,15 @@ class OrWhereClause extends CompositeWhereClause { * Creates a new OrWhereClause * @param WhereClause $whereClause,... optional unlimited list of WhereClause objects to be added */ - function OrWhereClause() { + function __construct() { $this->clauses = func_get_args(); } + + function OrWhereClause() { + if (version_compare(PHP_VERSION, '5.0.0', '<')) { + $this->__construct(); + } + } } /** @@ -667,9 +703,15 @@ class AndWhereClause extends CompositeWhereClause { * Creates a new AndWhereClause * @param WhereClause $whereClause,... optional unlimited list of WhereClause objects to be added */ - function AndWhereClause() { + function __construct() { $this->clauses = func_get_args(); } + + function AndWhereClause() { + if (version_compare(PHP_VERSION, '5.0.0', '<')) { + $this->__construct(); + } + } } @@ -701,11 +743,17 @@ class OrderBy { * @param int $compareAs Comparison type: DEFAULT_COMPARISON, STRING_COMPARISON, INTEGER_COMPARISION, * or NUMERIC_COMPARISON, or the name of a user defined function that you want to use for doing the comparison. */ - function OrderBy($field, $orderType, $compareAs = DEFAULT_COMPARISON) { + function __construct($field, $orderType, $compareAs = DEFAULT_COMPARISON) { $this->field = $field; $this->orderType = $orderType; $this->compareAs = $compareAs; } + + function OrderBy($field, $orderType, $compareAs) { + if (version_compare(PHP_VERSION, '5.0.0', '<')) { + $this->__construct(); + } + } } /** @@ -726,7 +774,7 @@ class Orderer { * @param mixed $orderBy An OrderBy object or an array of them * @param array $rowSchema Option row schema */ - function Orderer($orderBy, $rowSchema = null) { + function __construct($orderBy, $rowSchema = null) { if (!is_array($orderBy)) $orderBy = array($orderBy); if ($rowSchema) { @@ -741,6 +789,12 @@ class Orderer { $this->orderByList = $orderBy; } + function Orderer($orderBy, $rowSchema = null) { + if (version_compare(PHP_VERSION, '5.0.0', '<')) { + $this->__construct($orderBy, $rowSchema); + } + } + /** * Compares two table rows using the comparisons defined by the OrderBy * objects. This function is of the type that can be used passed to usort(). diff --git a/inc/flatfile/flatfile_utils.php b/inc/flatfile/flatfile_utils.php index 0326dd0..2afaea1 100644 --- a/inc/flatfile/flatfile_utils.php +++ b/inc/flatfile/flatfile_utils.php @@ -17,19 +17,31 @@ class Column { /** * Create a new column object */ - function Column($index, $type) { + function __construct($index, $type) { $this->index = $index; $this->type = $type; } + + function Column($index, $type) { + if (version_compare(PHP_VERSION, '5.0.0', '<')) { + $this->__construct($index, $type); + } + } } /** EXPERIMENTAL: Represent a column that is a foreign key. Used for temporarily building tables array */ class JoinColumn { - function JoinColumn($index, $tablename, $columnname) { + function __construct($index, $tablename, $columnname) { $this->index = $index; $this->tablename = $tablename; $this->columnname = $columnname; } + + function JoinColumn($index, $tablename, $columnname) { + if (version_compare(PHP_VERSION, '5.0.0', '<')) { + $this->__construct($index, $tablename, $columnname); + } + } } /**