Skip to content

Commit 55b76b7

Browse files
committed
Require Puli's Composer plugin so that consumers don't have to
1 parent c1a7747 commit 55b76b7

File tree

4 files changed

+193
-13
lines changed

4 files changed

+193
-13
lines changed

composer.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@
1919
"php": "^5.5|^7.0",
2020
"php-di/php-di": "^5.2",
2121
"doctrine/cache": "^1.4",
22-
"puli/repository": "^1.0.0-beta8@beta",
23-
"puli/discovery": "^1.0.0-beta8@beta"
22+
"puli/repository": "^1.0.0-beta8",
23+
"puli/discovery": "^1.0.0-beta8",
24+
"puli/composer-plugin": "^1.0.0-beta8"
2425
},
2526
"require-dev": {
2627
"phpunit/phpunit": "^4.8"
27-
}
28+
},
29+
"minimum-stability": "beta",
30+
"prefer-stable": true
2831
}

puli.json

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,168 @@
11
{
22
"version": "1.0",
3+
"name": "php-di/kernel",
34
"binding-types": {
45
"php-di/configuration": {
56
"description": "PHP-DI configuration file"
67
}
8+
},
9+
"config": {
10+
"bootstrap-file": "vendor/autoload.php"
11+
},
12+
"packages": {
13+
"container-interop/container-interop": {
14+
"install-path": "vendor/container-interop/container-interop",
15+
"installer": "composer"
16+
},
17+
"doctrine/cache": {
18+
"install-path": "vendor/doctrine/cache",
19+
"installer": "composer"
20+
},
21+
"doctrine/instantiator": {
22+
"install-path": "vendor/doctrine/instantiator",
23+
"installer": "composer",
24+
"env": "dev"
25+
},
26+
"php-di/invoker": {
27+
"install-path": "vendor/php-di/invoker",
28+
"installer": "composer"
29+
},
30+
"php-di/php-di": {
31+
"install-path": "vendor/php-di/php-di",
32+
"installer": "composer"
33+
},
34+
"php-di/phpdoc-reader": {
35+
"install-path": "vendor/php-di/phpdoc-reader",
36+
"installer": "composer"
37+
},
38+
"phpdocumentor/reflection-docblock": {
39+
"install-path": "vendor/phpdocumentor/reflection-docblock",
40+
"installer": "composer",
41+
"env": "dev"
42+
},
43+
"phpspec/prophecy": {
44+
"install-path": "vendor/phpspec/prophecy",
45+
"installer": "composer",
46+
"env": "dev"
47+
},
48+
"phpunit/php-code-coverage": {
49+
"install-path": "vendor/phpunit/php-code-coverage",
50+
"installer": "composer",
51+
"env": "dev"
52+
},
53+
"phpunit/php-file-iterator": {
54+
"install-path": "vendor/phpunit/php-file-iterator",
55+
"installer": "composer",
56+
"env": "dev"
57+
},
58+
"phpunit/php-text-template": {
59+
"install-path": "vendor/phpunit/php-text-template",
60+
"installer": "composer",
61+
"env": "dev"
62+
},
63+
"phpunit/php-timer": {
64+
"install-path": "vendor/phpunit/php-timer",
65+
"installer": "composer",
66+
"env": "dev"
67+
},
68+
"phpunit/php-token-stream": {
69+
"install-path": "vendor/phpunit/php-token-stream",
70+
"installer": "composer",
71+
"env": "dev"
72+
},
73+
"phpunit/phpunit": {
74+
"install-path": "vendor/phpunit/phpunit",
75+
"installer": "composer",
76+
"env": "dev"
77+
},
78+
"phpunit/phpunit-mock-objects": {
79+
"install-path": "vendor/phpunit/phpunit-mock-objects",
80+
"installer": "composer",
81+
"env": "dev"
82+
},
83+
"puli/composer-plugin": {
84+
"install-path": "vendor/puli/composer-plugin",
85+
"installer": "composer"
86+
},
87+
"puli/discovery": {
88+
"install-path": "vendor/puli/discovery",
89+
"installer": "composer"
90+
},
91+
"puli/repository": {
92+
"install-path": "vendor/puli/repository",
93+
"installer": "composer"
94+
},
95+
"puli/url-generator": {
96+
"install-path": "vendor/puli/url-generator",
97+
"installer": "composer"
98+
},
99+
"ramsey/uuid": {
100+
"install-path": "vendor/ramsey/uuid",
101+
"installer": "composer"
102+
},
103+
"sebastian/comparator": {
104+
"install-path": "vendor/sebastian/comparator",
105+
"installer": "composer",
106+
"env": "dev"
107+
},
108+
"sebastian/diff": {
109+
"install-path": "vendor/sebastian/diff",
110+
"installer": "composer",
111+
"env": "dev"
112+
},
113+
"sebastian/environment": {
114+
"install-path": "vendor/sebastian/environment",
115+
"installer": "composer",
116+
"env": "dev"
117+
},
118+
"sebastian/exporter": {
119+
"install-path": "vendor/sebastian/exporter",
120+
"installer": "composer",
121+
"env": "dev"
122+
},
123+
"sebastian/global-state": {
124+
"install-path": "vendor/sebastian/global-state",
125+
"installer": "composer",
126+
"env": "dev"
127+
},
128+
"sebastian/recursion-context": {
129+
"install-path": "vendor/sebastian/recursion-context",
130+
"installer": "composer",
131+
"env": "dev"
132+
},
133+
"sebastian/version": {
134+
"install-path": "vendor/sebastian/version",
135+
"installer": "composer",
136+
"env": "dev"
137+
},
138+
"symfony/process": {
139+
"install-path": "vendor/symfony/process",
140+
"installer": "composer"
141+
},
142+
"symfony/yaml": {
143+
"install-path": "vendor/symfony/yaml",
144+
"installer": "composer",
145+
"env": "dev"
146+
},
147+
"webmozart/assert": {
148+
"install-path": "vendor/webmozart/assert",
149+
"installer": "composer"
150+
},
151+
"webmozart/expression": {
152+
"install-path": "vendor/webmozart/expression",
153+
"installer": "composer"
154+
},
155+
"webmozart/glob": {
156+
"install-path": "vendor/webmozart/glob",
157+
"installer": "composer"
158+
},
159+
"webmozart/key-value-store": {
160+
"install-path": "vendor/webmozart/key-value-store",
161+
"installer": "composer"
162+
},
163+
"webmozart/path-util": {
164+
"install-path": "vendor/webmozart/path-util",
165+
"installer": "composer"
166+
}
7167
}
8168
}

