Skip to content

Commit

Permalink
Prepare to release (#187)
Browse files Browse the repository at this point in the history
Co-authored-by: Maxim Smakouz <m.smakouz@gmail.com>
Co-authored-by: Alexander Makarov <sam@rmcreative.ru>
  • Loading branch information
3 people committed Feb 28, 2024
1 parent 814dede commit 866b206
Show file tree
Hide file tree
Showing 30 changed files with 225 additions and 380 deletions.
2 changes: 1 addition & 1 deletion .phpstorm.meta.php
Expand Up @@ -3,7 +3,7 @@
namespace PHPSTORM_META {

expectedArguments(
\Yiisoft\Yii\Cycle\Schema\Conveyor\AnnotatedSchemaConveyor::setTableNaming(),
\Yiisoft\Yii\Cycle\Schema\Conveyor\MetadataSchemaConveyor::addGenerator(),
0,
argumentsSet('\Cycle\Annotated\Entities::TABLE_NAMINGS'),
);
Expand Down
1 change: 1 addition & 0 deletions composer.json
Expand Up @@ -46,6 +46,7 @@
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^4.30|^5.7",
"yiisoft/definitions": "^3.2",
"yiisoft/di": "^1.2",
"yiisoft/test-support": "^3.0"
},
"autoload": {
Expand Down
21 changes: 4 additions & 17 deletions config/di.php
Expand Up @@ -26,7 +26,6 @@
use Yiisoft\Yii\Cycle\Factory\CycleDynamicFactory;
use Yiisoft\Yii\Cycle\Factory\DbalFactory;
use Yiisoft\Yii\Cycle\Factory\OrmFactory;
use Yiisoft\Yii\Cycle\Schema\Conveyor\CompositeSchemaConveyor;
use Yiisoft\Yii\Cycle\Schema\Conveyor\MetadataSchemaConveyor;
use Yiisoft\Yii\Cycle\Schema\SchemaConveyorInterface;

Expand Down Expand Up @@ -92,20 +91,8 @@
],

// Schema Conveyor
SchemaConveyorInterface::class => static function (ContainerInterface $container) use (&$params) {
/** @var SchemaConveyorInterface $conveyor */
$conveyor = $container->get($params['yiisoft/yii-cycle']['conveyor'] ?? CompositeSchemaConveyor::class);

if ($conveyor instanceof MetadataSchemaConveyor) {
// deprecated option
if (\array_key_exists('annotated-entity-paths', $params['yiisoft/yii-cycle'])) {
$conveyor->addEntityPaths($params['yiisoft/yii-cycle']['annotated-entity-paths']);
}
// actual option
if (\array_key_exists('entity-paths', $params['yiisoft/yii-cycle'])) {
$conveyor->addEntityPaths($params['yiisoft/yii-cycle']['entity-paths']);
}
}
return $conveyor;
},
SchemaConveyorInterface::class => [
'class' => MetadataSchemaConveyor::class,
'addEntityPaths()' => $params['yiisoft/yii-cycle']['entity-paths'] ?? [],
],
];
7 changes: 1 addition & 6 deletions config/params.php
Expand Up @@ -6,7 +6,6 @@
use Cycle\Schema\Provider\Support\SchemaProviderPipeline;
use Yiisoft\Yii\Cycle\Command\Schema;
use Yiisoft\Yii\Cycle\Command\Migration;
use Yiisoft\Yii\Cycle\Schema\Conveyor\CompositeSchemaConveyor;

return [
// Console commands
Expand Down Expand Up @@ -81,13 +80,9 @@
],

/**
* Annotated/attributed entity directories list.
* An attributed entity directory list.
* {@see \Yiisoft\Aliases\Aliases} are also supported.
*/
'entity-paths' => [],
'conveyor' => CompositeSchemaConveyor::class,

