@@ -33,7 +33,7 @@ |
||
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | private function getSearchFieldFunction($fields, $mode) { |
| 36 | - return function ($data) use ($fields, $mode) { |
|
| 36 | + return function($data) use ($fields, $mode) { |
|
| 37 | 37 | foreach ($fields as $key => $val) { |
| 38 | 38 | $currentFieldResult = $this->getIfFieldMatches($key, $val, $data, $mode); |
| 39 | 39 | |
@@ -19,11 +19,11 @@ discard block |
||
| 19 | 19 | //For dates with times set, search on time, if the time is not set, search on date only. |
| 20 | 20 | //E.g. searching for all records posted on '2015-11-14' should return all records that day, not just the ones posted at 00:00:00 on that day |
| 21 | 21 | if ($value instanceof \DateTime) { |
| 22 | - if ($value->format('H:i:s') == '00:00:00') $value = $value->format('Y-m-d'); |
|
| 22 | + if ($value->format('H:i:s') == '00:00:00') $value = $value->format('Y-m-d'); |
|
| 23 | 23 | else $value = $value->format('Y-m-d H:i:s'); |
| 24 | 24 | } |
| 25 | 25 | if (is_object($value)) continue; |
| 26 | - if ($prependField){ |
|
| 26 | + if ($prependField) { |
|
| 27 | 27 | $sql[] = $this->quote($field) . ' = :' . $field; |
| 28 | 28 | } else { |
| 29 | 29 | $sql[] = ':' . $field; |
@@ -35,13 +35,13 @@ discard block |
||
| 35 | 35 | |
| 36 | 36 | public function insert($table, $data) { |
| 37 | 37 | $query = $this->buildSaveQuery($data); |
| 38 | - return new Query('INSERT INTO ' . $this->quote($table) . ' (' .implode(', ', array_keys($query['args'])).') VALUES ( ' . implode(', ', $query['sql']). ' )', $query['args']); |
|
| 38 | + return new Query('INSERT INTO ' . $this->quote($table) . ' (' . implode(', ', array_keys($query['args'])) . ') VALUES ( ' . implode(', ', $query['sql']) . ' )', $query['args']); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | public function update($table, array $primaryKey, $data) { |
| 42 | 42 | $query = $this->buildSaveQuery($data, true); |
| 43 | 43 | $where = []; |
| 44 | - foreach($primaryKey as $field) $where[] = $this->quote($field) . ' = :' . $field; |
|
| 45 | - return new Query('UPDATE ' . $this->quote($table) . ' SET ' . implode(', ', $query['sql']). ' WHERE '. implode(' AND ', $where), $query['args']); |
|
| 44 | + foreach ($primaryKey as $field) $where[] = $this->quote($field) . ' = :' . $field; |
|
| 45 | + return new Query('UPDATE ' . $this->quote($table) . ' SET ' . implode(', ', $query['sql']) . ' WHERE ' . implode(' AND ', $where), $query['args']); |
|
| 46 | 46 | } |
| 47 | 47 | } |
@@ -24,8 +24,8 @@ discard block |
||
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | public function offsetGet($key) { |
| 27 | - $depth = $this->getDepth()+1; |
|
| 28 | - if (count($this->primaryKey)-1 == $depth) return $this->mapper->filter([$this->primaryKey[$depth] => $key])->item(0); |
|
| 27 | + $depth = $this->getDepth() + 1; |
|
| 28 | + if (count($this->primaryKey) - 1 == $depth) return $this->mapper->filter([$this->primaryKey[$depth] => $key])->item(0); |
|
| 29 | 29 | else return new MultiPk($this->mapper, $key, $this->primaryKey, $this); |
| 30 | 30 | } |
| 31 | 31 | |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | |
| 45 | 45 | public function offsetUnset($key) { |
| 46 | 46 | $keys = $this->primaryKey; |
| 47 | - $this->mapper->filter([ array_pop($keys) => $key])->delete(); |
|
| 47 | + $this->mapper->filter([array_pop($keys) => $key])->delete(); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | public function offsetExists($key) { |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | //bit hacky, breaking encapsulation, but simplest way to work out the info for the other side of the many:many relationship. |
| 38 | 38 | private function getOtherFieldNameInfo() { |
| 39 | 39 | if ($this->otherInfo == null) { |
| 40 | - $propertyReader = function($name) {return $this->$name; }; |
|
| 40 | + $propertyReader = function($name) {return $this->$name; }; |
|
| 41 | 41 | |
| 42 | 42 | $reader = $propertyReader->bindTo($this->intermediateMapper, $this->intermediateMapper); |
| 43 | 43 | |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | $propertyReader = $propertyReader->bindTo($relation, $relation); |
| 46 | 46 | if ($propertyReader('parentField') != $this->parentField) { |
| 47 | 47 | $relation = $relation->getData($this->object); |
| 48 | - $this->otherInfo = [$propertyReader('localField'), $propertyReader('parentField'), $propertyReader('mapper')]; |
|
| 48 | + $this->otherInfo = [$propertyReader('localField'), $propertyReader('parentField'), $propertyReader('mapper')]; |
|
| 49 | 49 | } |
| 50 | 50 | } |
| 51 | 51 | } |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | list($relatedField, $valueField, $mapper) = $this->getOtherFieldNameInfo(); |
| 89 | 89 | if ($this->autoTraverse) { |
| 90 | 90 | $record = new \stdClass; |
| 91 | - $record->{$this->parentField} = $value->{$this->localField}; |
|
| 91 | + $record->{$this->parentField} = $value->{$this->localField}; |
|
| 92 | 92 | $record->$valueField = $this->object->{$relatedField}; |
| 93 | 93 | $this->intermediateMapper[] = $record; |
| 94 | 94 | |
@@ -1,19 +1,19 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace Maphper; |
| 3 | 3 | class Maphper implements \Countable, \ArrayAccess, \IteratorAggregate { |
| 4 | - const FIND_EXACT = 0x1; |
|
| 5 | - const FIND_LIKE = 0x2; |
|
| 6 | - const FIND_STARTS = 0x4; |
|
| 7 | - const FIND_ENDS = 0x8; |
|
| 8 | - const FIND_BIT = 0x10; |
|
| 9 | - const FIND_GREATER = 0x20; |
|
| 10 | - const FIND_LESS = 0x40; |
|
| 11 | - const FIND_EXPRESSION = 0x80; |
|
| 12 | - const FIND_AND = 0x100; |
|
| 13 | - const FIND_OR = 0x200; |
|
| 14 | - const FIND_NOT = 0x400; |
|
| 15 | - const FIND_BETWEEN = 0x800; |
|
| 16 | - const FIND_NOCASE = 0x1000; |
|
| 4 | + const FIND_EXACT = 0x1; |
|
| 5 | + const FIND_LIKE = 0x2; |
|
| 6 | + const FIND_STARTS = 0x4; |
|
| 7 | + const FIND_ENDS = 0x8; |
|
| 8 | + const FIND_BIT = 0x10; |
|
| 9 | + const FIND_GREATER = 0x20; |
|
| 10 | + const FIND_LESS = 0x40; |
|
| 11 | + const FIND_EXPRESSION = 0x80; |
|
| 12 | + const FIND_AND = 0x100; |
|
| 13 | + const FIND_OR = 0x200; |
|
| 14 | + const FIND_NOT = 0x400; |
|
| 15 | + const FIND_BETWEEN = 0x800; |
|
| 16 | + const FIND_NOCASE = 0x1000; |
|
| 17 | 17 | |
| 18 | 18 | private $dataSource; |
| 19 | 19 | private $relations = []; |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | } |
| 58 | 58 | } |
| 59 | 59 | $results = $this->dataSource->findByField($this->settings['filter'], |
| 60 | - ['order' => $this->settings['sort'], 'limit' => $this->settings['limit'], 'offset' => $this->settings['offset'] ]); |
|
| 60 | + ['order' => $this->settings['sort'], 'limit' => $this->settings['limit'], 'offset' => $this->settings['offset']]); |
|
| 61 | 61 | |
| 62 | 62 | $siblings = new \ArrayObject(); |
| 63 | 63 | |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | $data = $this->dataSource->findByField(array_merge($this->settings['filter'], [$this->dataSource->getPrimaryKey()[0] => $offset])); |
| 109 | 109 | return isset($data[0]); |
| 110 | 110 | } |
| 111 | - return (bool) $this->dataSource->findById($offset); |
|
| 111 | + return (bool)$this->dataSource->findById($offset); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | public function offsetUnset($id) { |
@@ -21,7 +21,7 @@ |
||
| 21 | 21 | public function wrap($relations, $object, $siblings = []) { |
| 22 | 22 | //see if any relations need overwriting |
| 23 | 23 | foreach ($relations as $name => $relation) { |
| 24 | - if (isset($object->$name) && !($object->$name instanceof \Maphper\Relation) ) { |
|
| 24 | + if (isset($object->$name) && !($object->$name instanceof \Maphper\Relation)) { |
|
| 25 | 25 | //After overwriting the relation, does the parent object ($object) need overwriting as well? |
| 26 | 26 | if ($relation->overwrite($object, $object->$name)) $this->parent[] = $object; |
| 27 | 27 | } |
@@ -7,20 +7,20 @@ discard block |
||
| 7 | 7 | |
| 8 | 8 | public function __construct($object) { |
| 9 | 9 | if ($object instanceof \stdclass) { |
| 10 | - $this->readClosure = function() use ($object) { return $object; }; |
|
| 11 | - $this->writeClosure = function ($field, $value) use ($object) { $object->$field = $value; }; |
|
| 10 | + $this->readClosure = function() use ($object) { return $object; }; |
|
| 11 | + $this->writeClosure = function($field, $value) use ($object) { $object->$field = $value; }; |
|
| 12 | 12 | } |
| 13 | 13 | else { |
| 14 | 14 | $this->readClosure = function() { |
| 15 | 15 | $data = new \stdClass; |
| 16 | - foreach ($this as $k => $v) { |
|
| 16 | + foreach ($this as $k => $v) { |
|
| 17 | 17 | if (is_scalar($v) || is_null($v) || (is_object($v) && $v instanceof \DateTime)) $data->$k = $v; |
| 18 | 18 | } |
| 19 | 19 | return $data; |
| 20 | 20 | }; |
| 21 | 21 | $this->readClosure = $this->readClosure->bindTo($object, $object); |
| 22 | 22 | |
| 23 | - $this->writeClosure = function ($field, $value) { $this->$field = $value; }; |
|
| 23 | + $this->writeClosure = function($field, $value) { $this->$field = $value; }; |
|
| 24 | 24 | $this->writeClosure = $this->writeClosure->bindTo($object, $object); |
| 25 | 25 | } |
| 26 | 26 | |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | public function write($data) { |
| 34 | 34 | if ($data != null) { |
| 35 | 35 | foreach ($data as $key => $value) { |
| 36 | - ($this->writeClosure)($key, $this->processDates($value)); |
|
| 36 | + ($this->writeClosure)($key, $this->processDates($value)); |
|
| 37 | 37 | } |
| 38 | 38 | } |
| 39 | 39 | } |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | return; |
| 97 | 97 | |
| 98 | 98 | $runAgain = false; |
| 99 | - $columns = $this->pdo->query('SELECT * FROM '. $this->quote($table) . ' PROCEDURE ANALYSE(1,1)')->fetchAll(\PDO::FETCH_OBJ); |
|
| 99 | + $columns = $this->pdo->query('SELECT * FROM ' . $this->quote($table) . ' PROCEDURE ANALYSE(1,1)')->fetchAll(\PDO::FETCH_OBJ); |
|
| 100 | 100 | foreach ($columns as $column) { |
| 101 | 101 | $parts = explode('.', $column->Field_name); |
| 102 | 102 | $name = $this->quote(end($parts)); |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | } |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - $this->pdo->query('ALTER TABLE ' . $this->quote($table) . ' MODIFY '. $name . ' ' . $type); |
|
| 133 | + $this->pdo->query('ALTER TABLE ' . $this->quote($table) . ' MODIFY ' . $name . ' ' . $type); |
|
| 134 | 134 | } |
| 135 | 135 | } |
| 136 | 136 | //Sometimes a second pass is needed, if a column has gone from varchar -> int(11) a better int type may be needed |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | private function tableExists($name) { |
| 58 | - $result = $this->pdo->query('SELECT name FROM sqlite_master WHERE type="table" and name="'. $name.'"'); |
|
| 58 | + $result = $this->pdo->query('SELECT name FROM sqlite_master WHERE type="table" and name="' . $name . '"'); |
|
| 59 | 59 | return count($result->fetchAll()) == 1; |
| 60 | 60 | } |
| 61 | 61 | |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | // SQLSTATE[HY000]: General error: 17 database schema has changed |
| 75 | 75 | $this->queryCache = []; |
| 76 | 76 | |
| 77 | - $affix = '_'.substr(md5($table), 0, 6); |
|
| 77 | + $affix = '_' . substr(md5($table), 0, 6); |
|
| 78 | 78 | $this->createTable($table . $affix, $primaryKey, $data); |
| 79 | 79 | $fields = []; |
| 80 | 80 | foreach ($data as $key => $value) { $fields[] = $key; } |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | $columns = implode(', ', $this->getColumns($table)); |
| 84 | 84 | |
| 85 | 85 | $this->pdo->query('INSERT INTO ' . $this->quote($table . $affix) . '(' . $columns . ') SELECT ' . $columns . ' FROM ' . $this->quote($table)); |
| 86 | - $this->pdo->query('DROP TABLE IF EXISTS ' . $table ); |
|
| 86 | + $this->pdo->query('DROP TABLE IF EXISTS ' . $table); |
|
| 87 | 87 | } |
| 88 | 88 | } |
| 89 | 89 | catch (\PDOException $e) { |
@@ -91,8 +91,8 @@ discard block |
||
| 91 | 91 | echo $e->getMessage(); |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - $this->pdo->query('DROP TABLE IF EXISTS ' . $table ); |
|
| 95 | - $this->pdo->query('ALTER TABLE ' . $table . $affix. ' RENAME TO '. $table ); |
|
| 94 | + $this->pdo->query('DROP TABLE IF EXISTS ' . $table); |
|
| 95 | + $this->pdo->query('ALTER TABLE ' . $table . $affix . ' RENAME TO ' . $table); |
|
| 96 | 96 | |
| 97 | 97 | } |
| 98 | 98 | |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | |
| 107 | 107 | $pkField = implode(', ', $parts) . ', PRIMARY KEY(' . implode(', ', $primaryKey) . ')'; |
| 108 | 108 | |
| 109 | - $this->pdo->query('DROP TABLE IF EXISTS ' . $table ); |
|
| 109 | + $this->pdo->query('DROP TABLE IF EXISTS ' . $table); |
|
| 110 | 110 | $this->pdo->query('CREATE TABLE ' . $table . ' (' . $pkField . ')'); |
| 111 | 111 | |
| 112 | 112 | foreach ($data as $key => $value) { |