Skip to content

Commit e54a4e9

Browse files
committed
~
1 parent 8a7d2bc commit e54a4e9

File tree

7 files changed

+61
-30
lines changed

7 files changed

+61
-30
lines changed

example/async/bootstrap.async.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ static function (IContainer $container): IDriverLinker {
2929
},
3030
IServiceDefinition::SINGLETON,
3131
),
32-
);
33-
34-
// Register driver linker with output factory
35-
$registry->bind(
32+
// Register driver linker decorator factory
3633
new ServiceDefinition(IDriverLinkerDecoratorFactory::class, DriverLinkerDecoratorFactory::class),
3734
);
3835

example/benchmark/container.php

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,32 +45,28 @@
4545

4646
$registry = DefinitionRegistry::getInstance();
4747

48-
$registry->bind(new ServiceDefinition(ITimer::class, new MicrosecondTimer()));
49-
$registry->bind(new ServiceDefinition(IDriverProviderFactory::class, BenchmarkingDriverProviderFactory::class));
50-
$registry->bind(new ServiceDefinition(IResultMaker::class, ResultMaker::class));
51-
$registry->bind(new ServiceDefinition(IBenchmarkResultsFactory::class, BenchmarkResultsFactory::class));
52-
$registry->bind(new ServiceDefinition(IBenchmarkingDriverFactory::class, BenchmarkingDriverFactory::class));
53-
$registry->bind(new ServiceDefinition(IBenchmarkingDriverBuilder::class, BenchmarkingDriverBuilder::class));
54-
$registry->bind(new ServiceDefinition(IBenchmarkFactory::class, BenchmarkFactory::class));
55-
$registry->bind(new ServiceDefinition(IMeasurementFactory::class, MeasurementFactory::class));
56-
$registry->bind(new ServiceDefinition(IStopwatchBuilder::class, StopwatchBuilder::class));
57-
$registry->bind(new ServiceDefinition(IStopwatchFactory::class, StopwatchFactory::class));
58-
$registry->bind(new ServiceDefinition(IReportPrinterBuilder::class, ReportPrinterBuilder::class));
59-
$registry->bind(new ServiceDefinition(IReportFormatter::class, ReportFormatter::class));
60-
$registry->bind(new ServiceDefinition(IDatetimeFormatter::class, DatetimeFormatter::class));
61-
$registry->bind(new ServiceDefinition(IResultFormatter::class, ResultFormatter::class));
62-
$registry->bind(new ServiceDefinition(IKeyFormatter::class, KeyFormatter::class));
63-
6448
$registry->bind(
49+
new ServiceDefinition(ITimer::class, new MicrosecondTimer()),
50+
new ServiceDefinition(IDriverProviderFactory::class, BenchmarkingDriverProviderFactory::class),
51+
new ServiceDefinition(IResultMaker::class, ResultMaker::class),
52+
new ServiceDefinition(IBenchmarkResultsFactory::class, BenchmarkResultsFactory::class),
53+
new ServiceDefinition(IBenchmarkingDriverFactory::class, BenchmarkingDriverFactory::class),
54+
new ServiceDefinition(IBenchmarkingDriverBuilder::class, BenchmarkingDriverBuilder::class),
55+
new ServiceDefinition(IBenchmarkFactory::class, BenchmarkFactory::class),
56+
new ServiceDefinition(IMeasurementFactory::class, MeasurementFactory::class),
57+
new ServiceDefinition(IStopwatchBuilder::class, StopwatchBuilder::class),
58+
new ServiceDefinition(IStopwatchFactory::class, StopwatchFactory::class),
59+
new ServiceDefinition(IReportPrinterBuilder::class, ReportPrinterBuilder::class),
60+
new ServiceDefinition(IReportFormatter::class, ReportFormatter::class),
61+
new ServiceDefinition(IDatetimeFormatter::class, DatetimeFormatter::class),
62+
new ServiceDefinition(IResultFormatter::class, ResultFormatter::class),
63+
new ServiceDefinition(IKeyFormatter::class, KeyFormatter::class),
6564
new ServiceDefinition(
6665
IReportPrinter::class,
6766
static function (ContainerInterface $container): IReportPrinter {
6867
return $container->get(IReportPrinterFactory::class)->create();
6968
}
7069
),
71-
);
72-
73-
$registry->bind(
7470
new ServiceDefinition(
7571
IReportPrinterFactory::class,
7672
static function (ContainerInterface $container): IReportPrinterFactory {

example/benchmark/container.sync.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ public function write(Traversable $data): void
2222
}
2323
}
2424
),
25-
);
26-
27-
$registry->bind(
2825
new ServiceDefinition(
2926
IDeltaTimer::class,
3027
new class() implements IDeltaTimer {

src/Spinner/Container/Contract/IDefinitionRegistry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ interface IDefinitionRegistry
1313
*/
1414
public function load(): Traversable;
1515

16-
public function bind(IServiceDefinition $serviceDefinition): void;
16+
public function bind(IServiceDefinition ...$serviceDefinitions): void;
1717
}

src/Spinner/Container/DefinitionRegistry.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ public function load(): Traversable
3636
yield from $this->definitions;
3737
}
3838

39-
public function bind(IServiceDefinition $serviceDefinition): void
39+
public function bind(IServiceDefinition ...$serviceDefinitions): void
4040
{
41-
$this->definitions->offsetSet($serviceDefinition->getId(), $serviceDefinition);
41+
foreach ($serviceDefinitions as $serviceDefinition) {
42+
$this->definitions->offsetSet($serviceDefinition->getId(), $serviceDefinition);
43+
}
4244
}
4345
}

tests/Spinner/Unit/Container/DefinitionRegistryTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,45 @@ private function getServiceDefinitionMock(): MockObject&IServiceDefinition
7979
return $this->createMock(IServiceDefinition::class);
8080
}
8181

82+
#[Test]
83+
public function definitionCanBeBoundAsMultipleParams(): void
84+
{
85+
$registry = $this->getTesteeInstance();
86+
87+
$serviceDefinition1 = $this->getServiceDefinitionMock();
88+
$serviceDefinition1
89+
->expects(self::once())
90+
->method('getId')
91+
->willReturn('service1')
92+
;
93+
$serviceDefinition2 = $this->getServiceDefinitionMock();
94+
$serviceDefinition2
95+
->expects(self::once())
96+
->method('getId')
97+
->willReturn('service2')
98+
;
99+
$serviceDefinition3 = $this->getServiceDefinitionMock();
100+
$serviceDefinition3
101+
->expects(self::once())
102+
->method('getId')
103+
->willReturn('service3')
104+
;
105+
106+
$registry->bind(
107+
$serviceDefinition1,
108+
$serviceDefinition2,
109+
$serviceDefinition3
110+
);
111+
112+
$definitions = iterator_to_array($registry->load());
113+
114+
self::assertCount(3, $definitions);
115+
116+
self::assertSame($serviceDefinition1, $definitions['service1']);
117+
self::assertSame($serviceDefinition2, $definitions['service2']);
118+
self::assertSame($serviceDefinition3, $definitions['service3']);
119+
}
120+
82121
#[Test]
83122
public function definitionCanBeOverridden(): void
84123
{

tests/TestCase/ContainerModifyingTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function load(): Traversable
6464
return $this->definitions;
6565
}
6666

67-
public function bind(IServiceDefinition $serviceDefinition): void
67+
public function bind(IServiceDefinition ...$serviceDefinitions): void
6868
{
6969
// do nothing
7070
}

0 commit comments

Comments
 (0)