|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +use Cycle\Annotated; |
| 6 | +use Cycle\Database\Config; |
| 7 | +use Cycle\Database\Driver; |
| 8 | +use Cycle\ORM\Collection; |
| 9 | +use Cycle\ORM\SchemaInterface; |
| 10 | +use Cycle\Schema; |
| 11 | +use WayOfDev\Cycle\Contracts\GeneratorLoader; |
| 12 | + |
| 13 | +return [ |
| 14 | + /* |
| 15 | + * Where ClassLocator should search for entities and embeddings. |
| 16 | + * Important: By default, Laravel's application skeleton has its Model classes in the app/Models folder. |
| 17 | + * With Cycle you'll need to create a dedicated folder for your Entities and point your config/cycle.php |
| 18 | + * paths array to it. If you don't, Cycle will scan your whole app/ folder for files, |
| 19 | + * which will have a huge impact on performance! |
| 20 | + */ |
| 21 | + 'tokenizer' => [ |
| 22 | + /* |
| 23 | + * Where should class locator scan for entities? |
| 24 | + */ |
| 25 | + 'directories' => [ |
| 26 | + __DIR__ . '/../src/Domain', |
| 27 | + ], |
| 28 | + |
| 29 | + /* |
| 30 | + * Directories, to exclude from Entity search |
| 31 | + */ |
| 32 | + 'exclude' => [ |
| 33 | + 'Console', |
| 34 | + 'Exceptions', |
| 35 | + 'Http', |
| 36 | + 'Providers', |
| 37 | + ], |
| 38 | + |
| 39 | + /* |
| 40 | + * Scopes to use when searching for entities |
| 41 | + */ |
| 42 | + 'scopes' => [], |
| 43 | + |
| 44 | + /* |
| 45 | + * Should class locator scan for entities in debug mode? |
| 46 | + */ |
| 47 | + 'debug' => env('APP_DEBUG', false), |
| 48 | + |
| 49 | + /* |
| 50 | + * Should class locator cache the results? |
| 51 | + */ |
| 52 | + 'cache' => [ |
| 53 | + 'directory' => null, |
| 54 | + 'enabled' => false, |
| 55 | + ], |
| 56 | + ], |
| 57 | + |
| 58 | + 'database' => [ |
| 59 | + /* |
| 60 | + * Default database connection |
| 61 | + */ |
| 62 | + 'default' => env('DB_DEFAULT_CONNECTION', 'default'), |
| 63 | + |
| 64 | + /* |
| 65 | + * The Cycle/Database module provides support to manage multiple databases |
| 66 | + * in one application, use read/write connections and logically separate |
| 67 | + * multiple databases within one connection using prefixes. |
| 68 | + * |
| 69 | + * To register a new database simply add a new one into |
| 70 | + * "databases" section below. |
| 71 | + */ |
| 72 | + 'databases' => [ |
| 73 | + 'default' => [ |
| 74 | + 'driver' => env('DB_CONNECTION', 'sqlite'), |
| 75 | + ], |
| 76 | + ], |
| 77 | + |
| 78 | + /* |
| 79 | + * Configuring connections, see: |
| 80 | + * https://cycle-orm.dev/docs/database-connect/2.x/en |
| 81 | + * |
| 82 | + * Each database instance must have an associated connection object. |
| 83 | + * Connections used to provide low-level functionality and wrap different |
| 84 | + * database drivers. To register a new connection you have to specify |
| 85 | + * the driver class and its connection options. |
| 86 | + */ |
| 87 | + 'drivers' => [ |
| 88 | + /* |
| 89 | + * Setup sqlite database in-memory for testing purposes |
| 90 | + */ |
| 91 | + 'sqlite' => new Config\SQLiteDriverConfig( |
| 92 | + connection: new Config\SQLite\MemoryConnectionConfig(), |
| 93 | + queryCache: true |
| 94 | + ), |
| 95 | + |
| 96 | + 'pgsql' => new Config\PostgresDriverConfig( |
| 97 | + connection: new Config\Postgres\TcpConnectionConfig( |
| 98 | + database: env('DB_DATABASE', 'wod'), |
| 99 | + host: env('DB_HOST', '127.0.0.1'), |
| 100 | + port: env('DB_PORT', 5432), |
| 101 | + user: env('DB_USERNAME', 'wod'), |
| 102 | + password: env('DB_PASSWORD', '') |
| 103 | + ), |
| 104 | + schema: Config\PostgresDriverConfig::DEFAULT_SCHEMA, |
| 105 | + driver: Driver\Postgres\PostgresDriver::class, |
| 106 | + reconnect: true, |
| 107 | + timezone: 'UTC', |
| 108 | + queryCache: true |
| 109 | + ), |
| 110 | + |
| 111 | + 'mysql' => new Config\MySQLDriverConfig( |
| 112 | + connection: new Config\MySQL\TcpConnectionConfig( |
| 113 | + database: env('DB_DATABASE', 'wod'), |
| 114 | + host: env('DB_HOST', '127.0.0.1'), |
| 115 | + port: env('DB_PORT', 3306), |
| 116 | + user: env('DB_USERNAME', 'wod'), |
| 117 | + password: env('DB_PASSWORD', '') |
| 118 | + ), |
| 119 | + driver: Driver\MySQL\MySQLDriver::class, |
| 120 | + reconnect: true, |
| 121 | + timezone: 'UTC', |
| 122 | + queryCache: true, |
| 123 | + ), |
| 124 | + |
| 125 | + 'sqlserver' => new Config\SQLServerDriverConfig( |
| 126 | + connection: new Config\SQLServer\TcpConnectionConfig( |
| 127 | + database: env('DB_DATABASE', 'wod'), |
| 128 | + host: env('DB_HOST', '127.0.0.1'), |
| 129 | + port: env('DB_PORT', 1433), |
| 130 | + user: env('DB_USERNAME', 'wod'), |
| 131 | + password: env('DB_PASSWORD', '') |
| 132 | + ), |
| 133 | + driver: Driver\SQLServer\SQLServerDriver::class, |
| 134 | + reconnect: true, |
| 135 | + timezone: 'UTC', |
| 136 | + queryCache: true, |
| 137 | + ), |
| 138 | + ], |
| 139 | + ], |
| 140 | + |
| 141 | + 'schema' => [ |
| 142 | + /* |
| 143 | + * true (Default) - Schema will be stored in a cache after compilation. |
| 144 | + * It won't be changed after entity modification. Use `php app.php cycle` to update schema. |
| 145 | + * |
| 146 | + * false - Schema won't be stored in a cache after compilation. |
| 147 | + * It will be automatically changed after entity modification. (Development mode) |
| 148 | + */ |
| 149 | + 'cache' => [ |
| 150 | + 'enabled' => env('CYCLE_SCHEMA_CACHE', true), |
| 151 | + 'store' => env('CACHE_DRIVER', 'file'), |
| 152 | + ], |
| 153 | + |
| 154 | + /* |
| 155 | + * The CycleORM provides the ability to manage default settings for |
| 156 | + * every schema with not defined segments |
| 157 | + */ |
| 158 | + 'defaults' => [ |
| 159 | + SchemaInterface::MAPPER => \Cycle\ORM\Mapper\Mapper::class, |
| 160 | + SchemaInterface::REPOSITORY => \Cycle\ORM\Select\Repository::class, |
| 161 | + SchemaInterface::SCOPE => null, |
| 162 | + SchemaInterface::TYPECAST_HANDLER => [ |
| 163 | + // \Cycle\ORM\Parser\Typecast::class, \App\Infrastructure\CycleORM\Typecaster\UuidTypecast::class, |
| 164 | + ], |
| 165 | + ], |
| 166 | + |
| 167 | + 'collections' => [ |
| 168 | + 'default' => env('DB_DEFAULT_COLLECTION', 'illuminate'), |
| 169 | + 'factories' => [ |
| 170 | + 'array' => Collection\ArrayCollectionFactory::class, |
| 171 | + 'illuminate' => Collection\IlluminateCollectionFactory::class, |
| 172 | + 'doctrine' => Collection\DoctrineCollectionFactory::class, |
| 173 | + ], |
| 174 | + ], |
| 175 | + |
| 176 | + /* |
| 177 | + * Schema generators (Optional) |
| 178 | + * null (default) - Will be used schema generators defined in bootloaders |
| 179 | + */ |
| 180 | + 'generators' => [ |
| 181 | + GeneratorLoader::GROUP_INDEX => [ |
| 182 | + // Register embeddable entities |
| 183 | + Annotated\Embeddings::class, |
| 184 | + // Register annotated entities |
| 185 | + Annotated\Entities::class, |
| 186 | + // Register STI/JTI |
| 187 | + Annotated\TableInheritance::class, |
| 188 | + // Add @Table column declarations |
| 189 | + Annotated\MergeColumns::class, |
| 190 | + ], |
| 191 | + GeneratorLoader::GROUP_RENDER => [ |
| 192 | + // Re-declared table schemas (remove columns) |
| 193 | + Schema\Generator\ResetTables::class, |
| 194 | + // Generate entity relations |
| 195 | + Schema\Generator\GenerateRelations::class, |
| 196 | + // Generate changes from schema modifiers |
| 197 | + Schema\Generator\GenerateModifiers::class, |
| 198 | + // Make sure all entity schemas are correct |
| 199 | + Schema\Generator\ValidateEntities::class, |
| 200 | + // Declare table schemas |
| 201 | + Schema\Generator\RenderTables::class, |
| 202 | + // Declare relation keys and indexes |
| 203 | + Schema\Generator\RenderRelations::class, |
| 204 | + // Render all schema modifiers |
| 205 | + Schema\Generator\RenderModifiers::class, |
| 206 | + // Add @Table column declarations |
| 207 | + Annotated\MergeIndexes::class, |
| 208 | + ], |
| 209 | + GeneratorLoader::GROUP_POSTPROCESS => [ |
| 210 | + // Typecast non string columns |
| 211 | + Schema\Generator\GenerateTypecast::class, |
| 212 | + ], |
| 213 | + ], |
| 214 | + ], |
| 215 | + |
| 216 | + 'migrations' => [ |
| 217 | + 'directory' => database_path('migrations/cycle'), |
| 218 | + |
| 219 | + 'table' => env('DB_MIGRATIONS_TABLE', 'cycle_migrations'), |
| 220 | + |
| 221 | + 'safe' => env('APP_ENV') !== 'production', |
| 222 | + ], |
| 223 | + |
| 224 | + /* |
| 225 | + * Enable schema cache warmup |
| 226 | + */ |
| 227 | + 'warmup' => env('CYCLE_SCHEMA_WARMUP', false), |
| 228 | + |
| 229 | + /* |
| 230 | + * Custom relation types for entities |
| 231 | + */ |
| 232 | + 'customRelations' => [ |
| 233 | + // \Cycle\ORM\Relation::EMBEDDED => [ |
| 234 | + // \Cycle\ORM\Config\RelationConfig::LOADER => \Cycle\ORM\Select\Loader\EmbeddedLoader::class, |
| 235 | + // \Cycle\ORM\Config\RelationConfig::RELATION => \Cycle\ORM\Relation\Embedded::class, |
| 236 | + // ], |
| 237 | + ], |
| 238 | +]; |
0 commit comments