Skip to content

Commit ebeef17

Browse files
committed
Replace Puli with composer-locator
1 parent e77adf3 commit ebeef17

File tree

9 files changed

+87
-376
lines changed

9 files changed

+87
-376
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
/vendor/
22
/composer.lock
3-
/.puli/

composer.json

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,12 @@
1616
}
1717
},
1818
"require": {
19-
"php": "^5.5|^7.0",
19+
"php": "^7.0",
2020
"php-di/php-di": "^5.2",
2121
"doctrine/cache": "^1.4",
22-
"puli/repository": "^1.0.0-beta8",
23-
"puli/discovery": "^1.0.0-beta8",
24-
"puli/composer-plugin": "^1.0.0-beta8"
22+
"mindplay/composer-locator": "^2.1"
2523
},
2624
"require-dev": {
27-
"phpunit/phpunit": "^4.8",
28-
"puli/cli": "^1.0"
29-
},
30-
"minimum-stability": "beta",
31-
"prefer-stable": true
25+
"phpunit/phpunit": "^5.0"
26+
}
3227
}

puli.json

Lines changed: 0 additions & 233 deletions
This file was deleted.

src/Kernel.php

Lines changed: 16 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@
22

33
namespace DI\Kernel;
44

5+
use ComposerLocator;
56
use DI\Cache\ArrayCache;
67
use DI\Container;
78
use DI\ContainerBuilder;
89
use Doctrine\Common\Cache\Cache;
9-
use Interop\Container\ContainerInterface;
10-
use Puli\Discovery\Api\Discovery;
11-
use Puli\Repository\Api\Resource\FilesystemResource;
12-
use Puli\Repository\Api\ResourceRepository;
1310

1411
/**
1512
* Application kernel.
@@ -19,11 +16,9 @@
1916
class Kernel
2017
{
2118
/**
22-
* If null, defaults to the constant PULI_FACTORY_CLASS defined by Puli.
23-
*
24-
* @var string|null
19+
* @var string
2520
*/
26-
public static $puliFactoryClass;
21+
public static $locatorClass = 'ComposerLocator';
2722

2823
/**
2924
* @var string[]
@@ -44,7 +39,7 @@ class Kernel
4439
* @param array $modules The name of the modules to load.
4540
* @param string $environment Environment of the application (prod, dev, test, ...).
4641
*/
47-
public function __construct(array $modules = [], $environment = 'prod')
42+
public function __construct(array $modules = [], string $environment = 'prod')
4843
{
4944
$this->modules = $modules;
5045
$this->environment = $environment;
@@ -65,43 +60,19 @@ public function addConfig(array $config)
6560
}
6661

6762
/**
68-
* Configure and create a container using all configuration files registered under
69-
* the `php-di/configuration` binding type in Puli.
70-
*
71-
* @return Container
63+
* Configure and create a container using all configuration files found in included modules.
7264
*/
73-
public function createContainer()
65+
public function createContainer() : Container
7466
{
75-
if (!self::$puliFactoryClass && !defined('PULI_FACTORY_CLASS')) {
76-
throw new \RuntimeException('Puli is not installed');
77-
}
78-
79-
// Create Puli objects
80-
$factoryClass = self::$puliFactoryClass ?: PULI_FACTORY_CLASS;
81-
$puli = new $factoryClass();
82-
/** @var ResourceRepository $repository */
83-
$repository = $puli->createRepository();
84-
8567
$containerBuilder = new ContainerBuilder();
8668

8769
$cache = $this->getContainerCache();
8870
if ($cache) {
8971
$containerBuilder->setDefinitionCache($cache);
9072
}
9173

92-
// Puli objects
93-
$containerBuilder->addDefinitions([
94-
'puli.factory' => $puli,
95-
ResourceRepository::class => $repository,
96-
Discovery::class => function (ContainerInterface $c) {
97-
$puli = $c->get('puli.factory');
98-
99-
return $puli->createDiscovery($c->get(ResourceRepository::class));
100-
},
101-
]);
102-
10374
foreach ($this->modules as $module) {
104-
$this->loadModule($containerBuilder, $repository, $module);
75+
$this->loadModule($containerBuilder, $module);
10576
}
10677

10778
if (!empty($this->config)) {
@@ -130,22 +101,20 @@ protected function configureContainerBuilder(ContainerBuilder $containerBuilder)
130101
{
131102
}
132103

133-
private function loadModule(ContainerBuilder $builder, ResourceRepository $resources, $module)
104+
private function loadModule(ContainerBuilder $builder, string $module)
134105
{
106+
$locatorClass = self::$locatorClass;
107+
$path = $locatorClass::getPath($module);
108+
135109
// Load all config files in the config/ directory
136-
foreach ($resources->find('/'.$module.'/config/*.php') as $resource) {
137-
if ($resource instanceof FilesystemResource) {
138-
$builder->addDefinitions($resource->getFilesystemPath());
139-
}
110+
foreach (glob($path.'/res/config/*.php') as $file) {
111+
$builder->addDefinitions($file);
140112
}
141113

142114
// Load the environment-specific config if it exists
143-
$envConfig = '/'.$module.'/config/env/'.$this->environment.'.php';
144-
if ($resources->contains($envConfig)) {
145-
$resource = $resources->get($envConfig);
146-
if ($resource instanceof FilesystemResource) {
147-
$builder->addDefinitions($resource->getFilesystemPath());
148-
}
115+
$envConfig = $path.'/res/config/env/'.$this->environment.'.php';
116+
if (file_exists($envConfig)) {
117+
$builder->addDefinitions($envConfig);
149118
}
150119
}
151120
}

0 commit comments

Comments
 (0)