@@ -301,6 +301,9 @@ |
||
| 301 | 301 | { |
| 302 | 302 | private $refresher; |
| 303 | 303 | |
| 304 | + /** |
|
| 305 | + * @param \Closure $refresher |
|
| 306 | + */ |
|
| 304 | 307 | public function __construct($refresher) |
| 305 | 308 | { |
| 306 | 309 | $this->refresher = $refresher; |
@@ -293,7 +293,7 @@ |
||
| 293 | 293 | { |
| 294 | 294 | if ($this->effectiveSearchPathCache === null) { |
| 295 | 295 | $this->initEffectiveSearchPathCache(); |
| 296 | - $refresher = function () { |
|
| 296 | + $refresher = function() { |
|
| 297 | 297 | $this->initEffectiveSearchPathCache(); |
| 298 | 298 | }; |
| 299 | 299 | $this->addObserver( |
@@ -118,8 +118,7 @@ discard block |
||
| 118 | 118 | } |
| 119 | 119 | if ($res !== false) { |
| 120 | 120 | return pg_fetch_result($res, 0, 0); |
| 121 | - } |
|
| 122 | - else { |
|
| 121 | + } else { |
|
| 123 | 122 | return null; |
| 124 | 123 | } |
| 125 | 124 | } |
@@ -156,8 +155,7 @@ discard block |
||
| 156 | 155 | // try exact match first, for performance reasons; hopefully, indexing the type map will not be needed |
| 157 | 156 | if (array_key_exists($propertyName, ConfigParam::TYPEMAP)) { |
| 158 | 157 | $type = ConfigParam::TYPEMAP[$propertyName]; |
| 159 | - } |
|
| 160 | - else { |
|
| 158 | + } else { |
|
| 161 | 159 | // okay, try to search for case-insensitive matches |
| 162 | 160 | if ($this->typeCache === null) { |
| 163 | 161 | $this->typeCache = array_change_key_case(ConfigParam::TYPEMAP, CASE_LOWER); |
@@ -180,8 +178,7 @@ discard block |
||
| 180 | 178 | $this->typeCache[$propertyName] = $type; |
| 181 | 179 | $this->typeCache[strtolower($propertyName)] = $type; |
| 182 | 180 | return ConfigParamType::createValue($type, $row['setting'], $row['unit']); |
| 183 | - } |
|
| 184 | - catch (UnsupportedException $e) { |
|
| 181 | + } catch (UnsupportedException $e) { |
|
| 185 | 182 | throw new UnsupportedException("Unsupported type of configuration parameter '$propertyName'"); |
| 186 | 183 | } |
| 187 | 184 | } |
@@ -199,8 +196,7 @@ discard block |
||
| 199 | 196 | if ($res !== false) { |
| 200 | 197 | $val = pg_fetch_result($res, 0, 0); |
| 201 | 198 | return ConfigParamType::createValue($type, $val); |
| 202 | - } |
|
| 203 | - else { |
|
| 199 | + } else { |
|
| 204 | 200 | return null; |
| 205 | 201 | } |
| 206 | 202 | } |
@@ -342,8 +338,7 @@ discard block |
||
| 342 | 338 | $v = $r->value(); |
| 343 | 339 | if (preg_match('~1(\D*)2~', $v, $m)) { |
| 344 | 340 | return $m[1]; |
| 345 | - } |
|
| 346 | - else { |
|
| 341 | + } else { |
|
| 347 | 342 | return null; |
| 348 | 343 | } |
| 349 | 344 | } |
@@ -357,8 +352,7 @@ discard block |
||
| 357 | 352 | foreach ($parameterName as $pn) { |
| 358 | 353 | $this->addObserverImpl($observer, $pn); |
| 359 | 354 | } |
| 360 | - } |
|
| 361 | - else { |
|
| 355 | + } else { |
|
| 362 | 356 | $this->addObserverImpl($observer, $parameterName); |
| 363 | 357 | } |
| 364 | 358 | } |
@@ -40,6 +40,9 @@ discard block |
||
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | |
| 43 | + /** |
|
| 44 | + * @param string $propertyName |
|
| 45 | + */ |
|
| 43 | 46 | public function handleSetForTransaction($propertyName) |
| 44 | 47 | { |
| 45 | 48 | if ($this->inTrans) { |
@@ -47,6 +50,9 @@ discard block |
||
| 47 | 50 | } |
| 48 | 51 | } |
| 49 | 52 | |
| 53 | + /** |
|
| 54 | + * @param string $propertyName |
|
| 55 | + */ |
|
| 50 | 56 | public function handleSetForSession($propertyName) |
| 51 | 57 | { |
| 52 | 58 | if ($this->inTrans) { |
@@ -157,6 +163,9 @@ discard block |
||
| 157 | 163 | } |
| 158 | 164 | } |
| 159 | 165 | |
| 166 | + /** |
|
| 167 | + * @param string $name |
|
| 168 | + */ |
|
| 160 | 169 | private function findSavepoint($name) |
| 161 | 170 | { |
| 162 | 171 | for ($idx = $this->tailIdx - 1; $idx >= 0; $idx--) { |
@@ -97,8 +97,7 @@ discard block |
||
| 97 | 97 | |
| 98 | 98 | if (isset($rolledBack[self::RESET_ALL])) { |
| 99 | 99 | $this->connConfig->notifyPropertiesReset(); |
| 100 | - } |
|
| 101 | - else { |
|
| 100 | + } else { |
|
| 102 | 101 | foreach ($rolledBack as $propName) { |
| 103 | 102 | $this->connConfig->notifyPropertyChange($propName); |
| 104 | 103 | } |
@@ -149,8 +148,7 @@ discard block |
||
| 149 | 148 | |
| 150 | 149 | if (isset($rolledBack[self::RESET_ALL])) { |
| 151 | 150 | $this->connConfig->notifyPropertiesReset(); |
| 152 | - } |
|
| 153 | - else { |
|
| 151 | + } else { |
|
| 154 | 152 | foreach ($rolledBack as $propName) { |
| 155 | 153 | $this->connConfig->notifyPropertyChange($propName); |
| 156 | 154 | } |
@@ -108,6 +108,9 @@ |
||
| 108 | 108 | return new $exClass($resultHandler, $query); |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | + /** |
|
| 112 | + * @param resource $resultHandler |
|
| 113 | + */ |
|
| 111 | 114 | private function inferExceptionClass($resultHandler, StatementExceptionFactory $fallbackFactory = null) |
| 112 | 115 | { |
| 113 | 116 | if ($this->bySqlStateCodeAndMessage || $this->bySqlStateCode || $this->bySqlStateClass) { |
@@ -145,8 +145,7 @@ |
||
| 145 | 145 | |
| 146 | 146 | if ($fallbackFactory !== null) { |
| 147 | 147 | return $fallbackFactory->inferExceptionClass($resultHandler); |
| 148 | - } |
|
| 149 | - else { |
|
| 148 | + } else { |
|
| 150 | 149 | return StatementException::class; |
| 151 | 150 | } |
| 152 | 151 | } |
@@ -166,7 +166,7 @@ |
||
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | /** |
| 169 | - * @param IConnection|string $conn (name of) connection to use as the default connection |
|
| 169 | + * @param IConnection $conn (name of) connection to use as the default connection |
|
| 170 | 170 | * @throws \RuntimeException if the requested connection is not defined |
| 171 | 171 | */ |
| 172 | 172 | public static function useConnectionAsDefault($conn) |
@@ -12,16 +12,16 @@ discard block |
||
| 12 | 12 | { |
| 13 | 13 | /** @var ICoreFactory */ |
| 14 | 14 | private static $coreFactory = null; |
| 15 | - /** @var TypeRegister */ |
|
| 16 | - private static $typeRegister = null; |
|
| 17 | - /** @var SqlPatternParser */ |
|
| 18 | - private static $sqlPatternParser = null; |
|
| 19 | - /** @var StatementExceptionFactory */ |
|
| 20 | - private static $stmtExFactory = null; |
|
| 21 | - /** @var IConnection[] map: name => connection */ |
|
| 22 | - private static $connections = []; |
|
| 23 | - /** @var IConnection */ |
|
| 24 | - private static $defaultConn = null; |
|
| 15 | + /** @var TypeRegister */ |
|
| 16 | + private static $typeRegister = null; |
|
| 17 | + /** @var SqlPatternParser */ |
|
| 18 | + private static $sqlPatternParser = null; |
|
| 19 | + /** @var StatementExceptionFactory */ |
|
| 20 | + private static $stmtExFactory = null; |
|
| 21 | + /** @var IConnection[] map: name => connection */ |
|
| 22 | + private static $connections = []; |
|
| 23 | + /** @var IConnection */ |
|
| 24 | + private static $defaultConn = null; |
|
| 25 | 25 | |
| 26 | 26 | |
| 27 | 27 | private function __construct() |
@@ -50,16 +50,16 @@ discard block |
||
| 50 | 50 | self::$coreFactory = $coreFactory; |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * @return TypeRegister the global type register, used for getting types not defined locally for a connection |
|
| 55 | - */ |
|
| 56 | - public static function getTypeRegister() : TypeRegister |
|
| 57 | - { |
|
| 58 | - if (self::$typeRegister === null) { |
|
| 53 | + /** |
|
| 54 | + * @return TypeRegister the global type register, used for getting types not defined locally for a connection |
|
| 55 | + */ |
|
| 56 | + public static function getTypeRegister() : TypeRegister |
|
| 57 | + { |
|
| 58 | + if (self::$typeRegister === null) { |
|
| 59 | 59 | self::$typeRegister = self::getCoreFactory()->createTypeRegister(); |
| 60 | - } |
|
| 61 | - return self::$typeRegister; |
|
| 62 | - } |
|
| 60 | + } |
|
| 61 | + return self::$typeRegister; |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | 64 | public static function getSqlPatternParser() : SqlPatternParser |
| 65 | 65 | { |
@@ -69,120 +69,120 @@ discard block |
||
| 69 | 69 | return self::$sqlPatternParser; |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * @return StatementExceptionFactory the global statement exception factory, used for emitting the |
|
| 74 | - * {@link \Ivory\Exception\StatementException}s upon statement errors; |
|
| 75 | - * like the type register, an overriding factory is also defined locally on each |
|
| 76 | - * connection - this factory only applies if the local one does not |
|
| 77 | - */ |
|
| 78 | - public static function getStatementExceptionFactory() : StatementExceptionFactory |
|
| 79 | - { |
|
| 80 | - if (self::$stmtExFactory === null) { |
|
| 81 | - self::$stmtExFactory = self::getCoreFactory()->createStatementExceptionFactory(); |
|
| 82 | - } |
|
| 83 | - return self::$stmtExFactory; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Sets up a new database connection. |
|
| 88 | - * |
|
| 89 | - * If this is the first connection to set up, it is automatically set as the default connection. |
|
| 90 | - * |
|
| 91 | - * The connection with the database is not immediately established - just a {@link Connection} object is initialized |
|
| 92 | - * and returned, it connects to the database on demand. |
|
| 93 | - * |
|
| 94 | - * @param mixed $params the parameters for creating the connection; |
|
| 95 | - * anything accepted by {@link ConnectionParameters::create()} - one of the following options: |
|
| 96 | - * <ul> |
|
| 97 | - * <li>a {@link ConnectionParameters} object |
|
| 98 | - * <li>a URI, e.g., <tt>"postgresql://usr@localhost:5433/db?connect_timeout=10"</tt> |
|
| 99 | - * <li>a PostgreSQL connection string, e.g., |
|
| 100 | - * <tt>"host=localhost port=5432 dbname=mydb connect_timeout=10"</tt> |
|
| 101 | - * <li>a map of connection parameter keywords to values, e.g., <tt>['host' => '/tmp']</tt> |
|
| 102 | - * </ul> |
|
| 103 | - * @param string|null $connName name for the connection; |
|
| 104 | - * if not given, the database name is considered if it is given within <tt>$params</tt> |
|
| 105 | - * or the fallback name <tt>'conn'</tt> is used; |
|
| 106 | - * if not given and if the auto-generated name is already taken, it is appended with a |
|
| 107 | - * numeric suffix, e.g., <tt>'conn1'</tt>, <tt>'conn2'</tt>, etc. |
|
| 108 | - * @return IConnection |
|
| 109 | - * @throws ConnectionException if connection name is explicitly specified but a connection with the same name |
|
| 110 | - * already exists |
|
| 111 | - */ |
|
| 112 | - public static function setupConnection($params, $connName = null) : IConnection |
|
| 113 | - { |
|
| 114 | - if (!$params instanceof ConnectionParameters) { |
|
| 115 | - $params = ConnectionParameters::create($params); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - if ($connName === null) { |
|
| 119 | - $connName = (isset($params['dbname']) ? $params['dbname'] : 'conn'); |
|
| 120 | - $safetyBreak = 10000; |
|
| 121 | - for ($i = 1; $i < $safetyBreak; $i++) { |
|
| 122 | - if (!isset(self::$connections[$connName . $i])) { |
|
| 123 | - $connName .= $i; |
|
| 124 | - break; |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - if ($i >= $safetyBreak) { |
|
| 128 | - throw new \RuntimeException('Error auto-generating name for the new connection: all suffixes taken'); |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - $conn = self::getCoreFactory()->createConnection($connName, $params); |
|
| 133 | - |
|
| 134 | - if (!self::$connections) { |
|
| 135 | - self::useConnectionAsDefault($conn); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - self::$connections[$connName] = $conn; |
|
| 139 | - |
|
| 140 | - return $conn; |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * @param string|null $connName name of the connection to get; <tt>null</tt> to get the default connection |
|
| 145 | - * @return IConnection |
|
| 146 | - * @throws \RuntimeException if the default connection is requested but no connection has been setup yet, or if the |
|
| 147 | - * requested connection is not defined |
|
| 148 | - */ |
|
| 149 | - public static function getConnection($connName = null) : IConnection |
|
| 150 | - { |
|
| 151 | - if ($connName === null) { |
|
| 152 | - if (self::$defaultConn) { |
|
| 153 | - return self::$defaultConn; |
|
| 154 | - } |
|
| 155 | - else { |
|
| 156 | - throw new \RuntimeException('No connection has been setup'); |
|
| 157 | - } |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - if (isset(self::$connections[$connName])) { |
|
| 161 | - return self::$connections[$connName]; |
|
| 162 | - } |
|
| 163 | - else { |
|
| 164 | - throw new \RuntimeException('Undefined connection'); |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * @param IConnection|string $conn (name of) connection to use as the default connection |
|
| 170 | - * @throws \RuntimeException if the requested connection is not defined |
|
| 171 | - */ |
|
| 172 | - public static function useConnectionAsDefault($conn) |
|
| 173 | - { |
|
| 174 | - if (is_string($conn)) { |
|
| 175 | - if (isset(self::$connections[$conn])) { |
|
| 176 | - $conn = self::$connections[$conn]; |
|
| 177 | - } |
|
| 178 | - else { |
|
| 179 | - throw new \RuntimeException('Undefined connection'); |
|
| 180 | - } |
|
| 181 | - } |
|
| 182 | - elseif (!$conn instanceof IConnection) { |
|
| 183 | - throw new \InvalidArgumentException('conn'); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - self::$defaultConn = $conn; |
|
| 187 | - } |
|
| 72 | + /** |
|
| 73 | + * @return StatementExceptionFactory the global statement exception factory, used for emitting the |
|
| 74 | + * {@link \Ivory\Exception\StatementException}s upon statement errors; |
|
| 75 | + * like the type register, an overriding factory is also defined locally on each |
|
| 76 | + * connection - this factory only applies if the local one does not |
|
| 77 | + */ |
|
| 78 | + public static function getStatementExceptionFactory() : StatementExceptionFactory |
|
| 79 | + { |
|
| 80 | + if (self::$stmtExFactory === null) { |
|
| 81 | + self::$stmtExFactory = self::getCoreFactory()->createStatementExceptionFactory(); |
|
| 82 | + } |
|
| 83 | + return self::$stmtExFactory; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Sets up a new database connection. |
|
| 88 | + * |
|
| 89 | + * If this is the first connection to set up, it is automatically set as the default connection. |
|
| 90 | + * |
|
| 91 | + * The connection with the database is not immediately established - just a {@link Connection} object is initialized |
|
| 92 | + * and returned, it connects to the database on demand. |
|
| 93 | + * |
|
| 94 | + * @param mixed $params the parameters for creating the connection; |
|
| 95 | + * anything accepted by {@link ConnectionParameters::create()} - one of the following options: |
|
| 96 | + * <ul> |
|
| 97 | + * <li>a {@link ConnectionParameters} object |
|
| 98 | + * <li>a URI, e.g., <tt>"postgresql://usr@localhost:5433/db?connect_timeout=10"</tt> |
|
| 99 | + * <li>a PostgreSQL connection string, e.g., |
|
| 100 | + * <tt>"host=localhost port=5432 dbname=mydb connect_timeout=10"</tt> |
|
| 101 | + * <li>a map of connection parameter keywords to values, e.g., <tt>['host' => '/tmp']</tt> |
|
| 102 | + * </ul> |
|
| 103 | + * @param string|null $connName name for the connection; |
|
| 104 | + * if not given, the database name is considered if it is given within <tt>$params</tt> |
|
| 105 | + * or the fallback name <tt>'conn'</tt> is used; |
|
| 106 | + * if not given and if the auto-generated name is already taken, it is appended with a |
|
| 107 | + * numeric suffix, e.g., <tt>'conn1'</tt>, <tt>'conn2'</tt>, etc. |
|
| 108 | + * @return IConnection |
|
| 109 | + * @throws ConnectionException if connection name is explicitly specified but a connection with the same name |
|
| 110 | + * already exists |
|
| 111 | + */ |
|
| 112 | + public static function setupConnection($params, $connName = null) : IConnection |
|
| 113 | + { |
|
| 114 | + if (!$params instanceof ConnectionParameters) { |
|
| 115 | + $params = ConnectionParameters::create($params); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + if ($connName === null) { |
|
| 119 | + $connName = (isset($params['dbname']) ? $params['dbname'] : 'conn'); |
|
| 120 | + $safetyBreak = 10000; |
|
| 121 | + for ($i = 1; $i < $safetyBreak; $i++) { |
|
| 122 | + if (!isset(self::$connections[$connName . $i])) { |
|
| 123 | + $connName .= $i; |
|
| 124 | + break; |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + if ($i >= $safetyBreak) { |
|
| 128 | + throw new \RuntimeException('Error auto-generating name for the new connection: all suffixes taken'); |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + $conn = self::getCoreFactory()->createConnection($connName, $params); |
|
| 133 | + |
|
| 134 | + if (!self::$connections) { |
|
| 135 | + self::useConnectionAsDefault($conn); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + self::$connections[$connName] = $conn; |
|
| 139 | + |
|
| 140 | + return $conn; |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * @param string|null $connName name of the connection to get; <tt>null</tt> to get the default connection |
|
| 145 | + * @return IConnection |
|
| 146 | + * @throws \RuntimeException if the default connection is requested but no connection has been setup yet, or if the |
|
| 147 | + * requested connection is not defined |
|
| 148 | + */ |
|
| 149 | + public static function getConnection($connName = null) : IConnection |
|
| 150 | + { |
|
| 151 | + if ($connName === null) { |
|
| 152 | + if (self::$defaultConn) { |
|
| 153 | + return self::$defaultConn; |
|
| 154 | + } |
|
| 155 | + else { |
|
| 156 | + throw new \RuntimeException('No connection has been setup'); |
|
| 157 | + } |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + if (isset(self::$connections[$connName])) { |
|
| 161 | + return self::$connections[$connName]; |
|
| 162 | + } |
|
| 163 | + else { |
|
| 164 | + throw new \RuntimeException('Undefined connection'); |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * @param IConnection|string $conn (name of) connection to use as the default connection |
|
| 170 | + * @throws \RuntimeException if the requested connection is not defined |
|
| 171 | + */ |
|
| 172 | + public static function useConnectionAsDefault($conn) |
|
| 173 | + { |
|
| 174 | + if (is_string($conn)) { |
|
| 175 | + if (isset(self::$connections[$conn])) { |
|
| 176 | + $conn = self::$connections[$conn]; |
|
| 177 | + } |
|
| 178 | + else { |
|
| 179 | + throw new \RuntimeException('Undefined connection'); |
|
| 180 | + } |
|
| 181 | + } |
|
| 182 | + elseif (!$conn instanceof IConnection) { |
|
| 183 | + throw new \InvalidArgumentException('conn'); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + self::$defaultConn = $conn; |
|
| 187 | + } |
|
| 188 | 188 | } |
@@ -151,16 +151,14 @@ discard block |
||
| 151 | 151 | if ($connName === null) { |
| 152 | 152 | if (self::$defaultConn) { |
| 153 | 153 | return self::$defaultConn; |
| 154 | - } |
|
| 155 | - else { |
|
| 154 | + } else { |
|
| 156 | 155 | throw new \RuntimeException('No connection has been setup'); |
| 157 | 156 | } |
| 158 | 157 | } |
| 159 | 158 | |
| 160 | 159 | if (isset(self::$connections[$connName])) { |
| 161 | 160 | return self::$connections[$connName]; |
| 162 | - } |
|
| 163 | - else { |
|
| 161 | + } else { |
|
| 164 | 162 | throw new \RuntimeException('Undefined connection'); |
| 165 | 163 | } |
| 166 | 164 | } |
@@ -174,12 +172,10 @@ discard block |
||
| 174 | 172 | if (is_string($conn)) { |
| 175 | 173 | if (isset(self::$connections[$conn])) { |
| 176 | 174 | $conn = self::$connections[$conn]; |
| 177 | - } |
|
| 178 | - else { |
|
| 175 | + } else { |
|
| 179 | 176 | throw new \RuntimeException('Undefined connection'); |
| 180 | 177 | } |
| 181 | - } |
|
| 182 | - elseif (!$conn instanceof IConnection) { |
|
| 178 | + } elseif (!$conn instanceof IConnection) { |
|
| 183 | 179 | throw new \InvalidArgumentException('conn'); |
| 184 | 180 | } |
| 185 | 181 | |
@@ -14,6 +14,9 @@ |
||
| 14 | 14 | /** @var IQueryResult */ |
| 15 | 15 | private $result = null; |
| 16 | 16 | |
| 17 | + /** |
|
| 18 | + * @param string $query |
|
| 19 | + */ |
|
| 17 | 20 | public function __construct(IStatementExecution $conn, $query, ...$args) |
| 18 | 21 | { |
| 19 | 22 | parent::__construct(); |
@@ -15,6 +15,9 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | trait RelationMacros |
| 17 | 17 | { |
| 18 | + /** |
|
| 19 | + * @param string[] $columns |
|
| 20 | + */ |
|
| 18 | 21 | abstract public function project($columns); |
| 19 | 22 | |
| 20 | 23 | /** |
@@ -74,6 +77,9 @@ discard block |
||
| 74 | 77 | return $this->tuple($tupleOffset)->value($colOffsetOrNameOrEvaluator); |
| 75 | 78 | } |
| 76 | 79 | |
| 80 | + /** |
|
| 81 | + * @param IColumn[] $columns |
|
| 82 | + */ |
|
| 77 | 83 | final protected function _colImpl($offsetOrNameOrEvaluator, $columns, $colNameMap, IRelation $relation) |
| 78 | 84 | { |
| 79 | 85 | if (is_scalar($offsetOrNameOrEvaluator)) { |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | public function assoc($col1, $col2, ...$moreCols) |
| 108 | 108 | { |
| 109 | 109 | return $this->assocImpl( |
| 110 | - function () { |
|
| 110 | + function() { |
|
| 111 | 111 | // FIXME: depending on the data type of the keys, either use an array-based implementation, or an object hashing implementation |
| 112 | 112 | return new ArrayValueMap(); |
| 113 | 113 | }, |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | public function map($mappingCol, ...$moreMappingCols) |
| 119 | 119 | { |
| 120 | 120 | return $this->assocImpl( |
| 121 | - function () { |
|
| 121 | + function() { |
|
| 122 | 122 | // FIXME: depending on the data type of the keys, either use an array-based implementation, or an object hashing implementation |
| 123 | 123 | return new ArrayTupleMap(); |
| 124 | 124 | }, |
@@ -80,26 +80,21 @@ |
||
| 80 | 80 | if (filter_var($offsetOrNameOrEvaluator, FILTER_VALIDATE_INT) !== false) { |
| 81 | 81 | if (isset($columns[$offsetOrNameOrEvaluator])) { |
| 82 | 82 | return $columns[$offsetOrNameOrEvaluator]; |
| 83 | - } |
|
| 84 | - else { |
|
| 83 | + } else { |
|
| 85 | 84 | throw new UndefinedColumnException("No column at offset $offsetOrNameOrEvaluator"); |
| 86 | 85 | } |
| 87 | - } |
|
| 88 | - else { |
|
| 86 | + } else { |
|
| 89 | 87 | if (isset($colNameMap[$offsetOrNameOrEvaluator])) { |
| 90 | 88 | return $columns[$colNameMap[$offsetOrNameOrEvaluator]]; |
| 91 | - } |
|
| 92 | - else { |
|
| 89 | + } else { |
|
| 93 | 90 | throw new UndefinedColumnException("No column named $offsetOrNameOrEvaluator"); |
| 94 | 91 | } |
| 95 | 92 | } |
| 96 | - } |
|
| 97 | - elseif ($offsetOrNameOrEvaluator instanceof ITupleEvaluator || |
|
| 93 | + } elseif ($offsetOrNameOrEvaluator instanceof ITupleEvaluator || |
|
| 98 | 94 | $offsetOrNameOrEvaluator instanceof \Closure) |
| 99 | 95 | { |
| 100 | 96 | return new Column($relation, $offsetOrNameOrEvaluator, null, null); |
| 101 | - } |
|
| 102 | - else { |
|
| 97 | + } else { |
|
| 103 | 98 | throw new \InvalidArgumentException('$offsetOrNameOrEvaluator'); |
| 104 | 99 | } |
| 105 | 100 | } |
@@ -29,6 +29,9 @@ discard block |
||
| 29 | 29 | private $delim; |
| 30 | 30 | private $elemNeedsQuotesRegex; |
| 31 | 31 | |
| 32 | + /** |
|
| 33 | + * @param string $delimiter |
|
| 34 | + */ |
|
| 32 | 35 | public function __construct(INamedType $elemType, $delimiter) |
| 33 | 36 | { |
| 34 | 37 | $this->elemType = $elemType; |
@@ -284,6 +287,11 @@ discard block |
||
| 284 | 287 | return $out; |
| 285 | 288 | } |
| 286 | 289 | |
| 290 | + /** |
|
| 291 | + * @param string $str |
|
| 292 | + * @param string $errMsg |
|
| 293 | + * @param integer $offset |
|
| 294 | + */ |
|
| 287 | 295 | private static function throwArrayParseException($str, $errMsg = null, $offset = null) |
| 288 | 296 | { |
| 289 | 297 | $msg = "Value '$str' is not valid for an array"; |
@@ -293,6 +301,11 @@ discard block |
||
| 293 | 301 | throw new ParseException($msg, $offset); |
| 294 | 302 | } |
| 295 | 303 | |
| 304 | + /** |
|
| 305 | + * @param string $str |
|
| 306 | + * @param integer $offset |
|
| 307 | + * @param ParseException $cause |
|
| 308 | + */ |
|
| 296 | 309 | private function throwParseException($str, $errMsg = null, $offset = null, $cause = null) |
| 297 | 310 | { |
| 298 | 311 | $elemTypeName = $this->elemType->getSchemaName() . '.' . $this->elemType->getName(); |
@@ -128,7 +128,7 @@ |
||
| 128 | 128 | case '{': |
| 129 | 129 | $dim++; |
| 130 | 130 | $keys[$dim] = $lowerBounds[$dim]; |
| 131 | - $refs[$dim] = &$refs[$dim - 1][$keys[$dim-1]]; |
|
| 131 | + $refs[$dim] = &$refs[$dim - 1][$keys[$dim - 1]]; |
|
| 132 | 132 | $refs[$dim] = []; |
| 133 | 133 | break; |
| 134 | 134 | case '}': |
@@ -72,8 +72,7 @@ discard block |
||
| 72 | 72 | for ($strOffset = $decorSepPos + 1; isset($str[$strOffset]) && ctype_space($str[$strOffset]); $strOffset++); |
| 73 | 73 | $lowerBounds = $m[1]; |
| 74 | 74 | unset($m); |
| 75 | - } |
|
| 76 | - else { |
|
| 75 | + } else { |
|
| 77 | 76 | if (trim($str) == '{}') { |
| 78 | 77 | return []; |
| 79 | 78 | } |
@@ -82,11 +81,9 @@ discard block |
||
| 82 | 81 | for ($i = $strOffset; $i < $len; $i++) { |
| 83 | 82 | if (ctype_space($str[$i])) { |
| 84 | 83 | continue; |
| 85 | - } |
|
| 86 | - elseif ($str[$i] == '{') { |
|
| 84 | + } elseif ($str[$i] == '{') { |
|
| 87 | 85 | $dims++; |
| 88 | - } |
|
| 89 | - else { |
|
| 86 | + } else { |
|
| 90 | 87 | break; |
| 91 | 88 | } |
| 92 | 89 | } |
@@ -146,14 +143,12 @@ discard block |
||
| 146 | 143 | $k = $keys[$dim]; |
| 147 | 144 | if (strcasecmp($elem, 'NULL') == 0) { |
| 148 | 145 | $refs[$dim][$k] = null; |
| 149 | - } |
|
| 150 | - else { |
|
| 146 | + } else { |
|
| 151 | 147 | $cont = ($elem[0] == '"' ? substr($elem, 1, -1) : $elem); |
| 152 | 148 | $unEsc = preg_replace('~\\\\(.)~', '$1', $cont); |
| 153 | 149 | $refs[$dim][$k] = $this->elemType->parseValue($unEsc); |
| 154 | 150 | } |
| 155 | - } |
|
| 156 | - catch (ParseException $e) { |
|
| 151 | + } catch (ParseException $e) { |
|
| 157 | 152 | $this->throwParseException($str, 'Error parsing the element value', $strOffset, $e); |
| 158 | 153 | } |
| 159 | 154 | $strOffset += strlen($elem); |
@@ -200,8 +195,7 @@ discard block |
||
| 200 | 195 | $maxDim = $curDim; |
| 201 | 196 | $b = ($arr ? [$keys[0], $keys[count($keys) - 1]] : [1, 0]); |
| 202 | 197 | $bounds[$curDim] = $b; |
| 203 | - } |
|
| 204 | - else { |
|
| 198 | + } else { |
|
| 205 | 199 | $b = $bounds[$curDim]; |
| 206 | 200 | if ($keys[0] < $b[0] || $keys[count($keys) - 1] > $b[1]) { |
| 207 | 201 | $msg = "Some array subscripts do not match the bounds of the array: " . print_r($val, true); |
@@ -218,15 +212,13 @@ discard block |
||
| 218 | 212 | foreach ($arr as $v) { |
| 219 | 213 | if ($first) { |
| 220 | 214 | $first = false; |
| 221 | - } |
|
| 222 | - else { |
|
| 215 | + } else { |
|
| 223 | 216 | $out .= $this->delim; |
| 224 | 217 | } |
| 225 | 218 | |
| 226 | 219 | if (is_array($v)) { |
| 227 | 220 | $out .= $this->serializeValueImpl($v, $curDim + 1, $maxDim, $bounds); |
| 228 | - } |
|
| 229 | - else { |
|
| 221 | + } else { |
|
| 230 | 222 | if ($curDim != $maxDim) { |
| 231 | 223 | $msg = "Some array items do not match the dimensions of the array: " . print_r($val, true); |
| 232 | 224 | throw new \InvalidArgumentException($msg); |
@@ -234,8 +226,7 @@ discard block |
||
| 234 | 226 | |
| 235 | 227 | if ($v === null) { |
| 236 | 228 | $valOut = 'NULL'; |
| 237 | - } |
|
| 238 | - else { |
|
| 229 | + } else { |
|
| 239 | 230 | $valOut = $this->elemType->serializeValue($v); |
| 240 | 231 | /* Trim the single quotes and other decoration - the value will be used inside a string literal. |
| 241 | 232 | As an optimization, doubled single quotes (meaning the literal single quote) will be preserved |
@@ -330,25 +321,20 @@ discard block |
||
| 330 | 321 | if ($bv !== null) { |
| 331 | 322 | return -1; |
| 332 | 323 | } |
| 333 | - } |
|
| 334 | - elseif ($bv === null) { |
|
| 324 | + } elseif ($bv === null) { |
|
| 335 | 325 | return 1; |
| 336 | - } |
|
| 337 | - elseif (is_array($av)) { |
|
| 326 | + } elseif (is_array($av)) { |
|
| 338 | 327 | if (is_array($bv)) { |
| 339 | 328 | $comp = $this->compareValuesImpl($av, $bv); |
| 340 | 329 | if ($comp) { |
| 341 | 330 | return $comp; |
| 342 | 331 | } |
| 343 | - } |
|
| 344 | - else { |
|
| 332 | + } else { |
|
| 345 | 333 | return 1; |
| 346 | 334 | } |
| 347 | - } |
|
| 348 | - elseif (is_array($bv)) { |
|
| 335 | + } elseif (is_array($bv)) { |
|
| 349 | 336 | return -1; |
| 350 | - } |
|
| 351 | - else { |
|
| 337 | + } else { |
|
| 352 | 338 | /** @var ITotallyOrderedType $et */ |
| 353 | 339 | $et = $this->elemType; |
| 354 | 340 | $comp = $et->compareValues($av, $bv); |
@@ -371,22 +357,17 @@ discard block |
||
| 371 | 357 | $bk = key($bFst); |
| 372 | 358 | if ($ak === null && $bk === null) { |
| 373 | 359 | return 0; |
| 374 | - } |
|
| 375 | - elseif ($ak === null) { |
|
| 360 | + } elseif ($ak === null) { |
|
| 376 | 361 | return -1; |
| 377 | - } |
|
| 378 | - elseif ($bk === null) { |
|
| 362 | + } elseif ($bk === null) { |
|
| 379 | 363 | return 1; |
| 380 | - } |
|
| 381 | - elseif (!is_numeric($ak) || !is_numeric($bk)) { |
|
| 364 | + } elseif (!is_numeric($ak) || !is_numeric($bk)) { |
|
| 382 | 365 | return 0; |
| 383 | - } |
|
| 384 | - else { |
|
| 366 | + } else { |
|
| 385 | 367 | $d = $ak - $bk; |
| 386 | 368 | if ($d) { |
| 387 | 369 | return $d; |
| 388 | - } |
|
| 389 | - else { |
|
| 370 | + } else { |
|
| 390 | 371 | $aFst = current($aFst); |
| 391 | 372 | $bFst = current($bFst); |
| 392 | 373 | } |
@@ -8,6 +8,9 @@ discard block |
||
| 8 | 8 | private $connection; |
| 9 | 9 | private $connHandler; |
| 10 | 10 | |
| 11 | + /** |
|
| 12 | + * @param resource|null $connHandler |
|
| 13 | + */ |
|
| 11 | 14 | public function __construct(IConnection $connection, $connHandler) |
| 12 | 15 | { |
| 13 | 16 | $this->connection = $connection; |
@@ -190,6 +193,10 @@ discard block |
||
| 190 | 193 | } |
| 191 | 194 | } |
| 192 | 195 | |
| 196 | + /** |
|
| 197 | + * @param string $query |
|
| 198 | + * @param string $errorDesc |
|
| 199 | + */ |
|
| 193 | 200 | private function query($query, $errorDesc) |
| 194 | 201 | { |
| 195 | 202 | $result = pg_query($this->connHandler, $query); |
@@ -137,8 +137,7 @@ discard block |
||
| 137 | 137 | "range. That might lead to unexpected results, though."; |
| 138 | 138 | trigger_error($msg, E_USER_WARNING); |
| 139 | 139 | } |
| 140 | - } |
|
| 141 | - else { |
|
| 140 | + } else { |
|
| 142 | 141 | $canonFunc = null; |
| 143 | 142 | } |
| 144 | 143 | $type = $this->createRangeType($schemaName, $typeName, $subtype, $canonFunc); |
@@ -218,8 +217,7 @@ discard block |
||
| 218 | 217 | $type = $typeProvider->provideType($schemaName, $typeName); |
| 219 | 218 | if ($type !== null) { |
| 220 | 219 | return $type; |
| 221 | - } |
|
| 222 | - else { |
|
| 220 | + } else { |
|
| 223 | 221 | return new UndefinedType($schemaName, $typeName, $this->connection->getName(), $this->connection); |
| 224 | 222 | } |
| 225 | 223 | } |
@@ -17,6 +17,10 @@ discard block |
||
| 17 | 17 | private $subtype; |
| 18 | 18 | private $canonicalFunc; |
| 19 | 19 | |
| 20 | + /** |
|
| 21 | + * @param string $schemaName |
|
| 22 | + * @param string $name |
|
| 23 | + */ |
|
| 20 | 24 | public function __construct($schemaName, $name, ITotallyOrderedType $subtype, IRangeCanonicalFunc $canonicalFunc = null) |
| 21 | 25 | { |
| 22 | 26 | $this->setName($schemaName, $name); |
@@ -69,6 +73,9 @@ discard block |
||
| 69 | 73 | return Range::createFromBounds($this->subtype, $this->canonicalFunc, $lower, $upper, $lowerInc, $upperInc); |
| 70 | 74 | } |
| 71 | 75 | |
| 76 | + /** |
|
| 77 | + * @param string $str |
|
| 78 | + */ |
|
| 72 | 79 | private function parseBoundStr($str) |
| 73 | 80 | { |
| 74 | 81 | if (strlen($str) == 0) { |
@@ -152,6 +159,11 @@ discard block |
||
| 152 | 159 | } |
| 153 | 160 | } |
| 154 | 161 | |
| 162 | + /** |
|
| 163 | + * @param integer $sgn |
|
| 164 | + * @param boolean|null $aIsInc |
|
| 165 | + * @param boolean|null $bIsInc |
|
| 166 | + */ |
|
| 155 | 167 | private function compareBounds($sgn, $aVal, $aIsInc, $bVal, $bIsInc) |
| 156 | 168 | { |
| 157 | 169 | if ($aVal === null && $bVal === null) { |
@@ -91,8 +91,7 @@ discard block |
||
| 91 | 91 | if (!$val instanceof Range) { |
| 92 | 92 | if (is_array($val) && isset($val[0], $val[1]) && count($val) == 2) { |
| 93 | 93 | $val = Range::createFromBounds($this->subtype, $this->canonicalFunc, $val[0], $val[1], true, true); |
| 94 | - } |
|
| 95 | - else { |
|
| 94 | + } else { |
|
| 96 | 95 | $message = "Value '$val' is not valid for type {$this->getSchemaName()}.{$this->getName()}"; |
| 97 | 96 | throw new \InvalidArgumentException($message); |
| 98 | 97 | } |
@@ -134,19 +133,15 @@ discard block |
||
| 134 | 133 | // empty ranges are sorted before all else in PostgreSQL |
| 135 | 134 | if ($a->isEmpty() && $b->isEmpty()) { |
| 136 | 135 | return 0; |
| 137 | - } |
|
| 138 | - elseif ($a->isEmpty()) { |
|
| 136 | + } elseif ($a->isEmpty()) { |
|
| 139 | 137 | return -1; |
| 140 | - } |
|
| 141 | - elseif ($b->isEmpty()) { |
|
| 138 | + } elseif ($b->isEmpty()) { |
|
| 142 | 139 | return 1; |
| 143 | - } |
|
| 144 | - else { |
|
| 140 | + } else { |
|
| 145 | 141 | $cmp = $this->compareBounds(-1, $a->getLower(), $a->isLowerInc(), $b->getLower(), $b->isLowerInc()); |
| 146 | 142 | if ($cmp != 0) { |
| 147 | 143 | return $cmp; |
| 148 | - } |
|
| 149 | - else { |
|
| 144 | + } else { |
|
| 150 | 145 | return $this->compareBounds(1, $a->getUpper(), $a->isUpperInc(), $b->getUpper(), $b->isUpperInc()); |
| 151 | 146 | } |
| 152 | 147 | } |
@@ -156,11 +151,9 @@ discard block |
||
| 156 | 151 | { |
| 157 | 152 | if ($aVal === null && $bVal === null) { |
| 158 | 153 | return 0; |
| 159 | - } |
|
| 160 | - elseif ($aVal === null) { |
|
| 154 | + } elseif ($aVal === null) { |
|
| 161 | 155 | return 1 * $sgn; |
| 162 | - } |
|
| 163 | - elseif ($bVal === null) { |
|
| 156 | + } elseif ($bVal === null) { |
|
| 164 | 157 | return -1 * $sgn; |
| 165 | 158 | } |
| 166 | 159 | |
@@ -172,14 +165,11 @@ discard block |
||
| 172 | 165 | // PHP 7: <=> could lead to a more compact form |
| 173 | 166 | if ($aIsInc && $bIsInc) { |
| 174 | 167 | return 0; |
| 175 | - } |
|
| 176 | - elseif ($aIsInc) { |
|
| 168 | + } elseif ($aIsInc) { |
|
| 177 | 169 | return 1 * $sgn; |
| 178 | - } |
|
| 179 | - elseif ($bIsInc) { |
|
| 170 | + } elseif ($bIsInc) { |
|
| 180 | 171 | return -1 * $sgn; |
| 181 | - } |
|
| 182 | - else { |
|
| 172 | + } else { |
|
| 183 | 173 | return 0; |
| 184 | 174 | } |
| 185 | 175 | } |