Skip to content

Commit 0c160e2

Browse files
committed
try entropy
1 parent e34eccd commit 0c160e2

File tree

2 files changed

+8
-57
lines changed

2 files changed

+8
-57
lines changed

composer.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"require": {
99
"php": ">=8.2",
1010
"composer/semver": "^3.4",
11-
"illuminate/container": "^12.37",
11+
"entropy/entropy": "dev-main",
1212
"nette/utils": "^4.0",
1313
"symfony/console": "^6.4",
1414
"symfony/finder": "^7.3",
@@ -23,7 +23,6 @@
2323
"shipmonk/composer-dependency-analyser": "^1.8",
2424
"phpecs/phpecs": "^2.2",
2525
"symplify/phpstan-extensions": "^12.0",
26-
"symplify/vendor-patches": "^11.5",
2726
"tomasvotruba/class-leak": "^2.0",
2827
"tracy/tracy": "^2.11"
2928
},
@@ -41,7 +40,6 @@
4140
"sort-packages": true,
4241
"platform-check": false,
4342
"allow-plugins": {
44-
"cweagans/composer-patches": true,
4543
"phpstan/extension-installer": true
4644
}
4745
},

src/DependencyInjection/ContainerFactory.php

Lines changed: 7 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44

55
namespace Rector\Jack\DependencyInjection;
66

7-
use Illuminate\Container\Container;
8-
use Rector\Jack\Console\JackConsoleApplication;
9-
use Symfony\Component\Console\Application;
10-
use Symfony\Component\Finder\Finder;
11-
use Webmozart\Assert\Assert;
7+
use Entropy\Console\CommandRegistry;
8+
use Entropy\Console\Contract\CommandInterface;
9+
use Entropy\Container\Container;
1210

1311
final class ContainerFactory
1412
{
@@ -19,57 +17,12 @@ public function create(): Container
1917
{
2018
$container = new Container();
2119

22-
// console
23-
$container->singleton(Application::class, function (Container $container): Application {
24-
$jackConsoleApplication = new JackConsoleApplication('Rector Jack');
25-
26-
$commandClasses = $this->findCommandClasses();
27-
28-
// register commands
29-
foreach ($commandClasses as $commandClass) {
30-
$command = $container->make($commandClass);
31-
$jackConsoleApplication->add($command);
32-
}
33-
34-
// remove basic command to make output clear
35-
$this->hideDefaultCommands($jackConsoleApplication);
36-
37-
return $jackConsoleApplication;
20+
// @todo avoid need of this
21+
$container->service(CommandRegistry::class, function (Container $container): CommandRegistry {
22+
$commands = $container->findByContract(CommandInterface::class);
23+
return new CommandRegistry($commands);
3824
});
3925

4026
return $container;
4127
}
42-
43-
public function hideDefaultCommands(Application $application): void
44-
{
45-
$application->get('list')
46-
->setHidden(true);
47-
$application->get('completion')
48-
->setHidden(true);
49-
$application->get('help')
50-
->setHidden(true);
51-
}
52-
53-
/**
54-
* @return string[]
55-
*/
56-
private function findCommandClasses(): array
57-
{
58-
$commandFinder = Finder::create()
59-
->files()
60-
->name('*Command.php')
61-
->in(__DIR__ . '/../Command');
62-
63-
$commandClasses = [];
64-
foreach ($commandFinder as $commandFile) {
65-
$commandClass = 'Rector\\Jack\\Command\\' . $commandFile->getBasename('.php');
66-
67-
// make sure it exists
68-
Assert::classExists($commandClass);
69-
70-
$commandClasses[] = $commandClass;
71-
}
72-
73-
return $commandClasses;
74-
}
7528
}

0 commit comments

Comments
 (0)