@@ -88,25 +88,25 @@ |
||
| 88 | 88 | list($relatedField, $valueField, $mapper) = $this->getOtherFieldNameInfo(); |
| 89 | 89 | if ($this->autoTraverse) $this->offsetSetAutotraverse($value, $relatedField, $valueField); |
| 90 | 90 | else if ($this->doUpdateInterMapper($value, $relatedField, $valueField)) { |
| 91 | - $record = $value; |
|
| 91 | + $record = $value; |
|
| 92 | 92 | $record->{$this->parentField} = $value->{$this->intermediateName}->{$this->localField}; |
| 93 | 93 | $record->$valueField = $this->object->{$relatedField}; |
| 94 | 94 | $this->intermediateMapper[] = $record; |
| 95 | 95 | } |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - private function doUpdateInterMapper($record, $relatedField, $valueField) { |
|
| 99 | - return !(isset($record->{$this->parentField}) && isset($record->{$this->intermediateName}) && |
|
| 100 | - $record->{$this->parentField} == $record->{$this->intermediateName}->{$this->localField} && |
|
| 101 | - $record->$valueField == $this->object->{$relatedField}); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - private function offsetSetAutotraverse($value, $relatedField, $valueField) { |
|
| 105 | - $record = new \stdClass; |
|
| 106 | - $record->{$this->parentField} = $value->{$this->localField}; |
|
| 107 | - $record->$valueField = $this->object->{$relatedField}; |
|
| 108 | - $this->intermediateMapper[] = $record; |
|
| 109 | - } |
|
| 98 | + private function doUpdateInterMapper($record, $relatedField, $valueField) { |
|
| 99 | + return !(isset($record->{$this->parentField}) && isset($record->{$this->intermediateName}) && |
|
| 100 | + $record->{$this->parentField} == $record->{$this->intermediateName}->{$this->localField} && |
|
| 101 | + $record->$valueField == $this->object->{$relatedField}); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + private function offsetSetAutotraverse($value, $relatedField, $valueField) { |
|
| 105 | + $record = new \stdClass; |
|
| 106 | + $record->{$this->parentField} = $value->{$this->localField}; |
|
| 107 | + $record->$valueField = $this->object->{$relatedField}; |
|
| 108 | + $this->intermediateMapper[] = $record; |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | 111 | public function offsetUnset($id) { |
| 112 | 112 | //$this->relation->mapper->filter([$relatedField => $this->object->$valueField, $this->relation->parentField => $id])->delete(); |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | private $siblings = []; |
| 10 | 10 | |
| 11 | 11 | public function __construct(\Maphper\Maphper $mapper, $parentField, $localField, array $criteria = []) { |
| 12 | - if ($criteria) $mapper = $mapper->filter($this->criteira); |
|
| 12 | + if ($criteria) $mapper = $mapper->filter($this->criteira); |
|
| 13 | 13 | $this->mapper = $mapper; |
| 14 | 14 | $this->parentField = $parentField; |
| 15 | 15 | $this->localField = $localField; |
@@ -48,11 +48,11 @@ discard block |
||
| 48 | 48 | //Fetch the results so they're in the cache for the corresponding maphper object |
| 49 | 49 | $results = $this->mapper->filter([$this->localField => $recordsToLoad]); |
| 50 | 50 | |
| 51 | - $this->loadDataIntoSiblings($results); |
|
| 51 | + $this->loadDataIntoSiblings($results); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - private function loadDataIntoSiblings($results) { |
|
| 55 | - $cache = []; |
|
| 54 | + private function loadDataIntoSiblings($results) { |
|
| 55 | + $cache = []; |
|
| 56 | 56 | foreach ($results as $result) { |
| 57 | 57 | $cache[$result->{$this->localField}] = $result; |
| 58 | 58 | } |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | else $sibling->data = $sibling->mapper->filter([$sibling->localField => $sibling->parentObject->{$this->parentField}])->item(0); |
| 67 | 67 | } |
| 68 | 68 | */ |
| 69 | - } |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | 71 | public function __call($func, array $args = []) { |
| 72 | 72 | if ($this->lazyLoad() == null) return ''; |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | |
| 76 | 76 | public function __get($name) { |
| 77 | 77 | if ($this->lazyLoad()) return $this->lazyLoad()->$name; |
| 78 | - else return null; |
|
| 78 | + else return null; |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | public function __isset($name) { |
@@ -3,14 +3,14 @@ discard block |
||
| 3 | 3 | class MysqlAdapter implements DatabaseAdapter { |
| 4 | 4 | private $pdo; |
| 5 | 5 | private $stmtCache; |
| 6 | - private $generalEditor; |
|
| 6 | + private $generalEditor; |
|
| 7 | 7 | |
| 8 | 8 | public function __construct(\PDO $pdo) { |
| 9 | 9 | $this->pdo = $pdo; |
| 10 | 10 | //Set to strict mode to detect 'out of range' errors, action at a distance but it needs to be set for all INSERT queries |
| 11 | 11 | $this->pdo->query('SET sql_mode = STRICT_ALL_TABLES'); |
| 12 | - $this->stmtCache = new StmtCache($pdo); |
|
| 13 | - $this->generalEditor = new GeneralEditDatabase($this->pdo, ['short_string_max_len' => 191]); |
|
| 12 | + $this->stmtCache = new StmtCache($pdo); |
|
| 13 | + $this->generalEditor = new GeneralEditDatabase($this->pdo, ['short_string_max_len' => 191]); |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | public function quote($str) { |
@@ -20,32 +20,32 @@ discard block |
||
| 20 | 20 | public function query(\Maphper\Lib\Query $query) { |
| 21 | 21 | $stmt = $this->stmtCache->getCachedStmt($query->getSql()); |
| 22 | 22 | $args = $query->getArgs(); |
| 23 | - $stmt->execute($args); |
|
| 23 | + $stmt->execute($args); |
|
| 24 | 24 | |
| 25 | 25 | return $stmt; |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | - private function alterColumns($table, array $primaryKey, $data) { |
|
| 29 | - foreach ($data as $key => $value) { |
|
| 28 | + private function alterColumns($table, array $primaryKey, $data) { |
|
| 29 | + foreach ($data as $key => $value) { |
|
| 30 | 30 | if ($this->generalEditor->isNotSavableType($value, $key, $primaryKey)) continue; |
| 31 | 31 | |
| 32 | 32 | $type = $this->generalEditor->getType($value); |
| 33 | 33 | $this->tryAlteringColumn($table, $key, $type); |
| 34 | 34 | } |
| 35 | - } |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - private function tryAlteringColumn($table, $key, $type) { |
|
| 38 | - try { |
|
| 39 | - if (!$this->pdo->query('ALTER TABLE ' . $table . ' ADD ' . $this->quote($key) . ' ' . $type)) throw new \Exception('Could not alter table'); |
|
| 40 | - } |
|
| 41 | - catch (\Exception $e) { |
|
| 42 | - $this->pdo->query('ALTER TABLE ' . $table . ' MODIFY ' . $this->quote($key) . ' ' . $type); |
|
| 43 | - } |
|
| 44 | - } |
|
| 37 | + private function tryAlteringColumn($table, $key, $type) { |
|
| 38 | + try { |
|
| 39 | + if (!$this->pdo->query('ALTER TABLE ' . $table . ' ADD ' . $this->quote($key) . ' ' . $type)) throw new \Exception('Could not alter table'); |
|
| 40 | + } |
|
| 41 | + catch (\Exception $e) { |
|
| 42 | + $this->pdo->query('ALTER TABLE ' . $table . ' MODIFY ' . $this->quote($key) . ' ' . $type); |
|
| 43 | + } |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | 46 | public function alterDatabase($table, array $primaryKey, $data) { |
| 47 | 47 | $this->generalEditor->createTable($table, $primaryKey, $data); |
| 48 | - $this->alterColumns($table, $primaryKey, $data); |
|
| 48 | + $this->alterColumns($table, $primaryKey, $data); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | public function lastInsertId() { |