Skip to content

Commit 85e7485

Browse files
authored
Merge pull request #659 from wayofdev/feat/laravel-services
2 parents b349e16 + 1738aea commit 85e7485

File tree

25 files changed

+653
-63
lines changed

25 files changed

+653
-63
lines changed

config/cycle.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,4 +324,25 @@
324324
'entityBehavior' => [
325325
'register' => env('CYCLE_REGISTER_ENTITY_BEHAVIOUR', true),
326326
],
327+
328+
'integrations' => [
329+
/*
330+
* Enables migration generation for Laravel Queues
331+
*/
332+
'queue' => [
333+
'enabled' => env('CYCLE_ADAPTER_QUEUE_INTEGRATION', true),
334+
],
335+
/*
336+
* Enables migration generation for Laravel Sessions
337+
*/
338+
'session' => [
339+
'enabled' => env('CYCLE_ADAPTER_SESSION_INTEGRATION', true),
340+
],
341+
/*
342+
* Enables migration generation for Laravel Cache
343+
*/
344+
'cache' => [
345+
'enabled' => env('CYCLE_ADAPTER_CACHE_INTEGRATION', true),
346+
],
347+
],
327348
];

docs/pages/services/_meta.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,8 @@
44
"testing": "Testing",
55
"validation": "Validation",
66
"pagination": "Pagination",
7+
"sessions": "Sessions",
8+
"queue": "Queue",
9+
"cache": "Cache",
710
"laravel-telescope": "Laravel Telescope"
811
}

docs/pages/services/cache.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Cache

docs/pages/services/laravel-telescope.mdx

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,30 @@ Install, telescope as usual, via Composer package manager:
2121
composer require laravel/telescope
2222
```
2323

24-
### Step 2: Publish Telescope Assets
24+
### Step 2: Add .env Configuration
25+
26+
Add the following configuration to your `.env` file:
27+
28+
```dotenv filename=".env"
29+
...
30+
31+
DB_USE_TELESCOPE_LOGGER=true
32+
33+
...
34+
```
35+
36+
### Step 3: Publish Telescope Assets
2537

2638
After installing Telescope, publish its assets and migrations using the `telescope:install` Artisan command.
2739

2840
```bash
2941
php artisan telescope:install
3042
```
3143

32-
### Step 3: Run Telescope Migrations trough Cycle-ORM-Adapter
44+
### Step 4: Run Telescope Migrations trough Cycle-ORM-Adapter
3345

3446
After installing Telescope, you should also run the migrate command in order to create the tables needed to store Telescope's data, but as you are using Cycle ORM, you should avoid using default `php artisan migrate` command, and instead, do the following steps:
3547

36-
Edit `config/cycle.php` file and add the following code to the `tokenizer.directories` array:
37-
38-
```php {7} filename="config/cycle.php"
39-
return [
40-
// ...
41-
'tokenizer' => [
42-
// ...
43-
'directories' => [
44-
app_path(),
45-
__DIR__ . '/../vendor/wayofdev/laravel-cycle-orm-adapter/src/Bridge/Telescope/Entities',
46-
],
47-
],
48-
],
49-
```
50-
5148
Run the following command to create the Telescope tables:
5249

5350
```bash
@@ -56,8 +53,7 @@ php artisan cycle:migrate:init
5653
php artisan cycle:orm:migrate --split --run
5754
```
5855

59-
60-
### Step 4: Add the CycleORM Query Watcher
56+
### Step 5: Add the CycleORM Query Watcher
6157

6258
Next, edit your `config/telescope.php` configuration file and add the following lines to the `watchers` array, right after the default`Watchers\QueryWatcher::class` line:
6359

@@ -85,18 +81,6 @@ return [
8581
];
8682
```
8783

88-
### Step 5: Add .env Configuration
89-
90-
Add the following configuration to your `.env` file:
91-
92-
```dotenv filename=".env"
93-
...
94-
95-
DB_USE_TELESCOPE_LOGGER=true
96-
97-
...
98-
```
99-
10084
### Step 6: Access Laravel Telescope
10185

10286
Finally, you may access the Telescope dashboard via the `/telescope` route. Of course, don't forget to start your Laravel application:

