@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | private function getAdapter(\PDO $pdo) { |
| 36 | - $adapter = '\\Maphper\\DataSource\\' . ucfirst($pdo->getAttribute(\PDO::ATTR_DRIVER_NAME)) . 'Adapter'; |
|
| 36 | + $adapter = '\\Maphper\\DataSource\\' . ucfirst($pdo->getAttribute(\PDO::ATTR_DRIVER_NAME)) . 'Adapter'; |
|
| 37 | 37 | return new $adapter($pdo); |
| 38 | 38 | } |
| 39 | 39 | |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | else $limit = ''; |
| 122 | 122 | |
| 123 | 123 | $query = $this->selectBuilder->createSql($fields, $mode); |
| 124 | - $query['sql'] = array_filter($query['sql']); |
|
| 124 | + $query['sql'] = array_filter($query['sql']); |
|
| 125 | 125 | $this->adapter->query($this->crudBuilder->delete($this->table, $query['sql'], $query['args'], $limit)); |
| 126 | 126 | $this->addIndex(array_keys($query['args'])); |
| 127 | 127 | |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | if (isset($options['fields'])) $this->fields = implode(',', array_map([$this->adapter, 'quote'], $options['fields'])); |
| 30 | 30 | $this->defaultSort = (isset($options['defaultSort'])) ? $options['defaultSort'] : implode(', ', $this->primaryKey); |
| 31 | 31 | if (isset($options['editmode'])) $this->alterDb = $options['editmode'] == true ? self::EDIT_STRUCTURE | self::EDIT_INDEX | self::EDIT_OPTIMISE : $options['editmode']; |
| 32 | - if (self::EDIT_OPTIMISE & $this->alterDb && rand(0,500) == 1) $this->adapter->optimiseColumns($table); |
|
| 32 | + if (self::EDIT_OPTIMISE & $this->alterDb && rand(0, 500) == 1) $this->adapter->optimiseColumns($table); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | private function getAdapter(\PDO $pdo) { |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | //Something has changed, clear any cached results as they may now be incorrect |
| 169 | 169 | $this->resultCache = []; |
| 170 | 170 | $pkValue = $data->{$this->primaryKey[0]}; |
| 171 | - if (isset($this->cache[$pkValue])) $this->cache[$pkValue] = (object) array_merge((array)$this->cache[$pkValue], (array)$data); |
|
| 171 | + if (isset($this->cache[$pkValue])) $this->cache[$pkValue] = (object)array_merge((array)$this->cache[$pkValue], (array)$data); |
|
| 172 | 172 | else $this->cache[$pkValue] = $data; |
| 173 | 173 | } |
| 174 | 174 | |
@@ -2,113 +2,113 @@ |
||
| 2 | 2 | namespace Maphper\DataSource; |
| 3 | 3 | use Maphper\Maphper; |
| 4 | 4 | class Mock implements \Maphper\DataSource { |
| 5 | - private $data; |
|
| 6 | - private $id; |
|
| 5 | + private $data; |
|
| 6 | + private $id; |
|
| 7 | 7 | |
| 8 | - public function __construct(\ArrayObject $data, $id) { |
|
| 9 | - $this->data = $data; |
|
| 10 | - $this->id = is_array($id) ? $id : [$id]; |
|
| 11 | - } |
|
| 8 | + public function __construct(\ArrayObject $data, $id) { |
|
| 9 | + $this->data = $data; |
|
| 10 | + $this->id = is_array($id) ? $id : [$id]; |
|
| 11 | + } |
|
| 12 | 12 | |
| 13 | - public function getPrimaryKey() { |
|
| 14 | - return $this->id; |
|
| 15 | - } |
|
| 13 | + public function getPrimaryKey() { |
|
| 14 | + return $this->id; |
|
| 15 | + } |
|
| 16 | 16 | |
| 17 | - public function findById($id) { |
|
| 18 | - return isset($this->data[$id]) ? (array)$this->data[$id] : []; |
|
| 19 | - } |
|
| 17 | + public function findById($id) { |
|
| 18 | + return isset($this->data[$id]) ? (array)$this->data[$id] : []; |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | - public function findByField(array $fields, $options = []) { |
|
| 22 | - $array = iterator_to_array($this->data->getIterator()); |
|
| 23 | - $filteredArray = array_filter($array, $this->getSearchFieldFunction($fields, \Maphper\Maphper::FIND_EXACT | \Maphper\Maphper::FIND_AND)); |
|
| 24 | - // Need to reset indexes |
|
| 25 | - $filteredArray = array_values($filteredArray); |
|
| 26 | - if (isset($options['order'])) { |
|
| 27 | - list($columns, $order) = explode(' ', $options['order']); |
|
| 28 | - usort($filteredArray, $this->getOrderFunction($order, $columns)); |
|
| 29 | - } |
|
| 30 | - if (isset($options['offset'])) $filteredArray = array_slice($filteredArray, $options['offset']); |
|
| 31 | - if (isset($options['limit'])) $filteredArray = array_slice($filteredArray, 0, $options['limit']); |
|
| 32 | - return $filteredArray; |
|
| 33 | - } |
|
| 21 | + public function findByField(array $fields, $options = []) { |
|
| 22 | + $array = iterator_to_array($this->data->getIterator()); |
|
| 23 | + $filteredArray = array_filter($array, $this->getSearchFieldFunction($fields, \Maphper\Maphper::FIND_EXACT | \Maphper\Maphper::FIND_AND)); |
|
| 24 | + // Need to reset indexes |
|
| 25 | + $filteredArray = array_values($filteredArray); |
|
| 26 | + if (isset($options['order'])) { |
|
| 27 | + list($columns, $order) = explode(' ', $options['order']); |
|
| 28 | + usort($filteredArray, $this->getOrderFunction($order, $columns)); |
|
| 29 | + } |
|
| 30 | + if (isset($options['offset'])) $filteredArray = array_slice($filteredArray, $options['offset']); |
|
| 31 | + if (isset($options['limit'])) $filteredArray = array_slice($filteredArray, 0, $options['limit']); |
|
| 32 | + return $filteredArray; |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - private function getSearchFieldFunction($fields, $mode) { |
|
| 36 | - return function ($data) use ($fields, $mode) { |
|
| 37 | - foreach ($fields as $key => $val) { |
|
| 38 | - $currentFieldResult = $this->getIfFieldMatches($key, $val, $data, $mode); |
|
| 35 | + private function getSearchFieldFunction($fields, $mode) { |
|
| 36 | + return function ($data) use ($fields, $mode) { |
|
| 37 | + foreach ($fields as $key => $val) { |
|
| 38 | + $currentFieldResult = $this->getIfFieldMatches($key, $val, $data, $mode); |
|
| 39 | 39 | |
| 40 | - if (Maphper::FIND_OR & $mode && $currentFieldResult === true) return true; |
|
| 41 | - else if (!(Maphper::FIND_OR & $mode) && $currentFieldResult === false) return false; |
|
| 42 | - } |
|
| 43 | - return !(Maphper::FIND_OR & $mode); |
|
| 44 | - }; |
|
| 45 | - } |
|
| 40 | + if (Maphper::FIND_OR & $mode && $currentFieldResult === true) return true; |
|
| 41 | + else if (!(Maphper::FIND_OR & $mode) && $currentFieldResult === false) return false; |
|
| 42 | + } |
|
| 43 | + return !(Maphper::FIND_OR & $mode); |
|
| 44 | + }; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - private function getIfFieldMatches($key, $val, $data, $mode) { |
|
| 48 | - if (is_numeric($key) && is_array($val)) { |
|
| 49 | - return $this->getSearchFieldFunction($val, $key)($data); |
|
| 50 | - } |
|
| 51 | - else if (!isset($data->$key)) return false; |
|
| 52 | - else if (!(Maphper::FIND_BETWEEN & $mode) && !is_numeric($key) && is_array($val)) |
|
| 53 | - return in_array($data->$key, $val); |
|
| 54 | - else |
|
| 55 | - return $this->processFilter($mode, $val, $data->$key); |
|
| 56 | - } |
|
| 47 | + private function getIfFieldMatches($key, $val, $data, $mode) { |
|
| 48 | + if (is_numeric($key) && is_array($val)) { |
|
| 49 | + return $this->getSearchFieldFunction($val, $key)($data); |
|
| 50 | + } |
|
| 51 | + else if (!isset($data->$key)) return false; |
|
| 52 | + else if (!(Maphper::FIND_BETWEEN & $mode) && !is_numeric($key) && is_array($val)) |
|
| 53 | + return in_array($data->$key, $val); |
|
| 54 | + else |
|
| 55 | + return $this->processFilter($mode, $val, $data->$key); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | 58 | public function findAggregate($function, $field, $group = null, array $criteria = [], array $options = []) { |
| 59 | - $array = iterator_to_array($this->data); |
|
| 60 | - return $function($this->findByField($criteria)); |
|
| 61 | - } |
|
| 59 | + $array = iterator_to_array($this->data); |
|
| 60 | + return $function($this->findByField($criteria)); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | 63 | public function deleteById($id) { |
| 64 | - unset($this->data[$id]); |
|
| 65 | - } |
|
| 64 | + unset($this->data[$id]); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | 67 | public function deleteByField(array $fields) { |
| 68 | - foreach ($this->findByField($fields) as $val) unset($this->data[$val->{$this->id[0]}]); |
|
| 69 | - } |
|
| 68 | + foreach ($this->findByField($fields) as $val) unset($this->data[$val->{$this->id[0]}]); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - public function save($data) { |
|
| 72 | - if (isset($data->{$this->id[0]})) { |
|
| 73 | - $id = $data->{$this->id[0]}; |
|
| 74 | - } |
|
| 75 | - else { |
|
| 76 | - $id = count($this->data); |
|
| 77 | - $data->{$this->id[0]} = $id; |
|
| 78 | - } |
|
| 71 | + public function save($data) { |
|
| 72 | + if (isset($data->{$this->id[0]})) { |
|
| 73 | + $id = $data->{$this->id[0]}; |
|
| 74 | + } |
|
| 75 | + else { |
|
| 76 | + $id = count($this->data); |
|
| 77 | + $data->{$this->id[0]} = $id; |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - $this->data[$id] = (object)array_merge($this->findById($id), (array)$data); |
|
| 81 | - } |
|
| 80 | + $this->data[$id] = (object)array_merge($this->findById($id), (array)$data); |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - public function getErrors() { |
|
| 84 | - return []; |
|
| 85 | - } |
|
| 83 | + public function getErrors() { |
|
| 84 | + return []; |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - private function getOrderFunction($order, $columns) { |
|
| 88 | - return function($a, $b) use ($order, $columns) { |
|
| 89 | - foreach (explode(',', $columns) as $column) { |
|
| 90 | - $aColumn = $a->$column; |
|
| 91 | - $bColumn = $b->$column; |
|
| 92 | - if ($aColumn === $bColumn) { |
|
| 93 | - $sortVal = 0; |
|
| 94 | - continue; |
|
| 95 | - } |
|
| 96 | - else $sortVal = ($aColumn < $bColumn) ? -1 : 1; |
|
| 97 | - break; |
|
| 98 | - } |
|
| 99 | - if ($order === 'desc') return -$sortVal; |
|
| 100 | - else return $sortVal; |
|
| 101 | - }; |
|
| 102 | - } |
|
| 87 | + private function getOrderFunction($order, $columns) { |
|
| 88 | + return function($a, $b) use ($order, $columns) { |
|
| 89 | + foreach (explode(',', $columns) as $column) { |
|
| 90 | + $aColumn = $a->$column; |
|
| 91 | + $bColumn = $b->$column; |
|
| 92 | + if ($aColumn === $bColumn) { |
|
| 93 | + $sortVal = 0; |
|
| 94 | + continue; |
|
| 95 | + } |
|
| 96 | + else $sortVal = ($aColumn < $bColumn) ? -1 : 1; |
|
| 97 | + break; |
|
| 98 | + } |
|
| 99 | + if ($order === 'desc') return -$sortVal; |
|
| 100 | + else return $sortVal; |
|
| 101 | + }; |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - private function processFilter($mode, $expected, $actual) { |
|
| 105 | - if (Maphper::FIND_NOT & $mode) return $expected != $actual; |
|
| 106 | - else if (Maphper::FIND_GREATER & $mode && Maphper::FIND_EXACT & $mode) return $expected <= $actual; |
|
| 107 | - else if (Maphper::FIND_LESS & $mode && Maphper::FIND_EXACT & $mode) return $expected >= $actual; |
|
| 108 | - else if (Maphper::FIND_GREATER & $mode) return $expected < $actual; |
|
| 109 | - else if (Maphper::FIND_LESS & $mode) return $expected > $actual; |
|
| 110 | - else if (Maphper::FIND_BETWEEN & $mode) return $expected[0] <= $actual && $actual <= $expected[1]; |
|
| 111 | - else if (Maphper::FIND_NOCASE & $mode) return strtolower($expected) == strtolower($actual); |
|
| 112 | - return $expected == $actual; |
|
| 113 | - } |
|
| 104 | + private function processFilter($mode, $expected, $actual) { |
|
| 105 | + if (Maphper::FIND_NOT & $mode) return $expected != $actual; |
|
| 106 | + else if (Maphper::FIND_GREATER & $mode && Maphper::FIND_EXACT & $mode) return $expected <= $actual; |
|
| 107 | + else if (Maphper::FIND_LESS & $mode && Maphper::FIND_EXACT & $mode) return $expected >= $actual; |
|
| 108 | + else if (Maphper::FIND_GREATER & $mode) return $expected < $actual; |
|
| 109 | + else if (Maphper::FIND_LESS & $mode) return $expected > $actual; |
|
| 110 | + else if (Maphper::FIND_BETWEEN & $mode) return $expected[0] <= $actual && $actual <= $expected[1]; |
|
| 111 | + else if (Maphper::FIND_NOCASE & $mode) return strtolower($expected) == strtolower($actual); |
|
| 112 | + return $expected == $actual; |
|
| 113 | + } |
|
| 114 | 114 | } |
@@ -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 | |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | |
| 24 | 24 | $args = $query->getArgs(); |
| 25 | 25 | foreach ($args as &$arg) if ($arg instanceof \DateTime) { |
| 26 | - if ($arg->format('H:i:s') == '00:00:00') $arg = $arg->format('Y-m-d'); |
|
| 26 | + if ($arg->format('H:i:s') == '00:00:00') $arg = $arg->format('Y-m-d'); |
|
| 27 | 27 | else $arg = $arg->format('Y-m-d H:i:s'); |
| 28 | 28 | } |
| 29 | 29 | |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | private function tableExists($name) { |
| 66 | - $result = $this->pdo->query('SELECT name FROM sqlite_master WHERE type="table" and name="'. $name.'"'); |
|
| 66 | + $result = $this->pdo->query('SELECT name FROM sqlite_master WHERE type="table" and name="' . $name . '"'); |
|
| 67 | 67 | return count($result->fetchAll()) == 1; |
| 68 | 68 | } |
| 69 | 69 | |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | // SQLSTATE[HY000]: General error: 17 database schema has changed |
| 83 | 83 | $this->queryCache = []; |
| 84 | 84 | |
| 85 | - $affix = '_'.substr(md5($table), 0, 6); |
|
| 85 | + $affix = '_' . substr(md5($table), 0, 6); |
|
| 86 | 86 | $this->createTable($table . $affix, $primaryKey, $data); |
| 87 | 87 | $fields = []; |
| 88 | 88 | foreach ($data as $key => $value) { $fields[] = $key; } |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | $columns = implode(', ', $this->getColumns($table)); |
| 92 | 92 | |
| 93 | 93 | $this->pdo->query('INSERT INTO ' . $this->quote($table . $affix) . '(' . $columns . ') SELECT ' . $columns . ' FROM ' . $this->quote($table)); |
| 94 | - $this->pdo->query('DROP TABLE IF EXISTS ' . $table ); |
|
| 94 | + $this->pdo->query('DROP TABLE IF EXISTS ' . $table); |
|
| 95 | 95 | } |
| 96 | 96 | } |
| 97 | 97 | catch (\PDOException $e) { |
@@ -99,8 +99,8 @@ discard block |
||
| 99 | 99 | echo $e->getMessage(); |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - $this->pdo->query('DROP TABLE IF EXISTS ' . $table ); |
|
| 103 | - $this->pdo->query('ALTER TABLE ' . $table . $affix. ' RENAME TO '. $table ); |
|
| 102 | + $this->pdo->query('DROP TABLE IF EXISTS ' . $table); |
|
| 103 | + $this->pdo->query('ALTER TABLE ' . $table . $affix . ' RENAME TO ' . $table); |
|
| 104 | 104 | |
| 105 | 105 | } |
| 106 | 106 | |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | |
| 115 | 115 | $pkField = implode(', ', $parts) . ', PRIMARY KEY(' . implode(', ', $primaryKey) . ')'; |
| 116 | 116 | |
| 117 | - $this->pdo->query('DROP TABLE IF EXISTS ' . $table ); |
|
| 117 | + $this->pdo->query('DROP TABLE IF EXISTS ' . $table); |
|
| 118 | 118 | $this->pdo->query('CREATE TABLE ' . $table . ' (' . $pkField . ')'); |
| 119 | 119 | |
| 120 | 120 | foreach ($data as $key => $value) { |
@@ -80,17 +80,17 @@ |
||
| 80 | 80 | return ['args' => $args, 'sql' => [$query]]; |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - private function getOperator($mode) { |
|
| 84 | - $operator = ""; |
|
| 83 | + private function getOperator($mode) { |
|
| 84 | + $operator = ""; |
|
| 85 | 85 | |
| 86 | - if (\Maphper\Maphper::FIND_NOCASE & $mode) $operator = 'LIKE'; |
|
| 87 | - else if (\Maphper\Maphper::FIND_BIT & $mode) $operator = '&'; |
|
| 88 | - else if (\Maphper\Maphper::FIND_GREATER & $mode) $operator = '>'; |
|
| 89 | - else if (\Maphper\Maphper::FIND_LESS & $mode) $operator = '<'; |
|
| 90 | - else if (\Maphper\Maphper::FIND_NOT & $mode) $operator = '!='; |
|
| 86 | + if (\Maphper\Maphper::FIND_NOCASE & $mode) $operator = 'LIKE'; |
|
| 87 | + else if (\Maphper\Maphper::FIND_BIT & $mode) $operator = '&'; |
|
| 88 | + else if (\Maphper\Maphper::FIND_GREATER & $mode) $operator = '>'; |
|
| 89 | + else if (\Maphper\Maphper::FIND_LESS & $mode) $operator = '<'; |
|
| 90 | + else if (\Maphper\Maphper::FIND_NOT & $mode) $operator = '!='; |
|
| 91 | 91 | |
| 92 | - if (\Maphper\Maphper::FIND_EXACT & $mode) $operator .= '='; |
|
| 92 | + if (\Maphper\Maphper::FIND_EXACT & $mode) $operator .= '='; |
|
| 93 | 93 | |
| 94 | - return $operator; |
|
| 95 | - } |
|
| 94 | + return $operator; |
|
| 95 | + } |
|
| 96 | 96 | } |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | |
| 26 | 26 | |
| 27 | 27 | //Needs to be broken up into better methods |
| 28 | - public function createSql($fields, $mode){ |
|
| 28 | + public function createSql($fields, $mode) { |
|
| 29 | 29 | $args = []; |
| 30 | 30 | $sql = []; |
| 31 | 31 | |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | $inSql[] = ':' . $key . $i; |
| 51 | 51 | } |
| 52 | 52 | if (count($inSql) == 0) return []; |
| 53 | - else $sql[] = $key . ' IN ( ' . implode(', ', $inSql) . ')'; |
|
| 53 | + else $sql[] = $key . ' IN ( ' . implode(', ', $inSql) . ')'; |
|
| 54 | 54 | } |
| 55 | 55 | else if ($value === NULL) { |
| 56 | 56 | $nullSql = $key . ' IS '; |
@@ -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 | |
@@ -74,7 +74,7 @@ |
||
| 74 | 74 | |
| 75 | 75 | public function __get($name) { |
| 76 | 76 | if ($this->lazyLoad()) return $this->lazyLoad()->$name; |
| 77 | - else return null; |
|
| 77 | + else return null; |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | public function __isset($name) { |
@@ -7,17 +7,17 @@ |
||
| 7 | 7 | private $intermediateName; |
| 8 | 8 | |
| 9 | 9 | public function __construct(\Maphper\Iterator $iterator, $intermediateName = null) { |
| 10 | - $this->iterator = $iterator; |
|
| 11 | - $this->intermediateName = $intermediateName; |
|
| 10 | + $this->iterator = $iterator; |
|
| 11 | + $this->intermediateName = $intermediateName; |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | public function current() { |
| 15 | - if ($this->intermediateName) return $this->iterator->current()->{$this->intermediateName}; |
|
| 15 | + if ($this->intermediateName) return $this->iterator->current()->{$this->intermediateName}; |
|
| 16 | 16 | return $this->iterator->current(); |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | public function key() { |
| 20 | - return $this->iterator->key(); |
|
| 20 | + return $this->iterator->key(); |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | public function next() { |