@@ -190,6 +190,10 @@ |
||
| 190 | 190 | return $return; |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | + /** |
|
| 194 | + * @param integer $level |
|
| 195 | + * @param string $opr |
|
| 196 | + */ |
|
| 193 | 197 | private function parseRightExpression($level, $opr) { |
| 194 | 198 | switch ($opr) { |
| 195 | 199 | case 'between': return $this->parseBetween(); |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | $this->getToken(); |
| 58 | 58 | $expression = $this->parseExpression(); |
| 59 | 59 | if ($this->token !== false) { |
| 60 | - throw new FilterCompilerException("Unexpected '" . $this->token . "' in filter [$filter]"); |
|
| 60 | + throw new FilterCompilerException("Unexpected '".$this->token."' in filter [$filter]"); |
|
| 61 | 61 | } |
| 62 | 62 | $parsed = $this->renderExpression($expression); |
| 63 | 63 | return $parsed; |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | |
| 66 | 66 | private function renderExpression($expression) { |
| 67 | 67 | if (is_array($expression)) { |
| 68 | - $expression = $this->renderExpression($expression['left']) . " {$expression['opr']} " . $this->renderExpression($expression['right']); |
|
| 68 | + $expression = $this->renderExpression($expression['left'])." {$expression['opr']} ".$this->renderExpression($expression['right']); |
|
| 69 | 69 | } |
| 70 | 70 | return $expression; |
| 71 | 71 | } |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | $tokens = [$tokens]; |
| 76 | 76 | } |
| 77 | 77 | if (array_search($this->lookahead, $tokens) === false) { |
| 78 | - throw new FilterCompilerException("Expected " . implode(' or ', $tokens) . " but found " . $this->lookahead); |
|
| 78 | + throw new FilterCompilerException("Expected ".implode(' or ', $tokens)." but found ".$this->lookahead); |
|
| 79 | 79 | } |
| 80 | 80 | } |
| 81 | 81 | |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | private function returnPositionTag() { |
| 163 | - return ":filter_bind_" . ( ++$this->numPositions); |
|
| 163 | + return ":filter_bind_".( ++$this->numPositions); |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | private function parseObracket() { |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | if ($this->token === false && strlen($this->filter) > 0) { |
| 240 | - throw new FilterCompilerException("Unexpected character [" . $this->filter[0] . "] begining " . $this->filter . "."); |
|
| 240 | + throw new FilterCompilerException("Unexpected character [".$this->filter[0]."] begining ".$this->filter."."); |
|
| 241 | 241 | } |
| 242 | 242 | } |
| 243 | 243 | |
@@ -251,7 +251,7 @@ discard block |
||
| 251 | 251 | $rewritten = []; |
| 252 | 252 | foreach ($data as $key => $value) { |
| 253 | 253 | if (is_numeric($key)) { |
| 254 | - $rewritten["filter_bind_" . ($key + 1)] = $value; |
|
| 254 | + $rewritten["filter_bind_".($key + 1)] = $value; |
|
| 255 | 255 | } else { |
| 256 | 256 | $rewritten[$key] = $value; |
| 257 | 257 | } |
@@ -90,6 +90,9 @@ |
||
| 90 | 90 | return $relationshipDetails; |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | + /** |
|
| 94 | + * @param string $type |
|
| 95 | + */ |
|
| 93 | 96 | private function createRelationships($type, $relationships) { |
| 94 | 97 | foreach ($relationships as $relationship) { |
| 95 | 98 | $relationship = $this->getRelationshipDetails($relationship); |
@@ -2,8 +2,6 @@ |
||
| 2 | 2 | |
| 3 | 3 | namespace ntentan\nibii; |
| 4 | 4 | |
| 5 | -use ntentan\atiaa\Db; |
|
| 6 | - |
|
| 7 | 5 | class ModelDescription { |
| 8 | 6 | |
| 9 | 7 | private $fields = []; |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | |
| 123 | 123 | /** |
| 124 | 124 | * @method |
| 125 | - * @param type $name |
|
| 125 | + * @param string $name |
|
| 126 | 126 | * @param type $arguments |
| 127 | 127 | * @return type |
| 128 | 128 | */ |
@@ -148,6 +148,10 @@ discard block |
||
| 148 | 148 | return $this->retrieveItem($name); |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | + /** |
|
| 152 | + * @param Relationship[] $relationships |
|
| 153 | + * @param integer $depth |
|
| 154 | + */ |
|
| 151 | 155 | private function expandArrayValue($array, $relationships, $depth, $index = null) { |
| 152 | 156 | foreach ($relationships as $name => $relationship) { |
| 153 | 157 | $array[$name] = $this->fetchRelatedFields($relationship, $index)->toArray($depth); |
@@ -26,9 +26,7 @@ |
||
| 26 | 26 | |
| 27 | 27 | namespace ntentan\nibii; |
| 28 | 28 | |
| 29 | -use ntentan\kaikai\Cache; |
|
| 30 | 29 | use ntentan\utils\Text; |
| 31 | -use ntentan\atiaa\Db; |
|
| 32 | 30 | |
| 33 | 31 | /** |
| 34 | 32 | * |
@@ -64,8 +64,8 @@ discard block |
||
| 64 | 64 | $this->quotedTable = $driver->quoteIdentifier($table); |
| 65 | 65 | $this->table = $this->unquotedTable = $table; |
| 66 | 66 | } else { |
| 67 | - $this->quotedTable = ( isset($table['schema']) ? "{$driver->quoteIdentifier($table["schema"])}." : "") . $driver->quoteIdentifier($table["table"]); |
|
| 68 | - $this->unquotedTable = (isset($table['schema']) ? "{$table['schema']}." : "") . $table['table']; |
|
| 67 | + $this->quotedTable = (isset($table['schema']) ? "{$driver->quoteIdentifier($table["schema"])}." : "").$driver->quoteIdentifier($table["table"]); |
|
| 68 | + $this->unquotedTable = (isset($table['schema']) ? "{$table['schema']}." : "").$table['table']; |
|
| 69 | 69 | $this->table = $table['table']; |
| 70 | 70 | $this->schema = $table['schema']; |
| 71 | 71 | } |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | */ |
| 84 | 84 | public function getDescription() { |
| 85 | 85 | return $this->context->getCache()->read( |
| 86 | - (new \ReflectionClass($this))->getName() . '::desc', function() { |
|
| 86 | + (new \ReflectionClass($this))->getName().'::desc', function() { |
|
| 87 | 87 | return $this->container->resolve(ModelDescription::class, ['model' => $this]); |
| 88 | 88 | } |
| 89 | 89 | ); |
@@ -34,8 +34,8 @@ discard block |
||
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | return $this->filter( |
| 37 | - "INSERT INTO " . $table . |
|
| 38 | - " (" . implode(", ", $quotedFields) . ") VALUES (" . implode(', ', $valueFields) . ")" |
|
| 37 | + "INSERT INTO ".$table. |
|
| 38 | + " (".implode(", ", $quotedFields).") VALUES (".implode(', ', $valueFields).")" |
|
| 39 | 39 | ); |
| 40 | 40 | } |
| 41 | 41 | |
@@ -77,10 +77,10 @@ discard block |
||
| 77 | 77 | } |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - return $this->filter("UPDATE " . |
|
| 81 | - $model->getDBStoreInformation()['quoted_table'] . |
|
| 82 | - " SET " . implode(', ', $valueFields) . |
|
| 83 | - " WHERE " . implode(' AND ', $conditions) |
|
| 80 | + return $this->filter("UPDATE ". |
|
| 81 | + $model->getDBStoreInformation()['quoted_table']. |
|
| 82 | + " SET ".implode(', ', $valueFields). |
|
| 83 | + " WHERE ".implode(' AND ', $conditions) |
|
| 84 | 84 | ); |
| 85 | 85 | } |
| 86 | 86 | |
@@ -10,6 +10,9 @@ |
||
| 10 | 10 | $this->db = $driver; |
| 11 | 11 | } |
| 12 | 12 | |
| 13 | + /** |
|
| 14 | + * @param string $query |
|
| 15 | + */ |
|
| 13 | 16 | private function filter($query) { |
| 14 | 17 | return $query; |
| 15 | 18 | } |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | public function getSorts() { |
| 73 | - return count($this->sorts) ? " ORDER BY " . implode(", ", $this->sorts) : null; |
|
| 73 | + return count($this->sorts) ? " ORDER BY ".implode(", ", $this->sorts) : null; |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | public function addFilter($field, $values = []) { |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | $this->whereClause .= "{$field} IN ("; |
| 91 | 91 | $comma = ''; |
| 92 | 92 | for ($i = 0; $i < $numValues; $i++) { |
| 93 | - $key = "filter_" . ($startIndex + $i); |
|
| 93 | + $key = "filter_".($startIndex + $i); |
|
| 94 | 94 | $this->whereClause .= "$comma:$key"; |
| 95 | 95 | $this->boundData[$key] = $values[$i]; |
| 96 | 96 | $comma = ' ,'; |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | /** |
| 24 | 24 | * |
| 25 | - * @param \ $model |
|
| 25 | + * @param string $table |
|
| 26 | 26 | */ |
| 27 | 27 | public function __construct($table) { |
| 28 | 28 | $this->table = $table; |
@@ -104,6 +104,9 @@ discard block |
||
| 104 | 104 | $this->boundData += $values; |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | + /** |
|
| 108 | + * @param boolean $firstOnly |
|
| 109 | + */ |
|
| 107 | 110 | public function setFirstOnly($firstOnly) { |
| 108 | 111 | $this->firstOnly = $firstOnly; |
| 109 | 112 | return $this; |
@@ -121,6 +124,9 @@ discard block |
||
| 121 | 124 | $this->offset = $offset; |
| 122 | 125 | } |
| 123 | 126 | |
| 127 | + /** |
|
| 128 | + * @param string $field |
|
| 129 | + */ |
|
| 124 | 130 | public function addSort($field, $direction = 'ASC') { |
| 125 | 131 | $this->sorts[] = "$field $direction"; |
| 126 | 132 | } |
@@ -70,11 +70,11 @@ |
||
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | if (!isset($this->options['junction_local_key'])) { |
| 73 | - $this->options['junction_local_key'] = Text::singularize($this->setupTable) . '_id'; |
|
| 73 | + $this->options['junction_local_key'] = Text::singularize($this->setupTable).'_id'; |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | if (!isset($this->options['junction_foreign_key'])) { |
| 77 | - $this->options['junction_foreign_key'] = Text::singularize($foreignModel->getDBStoreInformation()['table']) . '_id'; |
|
| 77 | + $this->options['junction_foreign_key'] = Text::singularize($foreignModel->getDBStoreInformation()['table']).'_id'; |
|
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | 80 | |
@@ -67,7 +67,7 @@ |
||
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | public static function getInstance() { |
| 70 | - if(self::$instance === null) throw new NibiiException("A context has not yet been initialized"); |
|
| 70 | + if (self::$instance === null) throw new NibiiException("A context has not yet been initialized"); |
|
| 71 | 71 | return self::$instance; |
| 72 | 72 | } |
| 73 | 73 | |
@@ -67,7 +67,9 @@ |
||
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | public static function getInstance() { |
| 70 | - if(self::$instance === null) throw new NibiiException("A context has not yet been initialized"); |
|
| 70 | + if(self::$instance === null) { |
|
| 71 | + throw new NibiiException("A context has not yet been initialized"); |
|
| 72 | + } |
|
| 71 | 73 | return self::$instance; |
| 72 | 74 | } |
| 73 | 75 | |
@@ -56,6 +56,9 @@ discard block |
||
| 56 | 56 | ->getJunctionClassName($classA, $classB); |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | + /** |
|
| 60 | + * @param RecordWrapper $instance |
|
| 61 | + */ |
|
| 59 | 62 | public function getModelTable($instance) { |
| 60 | 63 | return$this->container->singleton(interfaces\TableNameResolverInterface::class) |
| 61 | 64 | ->getTableName($instance); |
@@ -66,6 +69,9 @@ discard block |
||
| 66 | 69 | ->getModelClassName($model, $context); |
| 67 | 70 | } |
| 68 | 71 | |
| 72 | + /** |
|
| 73 | + * @param string $class |
|
| 74 | + */ |
|
| 69 | 75 | public function getModelName($class) { |
| 70 | 76 | return $class; |
| 71 | 77 | } |
@@ -2,9 +2,9 @@ |
||
| 2 | 2 | |
| 3 | 3 | namespace ntentan\nibii; |
| 4 | 4 | |
| 5 | -use ntentan\panie\Container; |
|
| 6 | -use ntentan\kaikai\Cache; |
|
| 7 | 5 | use ntentan\atiaa\DbContext; |
| 6 | +use ntentan\kaikai\Cache; |
|
| 7 | +use ntentan\panie\Container; |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * A collection of utility methods used as helpers for loading |
@@ -21,11 +21,11 @@ |
||
| 21 | 21 | $this->container = $container; |
| 22 | 22 | $this->dbContext = $container->resolve(DbContext::class); |
| 23 | 23 | $this->container->bind(interfaces\ModelJoinerInterface::class) |
| 24 | - ->to(Resolver::class); |
|
| 24 | + ->to(Resolver::class); |
|
| 25 | 25 | $this->container->bind(interfaces\TableNameResolverInterface::class) |
| 26 | - ->to(Resolver::class); |
|
| 26 | + ->to(Resolver::class); |
|
| 27 | 27 | $this->container->bind(interfaces\ModelClassResolverInterface::class) |
| 28 | - ->to(Resolver::class); |
|
| 28 | + ->to(Resolver::class); |
|
| 29 | 29 | $this->cache = $this->container->resolve(Cache::class); |
| 30 | 30 | self::$instance = $this; |
| 31 | 31 | } |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | /** |
| 42 | 42 | * |
| 43 | 43 | * |
| 44 | - * @param type $parameters |
|
| 44 | + * @param QueryParameters $parameters |
|
| 45 | 45 | * @return type |
| 46 | 46 | */ |
| 47 | 47 | public function select($parameters) { |
@@ -57,6 +57,9 @@ discard block |
||
| 57 | 57 | return $result; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | + /** |
|
| 61 | + * @param QueryParameters $parameters |
|
| 62 | + */ |
|
| 60 | 63 | public function count($parameters) { |
| 61 | 64 | $result = $this->driver->query( |
| 62 | 65 | $this->getQueryEngine()->getCountQuery($parameters), $parameters->getBoundData() |
@@ -87,12 +90,18 @@ discard block |
||
| 87 | 90 | return $this->driver->query($this->updateQuery, $record); |
| 88 | 91 | } |
| 89 | 92 | |
| 93 | + /** |
|
| 94 | + * @param QueryParameters $parameters |
|
| 95 | + */ |
|
| 90 | 96 | public function bulkUpdate($data, $parameters) { |
| 91 | 97 | return $this->driver->query( |
| 92 | 98 | $this->getQueryEngine()->getBulkUpdateQuery($data, $parameters), array_merge($data, $parameters->getBoundData()) |
| 93 | 99 | ); |
| 94 | 100 | } |
| 95 | 101 | |
| 102 | + /** |
|
| 103 | + * @param QueryParameters $parameters |
|
| 104 | + */ |
|
| 96 | 105 | public function delete($parameters) { |
| 97 | 106 | return $this->driver->query( |
| 98 | 107 | $this->getQueryEngine()->getDeleteQuery($parameters), $parameters->getBoundData() |
@@ -119,6 +128,9 @@ discard block |
||
| 119 | 128 | return $this->queryEngine; |
| 120 | 129 | } |
| 121 | 130 | |
| 131 | + /** |
|
| 132 | + * @param RecordWrapper $model |
|
| 133 | + */ |
|
| 122 | 134 | public function setModel($model) { |
| 123 | 135 | $this->modelInstance = $model; |
| 124 | 136 | } |
@@ -2,9 +2,6 @@ |
||
| 2 | 2 | |
| 3 | 3 | namespace ntentan\nibii; |
| 4 | 4 | |
| 5 | -use ntentan\utils\Text; |
|
| 6 | -use ntentan\atiaa\Db; |
|
| 7 | - |
|
| 8 | 5 | /** |
| 9 | 6 | * A DriverAdaptr is a generic database adapter. |
| 10 | 7 | * This adapter implements a lot of its operations through the atiaa library. |
@@ -51,7 +51,7 @@ |
||
| 51 | 51 | /** |
| 52 | 52 | * |
| 53 | 53 | * @param RecordWrapper $wrapper |
| 54 | - * @param DataAdapter $adapter |
|
| 54 | + * @param DriverAdapter $adapter |
|
| 55 | 55 | * @param DataOperations $dataOperations |
| 56 | 56 | */ |
| 57 | 57 | public function __construct(Context $context, RecordWrapper $wrapper, DriverAdapter $adapter, $dataOperations) { |
@@ -27,8 +27,6 @@ |
||
| 27 | 27 | namespace ntentan\nibii; |
| 28 | 28 | |
| 29 | 29 | use ntentan\utils\Text; |
| 30 | -use ntentan\atiaa\Db; |
|
| 31 | -use ntentan\panie\Container; |
|
| 32 | 30 | |
| 33 | 31 | class QueryOperations { |
| 34 | 32 | |