docs/pages/services/pagination.mdx

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,68 @@ Pagination is provided by external package [wayofdev/laravel-paginator](https://
88
composer require wayofdev/laravel-paginator
99
```
1010

11-
## Usage
11+
## Usage with Repositories
1212

1313
<div className="steps-container">
1414

1515
### Step 1: Define `paginate()` method in your Repository
1616

17-
@todo
17+
Create a `paginate()` method in your abstract repository class that will return a `CyclePaginator` instance.
18+
19+
```php filename="app/Infrastructure/Persistence/Cycle/Repository.php"
20+
<?php
21+
22+
declare(strict_types=1);
23+
24+
namespace Infrastructure\Persistence\Cycle;
25+
26+
use Cycle\ORM\EntityManagerInterface;
27+
use Cycle\ORM\Select;
28+
use Cycle\ORM\Select\Repository as CycleRepository;
29+
use Illuminate\Support\Collection;
30+
use Spiral\Pagination\Paginator as SpiralPaginator;
31+
use WayOfDev\Paginator\CyclePaginator;
32+
33+
class Repository extends CycleRepository
34+
{
35+
/**
36+
* Create repository linked to one specific selector.
37+
*
38+
* @param Select<TEntity> $select
39+
*/
40+
public function __construct(
41+
protected Select $select,
42+
protected EntityManagerInterface $entityManager
43+
) {
44+
parent::__construct($select);
45+
}
46+
47+
// ...
48+
49+
public function paginate(int $perPage = 20, int $page = 1, string $pageName = 'page'): CyclePaginator
50+
{
51+
return $this->paginateQuery(
52+
$this->select(),
53+
$perPage,
54+
$page,
55+
$pageName,
56+
);
57+
}
58+
59+
protected function paginateQuery(Select $query, int $perPage = 20, int $page = 1, string $pageName = 'page'): CyclePaginator
60+
{
61+
return new CyclePaginator(
62+
(new SpiralPaginator($perPage))->withPage($page)->paginate($query),
63+
$this->createCollection($query->fetchAll()),
64+
$pageName,
65+
);
66+
}
67+
68+
protected function createCollection(iterable $items): Collection
69+
{
70+
return new Collection($items);
71+
}
72+
}
73+
```
1874

1975
</div>

docs/pages/services/queue.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Queue

docs/pages/services/sessions.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Sessions

phpunit.xml.dist

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@
1313
<server name="APP_KEY" value="AckfSECXIvnK5r28GVIWUAxmbBSjTsmF"/>
1414
<server name="APP_ENV" value="testing"/>
1515
<server name="CACHE_DRIVER" value="array"/>
16+
<server name="CYCLE_ADAPTER_QUEUE_INTEGRATION" value="false"/>
17+
<server name="CYCLE_ADAPTER_SESSION_INTEGRATION" value="false"/>
18+
<server name="CYCLE_ADAPTER_CACHE_INTEGRATION" value="false"/>
19+
20+
<server name="CYCLE_ATTRIBUTES_CACHE" value="true"/>
21+
<server name="CYCLE_ATTRIBUTES_CACHE_DRIVER" value="array"/>
22+
23+
<server name="CYCLE_SCHEMA_CACHE" value="true"/>
24+
<server name="CYCLE_SCHEMA_CACHE_DRIVER" value="array"/>
1625
</php>
1726
<testsuites>
1827
<testsuite name="Tests">

src/Bridge/Cache/Entities/Cache.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace WayOfDev\Cycle\Bridge\Cache\Entities;
6+
7+
use Cycle\Annotated\Annotation\Column;
8+
use Cycle\Annotated\Annotation\Entity;
9+
10+
#[Entity(table: 'cache')]
11+
class Cache
12+
{
13+
#[Column(type: 'string', primary: true)]
14+
public string $key;
15+
16+
#[Column(type: 'longText')]
17+
public string $text;
18+
19+
#[Column(type: 'integer')]
20+
public int $expiration;
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace WayOfDev\Cycle\Bridge\Cache\Entities;
6+
7+
use Cycle\Annotated\Annotation\Column;
8+
use Cycle\Annotated\Annotation\Entity;
9+
10+
#[Entity(table: 'cache_locks')]
11+
class CacheLock
12+
{
13+
#[Column(type: 'string', primary: true)]
14+
public string $key;
15+
16+
#[Column(type: 'string')]
17+
public string $owner;
18+
19+
#[Column(type: 'integer')]
20+
public int $expiration;
21+
}

0 commit comments

Comments
 (0)