src/Kernel.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ class Kernel
2626
*/
2727
const PULI_BINDING_NAME = 'php-di/configuration';
2828

29+
/**
30+
* If null, defaults to the constant PULI_FACTORY_CLASS defined by Puli.
31+
*
32+
* @var string|null
33+
*/
34+
private $puliFactoryClass;
35+
36+
public function setPuliFactoryClass($class)
37+
{
38+
$this->puliFactoryClass = $class;
39+
}
40+
2941
/**
3042
* Configure and create a container using all configuration files registered under
3143
* the `php-di/configuration` binding type in Puli.
@@ -34,12 +46,12 @@ class Kernel
3446
*/
3547
public function createContainer()
3648
{
37-
if (!defined('PULI_FACTORY_CLASS')) {
49+
if (!$this->puliFactoryClass && !defined('PULI_FACTORY_CLASS')) {
3850
throw new \RuntimeException('Puli is not installed');
3951
}
4052

4153
// Create Puli objects
42-
$factoryClass = PULI_FACTORY_CLASS;
54+
$factoryClass = $this->puliFactoryClass ?: PULI_FACTORY_CLASS;
4355
$factory = new $factoryClass();
4456
/** @var ResourceRepository $repository */
4557
$repository = $factory->createRepository();

tests/KernelTest.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,35 @@
1414

1515
class KernelTest extends \PHPUnit_Framework_TestCase
1616
{
17+
/**
18+
* @var Kernel
19+
*/
20+
private $kernel;
21+
1722
public function setUp()
1823
{
19-
if (!defined('PULI_FACTORY_CLASS')) {
20-
define('PULI_FACTORY_CLASS', PuliFactoryClass::class);
21-
}
22-
2324
PuliFactoryClass::$repository = new InMemoryRepository();
2425
PuliFactoryClass::$discovery = new InMemoryDiscovery();
26+
27+
$this->kernel = new Kernel();
28+
// Mock the Puli factory
29+
$this->kernel->setPuliFactoryClass(PuliFactoryClass::class);
2530
}
2631

2732
/**
2833
* @test
2934
*/
3035
public function creates_a_container()
3136
{
32-
$this->assertInstanceOf('DI\Container', (new Kernel())->createContainer());
37+
$this->assertInstanceOf('DI\Container', $this->kernel->createContainer());
3338
}
3439

3540
/**
3641
* @test
3742
*/
3843
public function registers_puli_repository()
3944
{
40-
$container = (new Kernel())->createContainer();
45+
$container = $this->kernel->createContainer();
4146
$this->assertInstanceOf(ResourceRepository::class, $container->get(ResourceRepository::class));
4247
}
4348

@@ -46,7 +51,7 @@ public function registers_puli_repository()
4651
*/
4752
public function registers_puli_discovery()
4853
{
49-
$container = (new Kernel())->createContainer();
54+
$container = $this->kernel->createContainer();
5055
$this->assertInstanceOf(Discovery::class, $container->get(Discovery::class));
5156
}
5257

@@ -58,7 +63,7 @@ public function registers_module_configuration_files()
5863
$this->createPuliResource('/blog/config.php', __DIR__.'/Fixture/config.php');
5964
$this->bindPuliResource('/blog/config.php', Kernel::PULI_BINDING_NAME);
6065

61-
$container = (new Kernel())->createContainer();
66+
$container = $this->kernel->createContainer();
6267
$this->assertEquals('bar', $container->get('foo'));
6368
}
6469

0 commit comments

Comments
 (0)