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