Skip to content

Commit f74e0a4

Browse files
committed
consolidate and redistribute files from console and foundation
1 parent bf55172 commit f74e0a4

File tree

87 files changed

+5838
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+5838
-4
lines changed

.github/FUNDING.yml

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

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2020 Abed Halawi
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

bin/test-micro-commands.sh

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
# Check if file or directory exists. Exit if it doesn't.
6+
function examine() {
7+
if [ ! -f $1 ] && [ ! -d $1 ]; then
8+
echo "\n-- ERROR -- $1 could not be found!\n"
9+
exit 1
10+
fi
11+
}
12+
13+
# Lint a PHP file for syntax errors. Exit on error.
14+
function lint() {
15+
# echo "\n -- MISSING -- Lint file $1"
16+
RESULT=$(php -l $1)
17+
if [ ! $? -eq 0 ] ; then
18+
echo "$RESULT" && exit 1
19+
fi
20+
}
21+
22+
examine "app/Providers"
23+
examine "app/Providers/RouteServiceProvider.php"
24+
examine "resources"
25+
examine "resources/lang"
26+
examine "resources/views"
27+
examine "resources/views/welcome.blade.php"
28+
lint "resources/views/welcome.blade.php"
29+
examine "routes"
30+
examine "routes/api.php"
31+
examine "routes/web.php"
32+
lint "routes/api.php"
33+
lint "routes/web.php"
34+
examine "tests"
35+
36+
# Controller
37+
./vendor/bin/lucid make:controller trade
38+
examine "app/Http/Controllers/TradeController.php"
39+
lint "app/Http/Controllers/TradeController.php"
40+
41+
# Feature
42+
./vendor/bin/lucid make:feature trade
43+
examine "app/Features/TradeFeature.php"
44+
lint "app/Features/TradeFeature.php"
45+
examine "tests/Features/TradeFeatureTest.php"
46+
lint "tests/Features/TradeFeatureTest.php"
47+
48+
# Job
49+
./vendor/bin/lucid make:job submitTradeRequest shipping
50+
examine "app/Domains/Shipping/Jobs/SubmitTradeRequestJob.php"
51+
lint "app/Domains/Shipping/Jobs/SubmitTradeRequestJob.php"
52+
examine "tests/Domains/Shipping/Jobs/SubmitTradeRequestJobTest.php"
53+
lint "tests/Domains/Shipping/Jobs/SubmitTradeRequestJobTest.php"
54+
55+
./vendor/bin/lucid make:job sail boat --queue
56+
examine "app/Domains/Boat/Jobs/SailJob.php"
57+
lint "app/Domains/Boat/Jobs/SailJob.php"
58+
examine "tests/Domains/Boat/Jobs/SailJobTest.php"
59+
lint "tests/Domains/Boat/Jobs/SailJobTest.php"
60+
61+
# Model
62+
./vendor/bin/lucid make:model bridge
63+
examine "app/Data/Bridge.php"
64+
lint "app/Data/Bridge.php"
65+
66+
# Operation
67+
./vendor/bin/lucid make:operation spin
68+
examine "app/Operations/SpinOperation.php"
69+
lint "app/Operations/SpinOperation.php"
70+
examine "tests/Operations/SpinOperationTest.php"
71+
lint "tests/Operations/SpinOperationTest.php"
72+
73+
./vendor/bin/lucid make:operation twist --queue
74+
examine "app/Operations/TwistOperation.php"
75+
lint "app/Operations/TwistOperation.php"
76+
examine "tests/Operations/TwistOperationTest.php"
77+
lint "tests/Operations/TwistOperationTest.php"
78+
79+
./vendor/bin/lucid make:policy fly
80+
examine "app/Policies/FlyPolicy.php"
81+
lint "app/Policies/FlyPolicy.php"
82+
83+
# Ensure nothing is breaking
84+
./vendor/bin/lucid list:features
85+
./vendor/bin/lucid list:services
86+
87+
./vendor/bin/lucid delete:feature trade
88+
./vendor/bin/lucid delete:job submitTradeRequest shipping
89+
./vendor/bin/lucid delete:job sail boat
90+
./vendor/bin/lucid delete:model bridge
91+
./vendor/bin/lucid delete:operation spin
92+
./vendor/bin/lucid delete:operation twist
93+
./vendor/bin/lucid delete:policy fly
94+
rm app/Http/Controllers/TradeController.php
95+
96+
# Run PHPUnit tests
97+
if [ ! -f ".env" ]; then
98+
echo 'APP_KEY=' > .env
99+
php artisan key:generate
100+
fi
101+
102+
./vendor/bin/phpunit
103+
104+
echo "\nPASSED!\n"
105+
106+
exit 0

