Skip to content

Commit b17bdbc

Browse files
Merge pull request #2 from devajmeireles/general-enhancements
General Enhancements
2 parents a87ac76 + 6a41a31 commit b17bdbc

File tree

14 files changed

+229
-124
lines changed

14 files changed

+229
-124
lines changed

.gitattributes

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010
/.run export-ignore
1111
/arts export-ignore
1212
/tests export-ignore
13+
/docs export-ignore
14+
/coverage export-ignore
1315
.gitattributes export-ignore
1416
.gitignore export-ignore
15-
CONTRIBUTING.md export-ignore
1617
composer.lock export-ignore
18+
mkdocs.yml export-ignore
1719
phpstan.neon export-ignore
1820
phpunit.xml export-ignore
1921
.phpunit.result.cache export-ignore
2022
pint.json export-ignore
21-
testbench.yaml export-ignore
2223
rector.php export-ignore
24+
testbench.yaml export-ignore

src/Concerns/UsingDefer.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Fraction\Concerns;
6+
7+
use Fraction\Configurable\DeferUsing;
8+
9+
trait UsingDefer
10+
{
11+
/**
12+
* Configuration for deferring the action.
13+
*/
14+
private ?DeferUsing $deferred = null;
15+
16+
/**
17+
* Enable the action to be deferred.
18+
*
19+
* @return $this
20+
*/
21+
public function deferred(
22+
bool $always = false,
23+
?string $name = null,
24+
): self {
25+
$this->deferred = new DeferUsing($name, $always);
26+
27+
return $this;
28+
}
29+
}

src/Concerns/UsingQueue.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Fraction\Concerns;
6+
7+
use Fraction\Configurable\QueueUsing;
8+
9+
trait UsingQueue
10+
{
11+
/**
12+
* Configuration for queueing the action.
13+
*/
14+
private ?QueueUsing $queued = null;
15+
16+
/**
17+
* Enable the action to be queued.
18+
*
19+
* @return $this
20+
*/
21+
public function queued(
22+
mixed $delay = null,
23+
?string $queue = null,
24+
?string $connection = null,
25+
): self {
26+
$this->queued = new QueueUsing($delay, $queue, $connection);
27+
28+
return $this;
29+
}
30+
}

src/Concerns/UsingRescue.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Fraction\Concerns;
6+
7+
use Fraction\Configurable\RescuedUsing;
8+
9+
trait UsingRescue
10+
{
11+
/**
12+
* Indicates if the action should be rescued.
13+
*/
14+
private ?RescuedUsing $rescued = null;
15+
16+
/**
17+
* Enable the action to be rescued.
18+
*
19+
* @return $this
20+
*/
21+
public function rescued(mixed $default = null): self
22+
{
23+
$this->rescued = new RescuedUsing($default);
24+
25+
return $this;
26+
}
27+
}

src/Concerns/UsingThen.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Fraction\Concerns;
6+
7+
use Fraction\ValueObjects\Then;
8+
use UnitEnum;
9+
10+
trait UsingThen
11+
{
12+
/**
13+
* The array of "then" hooks.
14+
*
15+
* @var array<int, string>
16+
*/
17+
private array $then = [];
18+
19+
/**
20+
* Register a "then" hook.
21+
*/
22+
public function then(string|UnitEnum $action): self
23+
{
24+
$this->then[] = new Then($this->action, $action);
25+
26+
return $this;
27+
}
28+
}

src/FractionBuilder.php

Lines changed: 8 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@
77
use Closure;
88
use Fraction\Configurable\DeferUsing;
99
use Fraction\Configurable\QueueUsing;
10-
use Fraction\Configurable\RescuedUsing;
1110
use Fraction\Contracts\ShouldInterpreter;
1211
use Fraction\Exceptions\PreventDeferQueueSameTime;
13-
use Fraction\Interpreters\AsDefault;
14-
use Fraction\Interpreters\AsDefer;
15-
use Fraction\Interpreters\AsQueue;
16-
use Fraction\ValueObjects\Then;
12+
use Fraction\Handlers\AsDefer;
13+
use Fraction\Handlers\AsQueue;
14+
use Fraction\Handlers\AsSync;
1715
use Illuminate\Contracts\Container\BindingResolutionException;
1816
use Illuminate\Contracts\Support\Arrayable;
1917
use Illuminate\Foundation\Application;
@@ -23,27 +21,10 @@
2321

