From a7abed56d6a3d8d03b1c99e620a9c0ef3887bfcb Mon Sep 17 00:00:00 2001 From: Arsen Mirzaev Tatyano-Muradovich Date: Mon, 22 Mar 2021 05:01:43 +1000 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B0=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?,=20=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=B8=20=D0=B3=D0=B5=D0=BD=D0=B5=D1=80=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D0=B8=20=D0=B7=D0=B0=D0=BF=D1=80=D0=BE=D1=81=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 4 +- .../arangodb}/ActiveQuery.php | 0 .../arangodb}/ActiveRecord.php | 0 .../arangodb}/AqlExpression.php | 0 .../arangodb}/Connection.php | 0 .../arangodb}/Exception.php | 0 .../arangodb}/Migration.php | 3 +- .../arangodb}/Query.php | 58 +++++++++++++------ .../arangodb}/Serializer.php | 0 .../console/controllers/MigrateController.php | 0 .../panels/arangodb/ArangoDbPanel.php | 0 .../panels/arangodb/models/ArangoDb.php | 0 .../panels/arangodb/views/detail.php | 0 .../panels/arangodb/views/summary.php | 0 .../arangodb}/views/migration.php | 0 15 files changed, 43 insertions(+), 22 deletions(-) rename mirzaev/{yii2-arangodb => yii2/arangodb}/ActiveQuery.php (100%) rename mirzaev/{yii2-arangodb => yii2/arangodb}/ActiveRecord.php (100%) rename mirzaev/{yii2-arangodb => yii2/arangodb}/AqlExpression.php (100%) rename mirzaev/{yii2-arangodb => yii2/arangodb}/Connection.php (100%) rename mirzaev/{yii2-arangodb => yii2/arangodb}/Exception.php (100%) rename mirzaev/{yii2-arangodb => yii2/arangodb}/Migration.php (99%) rename mirzaev/{yii2-arangodb => yii2/arangodb}/Query.php (96%) rename mirzaev/{yii2-arangodb => yii2/arangodb}/Serializer.php (100%) rename mirzaev/{yii2-arangodb => yii2/arangodb}/console/controllers/MigrateController.php (100%) rename mirzaev/{yii2-arangodb => yii2/arangodb}/panels/arangodb/ArangoDbPanel.php (100%) rename mirzaev/{yii2-arangodb => yii2/arangodb}/panels/arangodb/models/ArangoDb.php (100%) rename mirzaev/{yii2-arangodb => yii2/arangodb}/panels/arangodb/views/detail.php (100%) rename mirzaev/{yii2-arangodb => yii2/arangodb}/panels/arangodb/views/summary.php (100%) rename mirzaev/{yii2-arangodb => yii2/arangodb}/views/migration.php (100%) diff --git a/composer.json b/composer.json index 83ec625..88f920c 100644 --- a/composer.json +++ b/composer.json @@ -34,12 +34,12 @@ }, "autoload": { "psr-4": { - "mirzaev\\yii2\\arangodb\\": "mirzaev/yii2-arangodb" + "mirzaev\\yii2\\arangodb\\": "mirzaev/yii2/arangodb" } }, "autoload-dev": { "psr-4": { - "mirzaev\\yii2\\arangodb\\tests\\": "mirzaev/yii2-arangodb/tests" + "mirzaev\\yii2\\arangodb\\tests\\": "mirzaev/yii2/arangodb/tests" } } } \ No newline at end of file diff --git a/mirzaev/yii2-arangodb/ActiveQuery.php b/mirzaev/yii2/arangodb/ActiveQuery.php similarity index 100% rename from mirzaev/yii2-arangodb/ActiveQuery.php rename to mirzaev/yii2/arangodb/ActiveQuery.php diff --git a/mirzaev/yii2-arangodb/ActiveRecord.php b/mirzaev/yii2/arangodb/ActiveRecord.php similarity index 100% rename from mirzaev/yii2-arangodb/ActiveRecord.php rename to mirzaev/yii2/arangodb/ActiveRecord.php diff --git a/mirzaev/yii2-arangodb/AqlExpression.php b/mirzaev/yii2/arangodb/AqlExpression.php similarity index 100% rename from mirzaev/yii2-arangodb/AqlExpression.php rename to mirzaev/yii2/arangodb/AqlExpression.php diff --git a/mirzaev/yii2-arangodb/Connection.php b/mirzaev/yii2/arangodb/Connection.php similarity index 100% rename from mirzaev/yii2-arangodb/Connection.php rename to mirzaev/yii2/arangodb/Connection.php diff --git a/mirzaev/yii2-arangodb/Exception.php b/mirzaev/yii2/arangodb/Exception.php similarity index 100% rename from mirzaev/yii2-arangodb/Exception.php rename to mirzaev/yii2/arangodb/Exception.php diff --git a/mirzaev/yii2-arangodb/Migration.php b/mirzaev/yii2/arangodb/Migration.php similarity index 99% rename from mirzaev/yii2-arangodb/Migration.php rename to mirzaev/yii2/arangodb/Migration.php index c50aae1..a786c2a 100644 --- a/mirzaev/yii2-arangodb/Migration.php +++ b/mirzaev/yii2/arangodb/Migration.php @@ -22,7 +22,8 @@ abstract class Migration extends Component implements MigrationInterface public function init() { parent::init(); - $this->db = Instance::ensure($this->db, Connection::className()); + + $this->db = Instance::ensure($this->db, Connection::class; } public function execute($aql, $bindValues = [], $params = []) diff --git a/mirzaev/yii2-arangodb/Query.php b/mirzaev/yii2/arangodb/Query.php similarity index 96% rename from mirzaev/yii2-arangodb/Query.php rename to mirzaev/yii2/arangodb/Query.php index 266ecc2..38c5a2f 100644 --- a/mirzaev/yii2-arangodb/Query.php +++ b/mirzaev/yii2/arangodb/Query.php @@ -48,7 +48,7 @@ class Query extends Component implements QueryInterface public string $collection; - public array $vars = []; + public array $lets = []; /** * Массив коллекций вершин и направлений для их обхода @@ -818,14 +818,18 @@ class Query extends Component implements QueryInterface */ protected function genQuery($query = null, array $params = []) { + // Инициализация isset($query) ? $query : $query = $this; + $this->in ?? (isset($this->collection) ? $this->in = $this->collection : throw new Exception('Не найдена коллекция')); + $this->for ?? $this->for = $this->in; + $this->collection ?? $this->collection = $this->in; $params = array_merge($params, $query->params); $clauses = [ static::genFor($query->for ?? $query->collection), static::genIn($query->in ?? $query->collection, $query->traversals), - static::genLet($query->vars), + static::genLet($query->lets), $this->genForeach($query->foreach), $this->genWhere($query->where, $params), isset($this->search) ? $this->genSearch($this->search, $this->searchType) : null, @@ -906,19 +910,24 @@ class Query extends Component implements QueryInterface } /** - * @param $collection * @param $columns * @param array $params * @param null $db + * * @return bool + * * @throws Exception */ - public function insert($collection, $columns, $params = [], $db = null) + public function insert($columns, $params = [], $db = null) { - $doc = Serializer::encode($columns); + // Инициализация + $this->in ?? (isset($this->collection) ? $this->in = $this->collection : throw new Exception('Не найдена коллекция')); + $this->collection ?? $this->collection = $this->in; + + $data = Serializer::encode($columns); $clauses = [ - "INSERT $doc IN {$this->quoteCollectionName($collection)}", + "INSERT $data IN {$this->quoteCollectionName($this->in ?? $this->collection)}", $this->genOptions(), ]; @@ -946,22 +955,26 @@ class Query extends Component implements QueryInterface } /** - * @param $collection * @param $columns - * @param array $condition * @param array $params * @param null $db + * * @return bool + * * @throws Exception */ - public function update($collection, $columns, $condition = [], $params = [], $db = null) + public function update($columns, $params = [], $db = null) { - $this->collection = $collection; + // Инициализация + $this->in ?? (isset($this->collection) ? $this->in = $this->collection : throw new Exception('Не найдена коллекция')); + $this->for ?? $this->for = $this->in; + $this->collection ?? $this->collection = $this->in; + $clauses = [ - $this->genFor($collection), - $this->genIn($collection), - $this->genWhere($condition, $params), - $this->genUpdate($collection, $columns), + static::genFor($this->for ?? $this->collection), + static::genIn($this->in ?? $this->collection, $this->traversals), + $this->genWhere($this->where, $params), + $this->genUpdate($this->collection, $columns), $this->genOptions(), ]; @@ -977,7 +990,9 @@ class Query extends Component implements QueryInterface $statement = $this->getStatement($params, $db); $token = $this->getRawAql($statement); + Yii::info($token, 'mirzaev\yii2\arangodb\Query::update'); + try { Yii::beginProfile($token, 'mirzaev\yii2\arangodb\Query::update'); $cursor = $statement->execute(); @@ -1000,12 +1015,17 @@ class Query extends Component implements QueryInterface * @return bool * @throws Exception */ - public function remove($condition = [], $params = [], $db = null) + public function remove($params = [], $db = null) { + // Инициализация + $this->in ?? (isset($this->collection) ? $this->in = $this->collection : throw new Exception('Не найдена коллекция')); + $this->for ?? $this->for = $this->in; + $this->collection ?? $this->collection = $this->in; + $clauses = [ static::genFor($this->for ?? $this->collection), static::genIn($this->in ?? $this->collection, $this->traversals), - $this->genWhere($condition, $params), + $this->genWhere($this->where, $params), $this->genRemove($this->in ?? $this->collection), $this->genOptions(), ]; @@ -1266,11 +1286,11 @@ class Query extends Component implements QueryInterface /** * @param array $expression */ - public function where($expression) + public function where($expression, $operator = 'AND') { $this->where = match (true) { is_null($this->where) => $expression, - default => ['AND', $this->where, $expression] + default => [$operator, $this->where, $expression] }; return $this; @@ -1280,7 +1300,7 @@ class Query extends Component implements QueryInterface */ public function let(string $name, mixed $value): static { - $this->vars[$name] = $value; + $this->lets[$name] = $value; return $this; } diff --git a/mirzaev/yii2-arangodb/Serializer.php b/mirzaev/yii2/arangodb/Serializer.php similarity index 100% rename from mirzaev/yii2-arangodb/Serializer.php rename to mirzaev/yii2/arangodb/Serializer.php diff --git a/mirzaev/yii2-arangodb/console/controllers/MigrateController.php b/mirzaev/yii2/arangodb/console/controllers/MigrateController.php similarity index 100% rename from mirzaev/yii2-arangodb/console/controllers/MigrateController.php rename to mirzaev/yii2/arangodb/console/controllers/MigrateController.php diff --git a/mirzaev/yii2-arangodb/panels/arangodb/ArangoDbPanel.php b/mirzaev/yii2/arangodb/panels/arangodb/ArangoDbPanel.php similarity index 100% rename from mirzaev/yii2-arangodb/panels/arangodb/ArangoDbPanel.php rename to mirzaev/yii2/arangodb/panels/arangodb/ArangoDbPanel.php diff --git a/mirzaev/yii2-arangodb/panels/arangodb/models/ArangoDb.php b/mirzaev/yii2/arangodb/panels/arangodb/models/ArangoDb.php similarity index 100% rename from mirzaev/yii2-arangodb/panels/arangodb/models/ArangoDb.php rename to mirzaev/yii2/arangodb/panels/arangodb/models/ArangoDb.php diff --git a/mirzaev/yii2-arangodb/panels/arangodb/views/detail.php b/mirzaev/yii2/arangodb/panels/arangodb/views/detail.php similarity index 100% rename from mirzaev/yii2-arangodb/panels/arangodb/views/detail.php rename to mirzaev/yii2/arangodb/panels/arangodb/views/detail.php diff --git a/mirzaev/yii2-arangodb/panels/arangodb/views/summary.php b/mirzaev/yii2/arangodb/panels/arangodb/views/summary.php similarity index 100% rename from mirzaev/yii2-arangodb/panels/arangodb/views/summary.php rename to mirzaev/yii2/arangodb/panels/arangodb/views/summary.php diff --git a/mirzaev/yii2-arangodb/views/migration.php b/mirzaev/yii2/arangodb/views/migration.php similarity index 100% rename from mirzaev/yii2-arangodb/views/migration.php rename to mirzaev/yii2/arangodb/views/migration.php