/** @deprecated use `entity-paths` key instead */
'annotated-entity-paths' => [],
],
];
34 changes: 13 additions & 21 deletions docs/en/installation.md
Expand Up @@ -3,7 +3,7 @@
The preferred way to install this package is through [Composer](https://getcomposer.org/download/):

```bash
composer require yiisoft/yii-cycle "2.0.x-dev"
composer require yiisoft/yii-cycle
```

## Configuring package
Expand All @@ -13,18 +13,16 @@ If you use Yii with `composer-config-plugin`, Yii-Cycle settings could be specif
```php
<?php
use Cycle\Schema\Generator;
use Yiisoft\Yii\Cycle\Schema\Conveyor\AttributedSchemaConveyor;
use Cycle\Schema\Provider\FromFilesSchemaProvider;
use Cycle\Schema\Provider\SimpleCacheSchemaProvider;
use Yiisoft\Yii\Cycle\Schema\Provider\FromConveyorSchemaProvider;

return [
// Common Cycle config
'yiisoft/yii-cycle' => [
// Cycle DBAL config
'dbal' => [
/**
* SQL query logger
* You may use {@see \Yiisoft\Yii\Cycle\Logger\StdoutQueryLogger} class to pass log to
* stdout or any PSR-compatible logger
*/
// PSR-3 compatible SQL query logger
'query-logger' => null,
// Default database (from 'databases' list)
'default' => 'default',
Expand Down Expand Up @@ -58,28 +56,22 @@ return [
* and its config as value:
*/
'schema-providers' => [
\Yiisoft\Yii\Cycle\Schema\Provider\SimpleCacheSchemaProvider::class => [
'key' => 'my-custom-cache-key'
],
\Yiisoft\Yii\Cycle\Schema\Provider\FromFilesSchemaProvider::class => [
'files' => ['@runtime/cycle-schema.php']
],
\Yiisoft\Yii\Cycle\Schema\Provider\FromConveyorSchemaProvider::class,
SimpleCacheSchemaProvider::class => SimpleCacheSchemaProvider::config(
key: 'my-custom-cache-key'
),
FromFilesSchemaProvider::class => FromFilesSchemaProvider::config(
files: ['@runtime/cycle-schema.php'],
),
FromConveyorSchemaProvider::class,
],

/**
* Option for {@see \Yiisoft\Yii\Cycle\Schema\Conveyor\MetadataSchemaConveyor}.
* Option for {@see \Yiisoft\Yii\Cycle\Schema\Provider\FromConveyorSchemaProvider}.
* A list of entity directories. You can use {@see \Yiisoft\Aliases\Aliases} in paths.
*/
'entity-paths' => [
'@src/Entity'
],
/**
* {@see \Yiisoft\Yii\Cycle\Schema\Conveyor\SchemaConveyorInterface} implementation class name.
* That implementation defines the entity data source: annotations, attributes or both.
* Can be `AttributedSchemaConveyor`, `AnnotatedSchemaConveyor` or `CompositeSchemaConveyor`
*/
'conveyor-class' => AttributedSchemaConveyor::class,
],
];
```
Expand Down
29 changes: 17 additions & 12 deletions docs/en/reading-schema.md
Expand Up @@ -15,18 +15,18 @@ Arrage schema providers in such an order, that caching providers are at the top
and origin schema providers at the end.


## Entity annotation based schema
## Entity attributes based schema

By default, schema is built based on annotations that are in your project entities.
By default, schema is built based on attributes that are in your project entities.

When building a schema generators are executed sequentially. The sequence is determined in an instance of
`SchemaConveyorInterface`. You can insert your own generators in this conveyor by defining them in
`entity-paths` option of `config/params.php` file.

In order to get a schema from conveyor `FromConveyorSchemaProvider` is used.
To get a schema from conveyor `FromConveyorSchemaProvider` is used.

The process of building schema from annotations is relatively heavy in terms of performance. Therefore, in case of
using annotations it is a good idea to use schema cache.
The process of building schema from attributes is relatively heavy in terms of performance. Therefore, in the case of
using attributes, it is a good idea to use schema cache.

## Schema cache

Expand All @@ -36,20 +36,22 @@ Place it to the beginning of providers list to make the process of obtaining a s

## File-based schema

If you want to avoid annotations, you can describe a schema in a PHP file.
If you want to avoid attributes, you can describe a schema in a PHP file.
Use `Cycle\Schema\Provider\FromFilesSchemaProvider` to load a schema:

```php
# config/common.php
[
use Cycle\Schema\Provider\FromFilesSchemaProvider;

return [
// ...
'yiisoft/yii-cycle' => [
// ...
'schema-providers' => [
\Cycle\Schema\Provider\FromFilesSchemaProvider::class => [
'files' => '@runtime/schema.php'
]
FromFilesSchemaProvider::class => FromFilesSchemaProvider::config(fiels: ['@runtime/schema.php']),
],
]
];
```

```php
Expand Down Expand Up @@ -99,8 +101,11 @@ return [
'schema-providers' => [
\Cycle\Schema\Provider\MergeSchemaProvider::class => [
// You can specify the provider class as the key and the configuration as the value.
// To generate a configuration array, you can use the static method `config()` of the
// provider class. In this case, autocomplete will be available.
\Cycle\Schema\Provider\FromFilesSchemaProvider::class => ['files' => ['@src/schema.php']],
// The provider and its configuration can be passed as an array.
// If you need to use multiple identically named schema providers,
// the provider and its configuration can be passed as an array of two elements.
[\Cycle\Schema\Provider\SimpleCacheSchemaProvider::class, ['key' => 'cycle-schema']],
// When defining the dependency as a string, make sure the container provides
// the already configured provider.
Expand All @@ -111,7 +116,7 @@ return [
];
```

## Switching from annotations to file
## Switching from attributes to file

### Console command

Expand Down
32 changes: 12 additions & 20 deletions docs/es/installation.md
Expand Up @@ -13,18 +13,16 @@ Si utiliza `yiisoft/config`, la configuración de `yisoft/yii-cycle` se debe esp
```php
<?php
use Cycle\Schema\Generator;
use Yiisoft\Yii\Cycle\Schema\Conveyor\AttributedSchemaConveyor;
use Cycle\Schema\Provider\FromFilesSchemaProvider;
use Cycle\Schema\Provider\SimpleCacheSchemaProvider;
use Yiisoft\Yii\Cycle\Schema\Provider\FromConveyorSchemaProvider;

return [
// Configuración de Cycle común
'yiisoft/yii-cycle' => [
// Configuración de Cycle DBAL
'dbal' => [
/**
* SQL query logger
* Puedes usar la clase {@see \Yiisoft\Yii\Cycle\Logger\StdoutQueryLogger} para pasar el registro a
* stdout o cualquier logger PSR-compatible.
*/
// PSR-3 SQL query logger
'query-logger' => null,
// Bases de datos por defecto (De la lista 'databases')
'default' => 'default',
Expand Down Expand Up @@ -58,28 +56,22 @@ return [
* y su configuración como valor:
*/
'schema-providers' => [
\Yiisoft\Yii\Cycle\Schema\Provider\SimpleCacheSchemaProvider::class => [
'key' => 'my-custom-cache-key'
],
\Yiisoft\Yii\Cycle\Schema\Provider\FromFilesSchemaProvider::class => [
'files' => ['@runtime/cycle-schema.php']
],
\Yiisoft\Yii\Cycle\Schema\Provider\FromConveyorSchemaProvider::class,
SimpleCacheSchemaProvider::class => SimpleCacheSchemaProvider::config(
key: 'my-custom-cache-key'
),
FromFilesSchemaProvider::class => FromFilesSchemaProvider::config(
files: ['@runtime/cycle-schema.php'],
),
FromConveyorSchemaProvider::class,
],

/**
* Opción para {@see \Yiisoft\Yii\Cycle\Schema\Conveyor\MetadataSchemaConveyor}.
* Opción para {@see \Yiisoft\Yii\Cycle\Schema\Provider\FromConveyorSchemaProvider}.
* Una lista de directorios de entidades. Puede utilizar {@see \Yiisoft\Aliases\Aliases} en las rutas.
*/
'entity-paths' => [
'@src/Entity'
],
/**
* {@see \Yiisoft\Yii\Cycle\Schema\Conveyor\SchemaConveyorInterface} Implementación del class name.
* Esa implementación define la fuente de datos de la entidad: anotaciones, atributos o ambos.
* Pueden ser `AttributedSchemaConveyor`, `AnnotatedSchemaConveyor` o `CompositeSchemaConveyor`
*/
'conveyor-class' => AttributedSchemaConveyor::class,
],
];
```
Expand Down
28 changes: 17 additions & 11 deletions docs/es/reading-schema.md
Expand Up @@ -14,18 +14,19 @@ de agrupación. Puede configurar este proveedor en la sección `schema-providers
Los proveedores de esquemas deben estar organizados de la siguiente manera, los proveedores de caché deben estar al principio de la lista y los proveedores de esquemas de origen al final.


## Esquema basado en la anotación de entidades
## Esquema basado en atributos de entidades

Por defecto, el esquema se construye en base a las anotaciones que se encuentran en las entidades de su proyecto.
Por defecto, el esquema se construye basado en los atributos que están en las entidades de su proyecto.

Cuando se construye un esquema, los generadores se ejecutan secuencialmente. La secuencia se determina en una instancia de
`SchemaConveyorInterface`. Puede insertar sus propios generadores dentro del transpotador, para ello debe especificarlos en
`entity-paths` dentro del archivo `config/params.php`.

Para obtener un esquema del transportador se usa la clase `FromConveyorSchemaProvider`.

El proceso de construcción de esquemas a partir de anotaciones es relativamente pesado en términos de rendimiento. Por lo tanto, en caso de
usar anotaciones es una buena idea usar el caché de esquemas.
El proceso de construcción de esquemas a partir de atributos es relativamente pesado en términos de rendimiento. Por lo tanto, en caso de
usar atributos es una buena idea usar el caché de esquemas.


## Esquemas desde caché

Expand All @@ -35,20 +36,22 @@ Debe indicarse al principio de la lista de proveedores para que el proceso de ob

## Esquemas basados en archivos

Si quiere evitar las anotaciones, puede describir un esquema en un archivo PHP.
Si quiere evitar las atributos, puede describir un esquema en un archivo PHP.
Utilice `Cycle\Schema\Provider\FromFilesSchemaProvider` para cargar un esquema:

```php
# config/common.php
[
use Cycle\Schema\Provider\FromFilesSchemaProvider;

return [
// ...
'yiisoft/yii-cycle' => [
// ...
'schema-providers' => [
\Cycle\Schema\Provider\FromFilesSchemaProvider::class => [
'files' => '@runtime/schema.php'
]
FromFilesSchemaProvider::class => FromFilesSchemaProvider::config(fiels: ['@runtime/schema.php']),
],
]
];
```

```php
Expand Down Expand Up @@ -98,8 +101,11 @@ return [
'schema-providers' => [
\Cycle\Schema\Provider\MergeSchemaProvider::class => [
// Puede especificar la clase de proveedor como clave y la configuración como valor.
// Para generar un arreglo de configuración, puede utilizar el método estático `config()` de
// la clase del proveedor. En este caso, estará disponible el autocompletado.
\Cycle\Schema\Provider\FromFilesSchemaProvider::class => ['files' => ['@src/schema.php']],
// El proveedor y su configuración pueden pasarse como un array.
// Si necesita utilizar varios proveedores de esquemas con el mismo nombre,
// el proveedor y su configuración se pueden pasar como un arreglo de dos elementos.
[\Cycle\Schema\Provider\SimpleCacheSchemaProvider::class, ['key' => 'cycle-schema']],
// Al definir la dependencia como una cadena, asegúrese de que el contenedor proporciona
// el proveedor ya configurado.
Expand All @@ -110,7 +116,7 @@ return [
];
```

## Pasar de las anotaciones al archivo
## Pasar de las atributos al archivo

### Comando de consola

Expand Down

0 comments on commit 866b206

Please sign in to comment.