2422
final class FractionBuilder implements Arrayable
2523
{
26-
/**
27-
* The array of "then" hooks.
28-
*
29-
* @var array<int, string>
30-
*/
31-
private array $then = [];
32-
33-
/**
34-
* Configuration for queueing the action.
35-
*/
36-
private ?QueueUsing $queued = null;
37-
38-
/**
39-
* Configuration for deferring the action.
40-
*/
41-
private ?DeferUsing $deferred = null;
42-
43-
/**
44-
* Indicates if the action should be rescued.
45-
*/
46-
private ?RescuedUsing $rescued = null;
24+
use Concerns\UsingDefer;
25+
use Concerns\UsingQueue;
26+
use Concerns\UsingRescue;
27+
use Concerns\UsingThen;
4728

4829
public function __construct(
4930
public Application $application,
@@ -69,7 +50,7 @@ public function __invoke(...$arguments): mixed
6950
$interpret = match (true) {
7051
$this->queued instanceof QueueUsing => AsQueue::class,
7152
$this->deferred instanceof DeferUsing => AsDefer::class,
72-
default => AsDefault::class,
53+
default => AsSync::class,
7354
};
7455

7556
/** @var ShouldInterpreter $interpreter */
@@ -95,57 +76,6 @@ public function __invoke(...$arguments): mixed
9576
return $result;
9677
}
9778

98-
/**
99-
* Register a "then" hook.
100-
*/
101-
public function then(string|UnitEnum $action): self
102-
{
103-
$this->then[] = new Then($this->action, $action);
104-
105-
return $this;
106-
}
107-
108-
/**
109-
* Enable the action to be queued.
110-
*
111-
* @return $this
112-
*/
113-
public function queued(
114-
mixed $delay = null,
115-
?string $queue = null,
116-
?string $connection = null,
117-
): self {
118-
$this->queued = new QueueUsing($delay, $queue, $connection);
119-
120-
return $this;
121-
}
122-
123-
/**
124-
* Enable the action to be deferred.
125-
*
126-
* @return $this
127-
*/
128-
public function deferred(
129-
bool $always = false,
130-
?string $name = null,
131-
): self {
132-
$this->deferred = new DeferUsing($name, $always);
133-
134-
return $this;
135-
}
136-
137-
/**
138-
* Enable the action to be rescued.
139-
*
140-
* @return $this
141-
*/
142-
public function rescued(mixed $default = null): self
143-
{
144-
$this->rescued = new RescuedUsing($default);
145-
146-
return $this;
147-
}
148-
14979
/** {@inheritDoc} */
15080
public function toArray(): array
15181
{

src/FractionManager.php

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Closure;
88
use Fraction\Exceptions\ActionNotRegistered;
99
use Fraction\Exceptions\UnallowedActionDuplication;
10+
use Fraction\Support\Bootable;
1011
use Fraction\Support\FractionName;
1112
use Illuminate\Foundation\Application;
1213
use UnitEnum;
@@ -61,35 +62,6 @@ public function get(string|UnitEnum $action): mixed
6162
*/
6263
public function boot(): void
6364
{
64-
$cached = [];
65-
66-
if ($this->application->isProduction() && file_exists($path = base_path('bootstrap/cache/actions.php'))) {
67-
$files = require $path;
68-
69-
foreach ($files as $file) {
70-
require_once $file;
71-
}
72-
} else {
73-
$files = glob(config('fraction.path').'/*.php');
74-
75-
foreach ($files as $file) {
76-
$content = file_get_contents($file);
77-
78-
if (mb_strpos($content, 'namespace') !== false || mb_strpos($content, 'execute') === false) {
79-
continue;
80-
}
81-
82-
$cached[] = $file;
83-
84-
require_once $file;
85-
}
86-
87-
if ($cached !== []) {
88-
file_put_contents(
89-
base_path('bootstrap/cache/actions.php'),
90-
'<?php return '.var_export($cached, true).';'
91-
);
92-
}
93-
}
65+
Bootable::fire($this->application);
9466
}
9567
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
declare(strict_types=1);
44

5-
namespace Fraction\Interpreters;
5+
namespace Fraction\Handlers;
66

7-
use Fraction\Concerns\ShareableInterpreter;
87
use Fraction\Configurable\DeferUsing;
98
use Fraction\Contracts\Configurable;
109
use Fraction\Contracts\ShouldInterpreter;
10+
use Fraction\Handlers\Concerns\ShareableInterpreter;
1111
use Illuminate\Container\Container;
1212

1313
final class AsDefer implements Configurable, ShouldInterpreter
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
declare(strict_types=1);
44

5-
namespace Fraction\Interpreters;
5+
namespace Fraction\Handlers;
66

7-
use Fraction\Concerns\ShareableInterpreter;
87
use Fraction\Configurable\QueueUsing;
98
use Fraction\Contracts\Configurable;
109
use Fraction\Contracts\ShouldInterpreter;
10+
use Fraction\Handlers\Concerns\ShareableInterpreter;
1111
use Fraction\Jobs\FractionJob;
1212
use Illuminate\Container\Container;
1313
use Illuminate\Foundation\Bus\PendingDispatch;
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
declare(strict_types=1);
44

5-
namespace Fraction\Interpreters;
5+
namespace Fraction\Handlers;
66

7-
use Fraction\Concerns\ShareableInterpreter;
87
use Fraction\Configurable\RescuedUsing;
98
use Fraction\Contracts\Configurable;
109
use Fraction\Contracts\ShouldInterpreter;
10+
use Fraction\Handlers\Concerns\ShareableInterpreter;
1111
use Illuminate\Container\Container;
1212

13-
final class AsDefault implements Configurable, ShouldInterpreter
13+
final class AsSync implements Configurable, ShouldInterpreter
1414
{
1515
use ShareableInterpreter;
1616

0 commit comments

Comments
 (0)