Skip to content

Commit d464e45

Browse files
authored
Merge pull request #9 from wayofdev/feat/labels
2 parents f8bdbb3 + 7bf270a commit d464e45

File tree

12 files changed

+487
-156
lines changed

12 files changed

+487
-156
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ prepare:
124124
# ------------------------------------------------------------------------------------
125125
up: # Creates and starts containers, defined in docker-compose and override file
126126
$(DOCKER_COMPOSE) up --remove-orphans -d
127-
$(DOCKER_COMPOSE) exec app wait4x tcp database:5432 -t 1m
127+
$(DOCKER_COMPOSE) exec app wait4x postgresql 'postgres://${DB_USERNAME}:${DB_PASSWORD}@database:5432/${DB_DATABASE}?sslmode=disable' -t 1m
128128
.PHONY: up
129129

130130
down: # Stops and removes containers of this project

app/composer.lock

Lines changed: 103 additions & 100 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/config/auth.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,9 @@
5252
*/
5353
'providers' => [
5454
'users' => [
55-
'driver' => 'eloquent',
56-
'model' => \Domain\User\Models\User::class,
55+
'driver' => 'database',
56+
'table' => 'users',
5757
],
58-
59-
// 'users' => [
60-
// 'driver' => 'database',
61-
// 'table' => 'users',
62-
// ],
6358
],
6459

6560
/*

app/config/cycle.php

Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
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+
];
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Migration;
6+
7+
use Cycle\Migrations\Migration;
8+
9+
class OrmDefault9296507f0aee2fd6fb380d0901b971a3 extends Migration
10+
{
11+
protected const DATABASE = 'default';
12+
13+
public function up(): void
14+
{
15+
$this->table('users')
16+
->addColumn('incremental_id', 'bigInteger', ['nullable' => false, 'default' => null])
17+
->addColumn('email', 'string', ['nullable' => true, 'default' => null, 'size' => 255])
18+
->addColumn('company', 'string', ['nullable' => true, 'default' => null, 'size' => 255])
19+
->addColumn('name', 'string', ['nullable' => false, 'default' => null, 'size' => 255])
20+
->setPrimaryKeys(['incremental_id'])
21+
->create();
22+
$this->table('roles')
23+
->addColumn('id', 'primary', ['nullable' => false, 'default' => null])
24+
->addColumn('name', 'string', ['nullable' => false, 'default' => null, 'size' => 255])
25+
->addColumn('user_incrementalId', 'bigInteger', ['nullable' => false, 'default' => null])
26+
->addIndex(['user_incrementalId'], ['name' => 'roles_index_user_incrementalid_646522feb8e5f', 'unique' => false])
27+
->addForeignKey(['user_incrementalId'], 'users', ['incremental_id'], [
28+
'name' => 'roles_foreign_user_incrementalid_646522feb8e6c',
29+
'delete' => 'CASCADE',
30+
'update' => 'CASCADE',
31+
'indexCreate' => true,
32+
])
33+
->setPrimaryKeys(['id'])
34+
->create();
35+
}
36+
37+
public function down(): void
38+
{
39+
$this->table('roles')->drop();
40+
$this->table('users')->drop();
41+
}
42+
}

app/src/Bridge/Laravel/Providers/RouteServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ final class RouteServiceProvider extends ServiceProvider
2727
public function boot(): void
2828
{
2929
RateLimiter::for('api', function (Request $request) {
30-
return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
30+
return Limit::perMinute(60)->by($request->user()?->incrementalId ?: $request->ip());
3131
});
3232

3333
$this->routes(function (): void {

app/src/Domain/Role/Role.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Domain\Role;
6+
7+
use Cycle\Annotated\Annotation\Column;
8+
use Cycle\Annotated\Annotation\Entity;
9+
10+
#[Entity(repository: RoleRepository::class)]
11+
class Role
12+
{
13+
#[Column(type: 'primary')]
14+
public int $id;
15+
16+
#[Column(type: 'string')]
17+
public string $name;
18+
19+
public function __construct(string $name)
20+
{
21+
$this->name = $name;
22+
}
23+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Domain\Role;
6+
7+
use Cycle\ORM\RepositoryInterface;
8+
9+
interface RoleRepository extends RepositoryInterface
10+
{
11+
public function findById(string $id): ?object;
12+
}

0 commit comments

Comments
 (0)