composer.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"license": "MIT",
66
"keywords": ["architecture", "lucid", "laravel"],
77
"homepage": "https://lucidarch.dev",
8+
"bin": ["lucid"],
89
"support": {
910
"source": "https://github.com/lucidarch/lucid",
1011
"issues": "https://github.com/lucidarch/lucid/issues"
@@ -16,10 +17,15 @@
1617
}
1718
],
1819
"require": {
19-
"symfony/console": "^5.1",
20-
"symfony/process": "^5.1",
21-
"symfony/finder": "^5.1",
22-
"symfony/filesystem": "^5.1"
20+
"symfony/console": "*",
21+
"symfony/filesystem": "*",
22+
"symfony/finder": "*",
23+
"symfony/process": "*"
24+
},
25+
"autoload": {
26+
"psr-4": {
27+
"Lucid\\": "src/"
28+
}
2329
},
2430
"config": {
2531
"sort-packages": true

lucid

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
if (file_exists('./vendor/autoload.php')) {
5+
require './vendor/autoload.php';
6+
} else if(file_exists(__DIR__.'/vendor/autoload.php')) {
7+
require __DIR__.'/vendor/autoload.php';
8+
} else {
9+
require __DIR__.'/../../../bootstrap/autoload.php';
10+
}
11+
12+
if (file_exists('./bootstrap/app.php')) {
13+
$laravel = require'./bootstrap/app.php';
14+
} else {
15+
$laravel = require __DIR__.'/../../../bootstrap/app.php';
16+
}
17+
18+
$commands = [
19+
new Lucid\Console\Commands\ChangeSourceNamespaceCommand(),
20+
new Lucid\Console\Commands\JobMakeCommand(),
21+
new Lucid\Console\Commands\JobDeleteCommand(),
22+
new Lucid\Console\Commands\ServiceMakeCommand(),
23+
new Lucid\Console\Commands\ServiceDeleteCommand(),
24+
new Lucid\Console\Commands\FeatureMakeCommand(),
25+
new Lucid\Console\Commands\FeatureDeleteCommand(),
26+
new Lucid\Console\Commands\ControllerMakeCommand(),
27+
new Lucid\Console\Commands\MigrationMakeCommand(),
28+
new Lucid\Console\Commands\ServicesListCommand(),
29+
new Lucid\Console\Commands\FeaturesListCommand(),
30+
31+
new Lucid\Console\Commands\ModelMakeCommand(),
32+
new Lucid\Console\Commands\ModelDeleteCommand(),
33+
new Lucid\Console\Commands\RequestMakeCommand(),
34+
new Lucid\Console\Commands\RequestDeleteCommand(),
35+
new Lucid\Console\Commands\PolicyMakeCommand(),
36+
new Lucid\Console\Commands\PolicyDeleteCommand(),
37+
38+
new Lucid\Console\Commands\OperationMakeCommand(),
39+
new Lucid\Console\Commands\OperationDeleteCommand(),
40+
];
41+
42+
$app = new Symfony\Component\Console\Application('Lucid', '1.0.0');
43+
array_walk($commands, [$app, 'add']);
44+
45+
$app->run();

src/Bus/MarshalTrait.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
namespace Lucid\Bus;
4+
5+
use Exception;
6+
use ArrayAccess;
7+
use ReflectionClass;
8+
use ReflectionParameter;
9+
10+
trait MarshalTrait
11+
{
12+
/**
13+
* Marshal a command from the given array accessible object.
14+
*
15+
* @param string $command
16+
* @param \ArrayAccess $source
17+
* @param array $extras
18+
*
19+
* @return mixed
20+
*/
21+
protected function marshal($command, ArrayAccess $source, array $extras = [])
22+
{
23+
$injected = [];
24+
25+
$reflection = new ReflectionClass($command);
26+
27+
if ($constructor = $reflection->getConstructor()) {
28+
$injected = array_map(function ($parameter) use ($command, $source, $extras) {
29+
return $this->getParameterValueForCommand($command, $source, $parameter, $extras);
30+
}, $constructor->getParameters());
31+
}
32+
33+
return $reflection->newInstanceArgs($injected);
34+
}
35+
36+
/**
37+
* Get a parameter value for a marshaled command.
38+
*
39+
* @param string $command
40+
* @param \ArrayAccess $source
41+
* @param \ReflectionParameter $parameter
42+
* @param array $extras
43+
*
44+
* @return mixed
45+
* @throws Exception
46+
*/
47+
protected function getParameterValueForCommand($command, ArrayAccess $source,
48+
ReflectionParameter $parameter, array $extras = [])
49+
{
50+
if (array_key_exists($parameter->name, $extras)) {
51+
return $extras[$parameter->name];
52+
}
53+
54+
if (isset($source[$parameter->name])) {
55+
return $source[$parameter->name];
56+
}
57+
58+
if ($parameter->isDefaultValueAvailable()) {
59+
return $parameter->getDefaultValue();
60+
}
61+
62+
throw new Exception("Unable to map parameter [{$parameter->name}] to command [{$command}]");
63+
}
64+
}

src/Bus/ServesFeaturesTrait.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Lucid\Bus;
4+
5+
use Illuminate\Support\Collection;
6+
use Lucid\Bus\MarshalTrait;
7+
use Illuminate\Foundation\Bus\DispatchesJobs;
8+
use Lucid\Events\FeatureStarted;
9+
10+
trait ServesFeaturesTrait
11+
{
12+
use MarshalTrait;
13+
use DispatchesJobs;
14+
15+
/**
16+
* Serve the given feature with the given arguments.
17+
*
18+
* @param string $feature
19+
* @param array $arguments
20+
*
21+
* @return mixed
22+
*/
23+
public function serve($feature, $arguments = [])
24+
{
25+
event(new FeatureStarted($feature, $arguments));
26+
27+
return $this->dispatch($this->marshal($feature, new Collection(), $arguments));
28+
}
29+
}

src/Bus/UnitDispatcherTrait.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
namespace Lucid\Bus;
4+
5+
use ReflectionClass;
6+
use Lucid\Units\Job;
7+
use ReflectionException;
8+
use Lucid\Units\Operation;
9+
use Illuminate\Http\Request;
10+
use Illuminate\Support\Collection;
11+
use Lucid\Events\JobStarted;
12+
use Lucid\Events\OperationStarted;
13+
14+
trait UnitDispatcherTrait
15+
{
16+
/**
17+
* decorator function to be called instead of the
18+
* laravel function dispatchFromArray.
19+
* When the $arguments is an instance of Request
20+
* it will call dispatchFrom instead.
21+
*
22+
* @param string $unit
23+
* @param array|\Illuminate\Http\Request $arguments
24+
* @param array $extra
25+
*
26+
* @return mixed
27+
*/
28+
public function run($unit, $arguments = [], $extra = [])
29+
{
30+
if ($arguments instanceof Request) {
31+
$result = $this->dispatch($this->marshal($unit, $arguments, $extra));
32+
} else {
33+
if (!is_object($unit)) {
34+
$unit = $this->marshal($unit, new Collection(), $arguments);
35+
}
36+
37+
if ($unit instanceof Operation) {
38+
event(new OperationStarted(get_class($unit), $arguments));
39+
}
40+
41+
if ($unit instanceof Job) {
42+
event(new JobStarted(get_class($unit), $arguments));
43+
}
44+
45+
$result = $this->dispatch($unit, $arguments);
46+
}
47+
48+
return $result;
49+
}
50+
51+
/**
52+
* Run the given unit in the given queue.
53+
*
54+
* @param string $unit
55+
* @param array $arguments
56+
* @param string|null $queue
57+
*
58+
* @return mixed
59+
* @throws ReflectionException
60+
*/
61+
public function runInQueue($unit, array $arguments = [], $queue = 'default')
62+
{
63+
// instantiate and queue the unit
64+
$reflection = new ReflectionClass($unit);
65+
$instance = $reflection->newInstanceArgs($arguments);
66+
$instance->onQueue((string) $queue);
67+
68+
return $this->dispatch($instance);
69+
}
70+
}

0 commit comments

Comments
 (0)