From 11c78afbbe1ec9a66f0eb450328d4fd93dc0ce38 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 24 Aug 2018 21:09:40 +0200 Subject: [PATCH] Fix invalid global namespace --- Config/SettingsAbstract.php | 39 ++++++++++++---------- Math/Geometry/ConvexHull/MonotoneChain.php | 2 +- Math/Matrix/Matrix.php | 2 +- Message/RequestAbstract.php | 25 ++++++++++++-- System/File/Local/Directory.php | 2 +- 5 files changed, 47 insertions(+), 23 deletions(-) diff --git a/Config/SettingsAbstract.php b/Config/SettingsAbstract.php index e93b2c7f6..8bb089352 100644 --- a/Config/SettingsAbstract.php +++ b/Config/SettingsAbstract.php @@ -87,33 +87,28 @@ abstract class SettingsAbstract implements OptionsInterface public function get($columns) { try { - if (!is_array($columns)) { + if (!\is_array($columns)) { $columns = [$columns]; } $options = []; + $query = new Builder($this->connection); + $sql = $query->select(...static::$columns) + ->from($this->connection->prefix . static::$table) + ->where(static::$columns[0], 'in', $columns) + ->toSql(); - switch ($this->connection->getType()) { - case DatabaseType::MYSQL: - $query = new Builder($this->connection); - $sql = $query->select(...static::$columns) - ->from($this->connection->prefix . static::$table) - ->where(static::$columns[0], 'in', $columns) - ->toSql(); + $sth = $this->connection->con->prepare($sql); + $sth->execute(); - $sth = $this->connection->con->prepare($sql); - $sth->execute(); + $options = $sth->fetchAll(\PDO::FETCH_KEY_PAIR); - $options = $sth->fetchAll(\PDO::FETCH_KEY_PAIR); - - if ($options === false) { - return []; - } - - $this->setOptions($options); - break; + if ($options === false) { + return []; } + $this->setOptions($options); + return \count($options) > 1 ? $options : \reset($options); } catch (\PDOException $e) { $exception = DatabaseExceptionFactory::createException($e); @@ -138,7 +133,13 @@ abstract class SettingsAbstract implements OptionsInterface $this->setOptions($options); if ($store) { + $this->connection->con->beginTransaction(); + foreach ($this->options as $key => $option) { + if (\is_string($key)) { + $key = (int) \preg_replace('/[^0-9.]/', '', $key); + } + $query = new Builder($this->connection); $sql = $query->update($this->connection->prefix . static::$table) ->set([static::$columns[1] => $option]) @@ -148,6 +149,8 @@ abstract class SettingsAbstract implements OptionsInterface $sth = $this->connection->con->prepare($sql); $sth->execute(); } + + $this->connection->con->commit(); } } } diff --git a/Math/Geometry/ConvexHull/MonotoneChain.php b/Math/Geometry/ConvexHull/MonotoneChain.php index 757b316fb..5afa8fcf3 100644 --- a/Math/Geometry/ConvexHull/MonotoneChain.php +++ b/Math/Geometry/ConvexHull/MonotoneChain.php @@ -104,7 +104,7 @@ final class MonotoneChain * * @since 1.0.0 */ - private static function \sort(array $a, array $b) : float + private static function sort(array $a, array $b) : float { return $a['x'] === $b['x'] ? $a['y'] - $b['y'] : $a['x'] - $b['x']; } diff --git a/Math/Matrix/Matrix.php b/Math/Matrix/Matrix.php index 33ac7ab8b..d18e86a35 100644 --- a/Math/Matrix/Matrix.php +++ b/Math/Matrix/Matrix.php @@ -772,7 +772,7 @@ class Matrix implements \ArrayAccess, \Iterator /** * {@inheritdoc} */ - public function \rewind() + public function rewind() { $this->position = 0; } diff --git a/Message/RequestAbstract.php b/Message/RequestAbstract.php index 49fe4656e..306f965f9 100644 --- a/Message/RequestAbstract.php +++ b/Message/RequestAbstract.php @@ -167,11 +167,32 @@ abstract class RequestAbstract implements MessageInterface return $this->data; } - $key = mb_strtolower($key); + $key = \mb_strtolower($key); return $this->data[$key] ?? null; } + /** + * Get data based on wildcard. + * + * @param string $regex Regex data key + * + * @return array + * + * @since 1.0.0 + */ + public function getLike(string $regex) : array + { + $data = []; + foreach ($this->data as $key => $value) { + if (\preg_match('/' . $regex . '/', $key) === 1) { + $data[$key] = $value; + } + } + + return $data; + } + /** * Check if has data. * @@ -200,7 +221,7 @@ abstract class RequestAbstract implements MessageInterface public function setData($key, $value, bool $overwrite = true) : bool { if (!$this->lock) { - $key = mb_strtolower($key); + $key = \mb_strtolower($key); if ($overwrite || !isset($this->data[$key])) { $this->data[$key] = $value; diff --git a/System/File/Local/Directory.php b/System/File/Local/Directory.php index d92719f67..19ea1ca55 100644 --- a/System/File/Local/Directory.php +++ b/System/File/Local/Directory.php @@ -449,7 +449,7 @@ final class Directory extends FileAbstract implements DirectoryInterface /** * {@inheritdoc} */ - public function \rewind() + public function rewind() { \reset($this->nodes); }