Skip to content
This repository was archived by the owner on Feb 6, 2020. It is now read-only.

Commit 11d516c

Browse files
committed
Merge pull request #89 from Ocramius/fix/#83-misconfigured-aliases-can-lead-to-infinite-loops
Fix for #83: misconfigured aliases can lead to infinite loops
2 parents 218eb28 + a27bafd commit 11d516c

17 files changed

+729
-134
lines changed

CHANGELOG.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
All notable changes to this project will be documented in this file, in reverse chronological order by release.
44

5-
## 3.0.2 - TBD
5+
## 3.0.3 - TBD
66

77
### Added
88

@@ -20,6 +20,33 @@ All notable changes to this project will be documented in this file, in reverse
2020

2121
- Nothing.
2222

23+
## 3.0.2 - 2016-01-24
24+
25+
### Added
26+
27+
- [#64](https://github.com/zendframework/zend-servicemanager/pull/64) performance optimizations
28+
when dealing with alias resolution during service manager instantiation
29+
30+
### Deprecated
31+
32+
- Nothing.
33+
34+
### Removed
35+
36+
- Nothing.
37+
38+
### Fixed
39+
40+
- [#62](https://github.com/zendframework/zend-servicemanager/pull/62)
41+
[#64](https://github.com/zendframework/zend-servicemanager/pull/64) corrected benchmark assets signature
42+
- [#72](https://github.com/zendframework/zend-servicemanager/pull/72) corrected link to the Proxy Pattern Wikipedia
43+
page in the documentation
44+
- [#78](https://github.com/zendframework/zend-servicemanager/issues/78)
45+
[#79](https://github.com/zendframework/zend-servicemanager/pull/79) creation context was not being correctly passed
46+
to abstract factories when using plugin managers
47+
- [#82](https://github.com/zendframework/zend-servicemanager/pull/82) corrected migration guide in the DocBlock of
48+
the `InitializerInterface`
49+
2350
## 3.0.1 - 2016-01-19
2451

2552
### Added

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ retrieving other objects.
1818
## Benchmarks
1919

2020
We provide scripts for benchmarking zend-servicemanager using the
21-
[Athletic](https://github.com/polyfractal/athletic) framework; these can be
21+
[PHPBench](https://github.com/phpbench/phpbench) framework; these can be
2222
found in the `benchmarks/` directory.
2323

2424
To execute the benchmarks you can run the following command:
2525

2626
```bash
27-
$ vendor/bin/athletic -p benchmarks
27+
$ vendor/bin/phpbench run --report=aggregate
2828
```

benchmarks/BenchAsset/AbstractFactoryFoo.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@
66

77
class AbstractFactoryFoo implements AbstractFactoryInterface
88
{
9-
public function canCreateServiceWithName(ContainerInterface $container, $requestedName)
10-
{
11-
return ($requestedName === 'foo');
12-
}
13-
149
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
1510
{
1611
if ($requestedName === 'foo') {
1712
return new Foo($options);
1813
}
1914
return false;
2015
}
16+
17+
public function canCreate(ContainerInterface $container, $requestedName)
18+
{
19+
return ($requestedName === 'foo');
20+
}
21+
2122
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<?php
2+
3+
namespace ZendBench\ServiceManager;
4+
5+
use PhpBench\Benchmark\Metadata\Annotations\Iterations;
6+
use PhpBench\Benchmark\Metadata\Annotations\Revs;
7+
use PhpBench\Benchmark\Metadata\Annotations\Warmup;
8+
use Zend\ServiceManager\ServiceManager;
9+
10+
/**
11+
* @Revs(1000)
12+
* @Iterations(20)
13+
* @Warmup(2)
14+
*/
15+
class FetchCachedServicesBench
16+
{
17+
/**
18+
* @var ServiceManager
19+
*/
20+
private $sm;
21+
22+
public function __construct()
23+
{
24+
$this->sm = new ServiceManager([
25+
'factories' => [
26+
'factory1' => BenchAsset\FactoryFoo::class,
27+
],
28+
'invokables' => [
29+
'invokable1' => BenchAsset\Foo::class,
30+
],
31+
'services' => [
32+
'service1' => new \stdClass(),
33+
],
34+
'aliases' => [
35+
'alias1' => 'service1',
36+
'recursiveAlias1' => 'alias1',
37+
'recursiveAlias2' => 'recursiveAlias1',
38+
],
39+
'abstract_factories' => [
40+
BenchAsset\AbstractFactoryFoo::class
41+
]
42+
]);
43+
44+
// forcing initialization of all the services
45+
$this->sm->get('factory1');
46+
$this->sm->get('invokable1');
47+
$this->sm->get('service1');
48+
$this->sm->get('alias1');
49+
$this->sm->get('recursiveAlias1');
50+
$this->sm->get('recursiveAlias2');
51+
}
52+
53+
public function benchFetchFactory1()
54+
{
55+
// @todo @link https://github.com/phpbench/phpbench/issues/304
56+
$sm = clone $this->sm;
57+
58+
$sm->get('factory1');
59+
}
60+
61+
public function benchFetchInvokable1()
62+
{
63+
// @todo @link https://github.com/phpbench/phpbench/issues/304
64+
$sm = clone $this->sm;
65+
66+
$sm->get('invokable1');
67+
}
68+
69+
public function benchFetchService1()
70+
{
71+
// @todo @link https://github.com/phpbench/phpbench/issues/304
72+
$sm = clone $this->sm;
73+
74+
$sm->get('service1');
75+
}
76+
77+
public function benchFetchAlias1()
78+
{
79+
// @todo @link https://github.com/phpbench/phpbench/issues/304
80+
$sm = clone $this->sm;
81+
82+
$sm->get('alias1');
83+
}
84+
85+
public function benchFetchRecursiveAlias1()
86+
{
87+
// @todo @link https://github.com/phpbench/phpbench/issues/304
88+
$sm = clone $this->sm;
89+
90+
$sm->get('recursiveAlias1');
91+
}
92+
93+
public function benchFetchRecursiveAlias2()
94+
{
95+
// @todo @link https://github.com/phpbench/phpbench/issues/304
96+
$sm = clone $this->sm;
97+
98+
$sm->get('recursiveAlias2');
99+
}
100+
101+
public function benchFetchAbstractFactoryService()
102+
{
103+
// @todo @link https://github.com/phpbench/phpbench/issues/304
104+
$sm = clone $this->sm;
105+
106+
$sm->get('foo');
107+
}
108+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace ZendBench\ServiceManager;
4+
5+
use PhpBench\Benchmark\Metadata\Annotations\Iterations;
6+
use PhpBench\Benchmark\Metadata\Annotations\Revs;
7+
use PhpBench\Benchmark\Metadata\Annotations\Warmup;
8+
use Zend\ServiceManager\ServiceManager;
9+
10+
/**
11+
* @Revs(100)
12+
* @Iterations(20)
13+
* @Warmup(2)
14+
*/
15+
class FetchNewServiceManagerBench
16+
{
17+
const NUM_SERVICES = 1000;
18+
19+
/**
20+
* @var array
21+
*/
22+
private $config = [];
23+
24+
public function __construct()
25+
{
26+
$config = [
27+
'factories' => [],
28+
'invokables' => [],
29+
'services' => [],
30+
'aliases' => [],
31+
'abstract_factories' => [
32+
BenchAsset\AbstractFactoryFoo::class,
33+
],
34+
];
35+
36+
$service = new \stdClass();
37+
38+
for ($i = 0; $i <= self::NUM_SERVICES; $i++) {
39+
$config['factories']["factory_$i"] = BenchAsset\FactoryFoo::class;
40+
$config['invokables']["invokable_$i"] = BenchAsset\Foo::class;
41+
$config['services']["service_$i"] = $service;
42+
$config['aliases']["alias_$i"] = "service_$i";
43+
}
44+
$this->config = $config;
45+
}
46+
47+
public function benchFetchServiceManagerCreation()
48+
{
49+
new ServiceManager($this->config);
50+
}
51+
}

benchmarks/FetchNewServicesBench.php

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
<?php
2+
3+
namespace ZendBench\ServiceManager;
4+
5+
use PhpBench\Benchmark\Metadata\Annotations\Iterations;
6+
use PhpBench\Benchmark\Metadata\Annotations\Revs;
7+
use PhpBench\Benchmark\Metadata\Annotations\Warmup;
8+
use Zend\ServiceManager\ServiceManager;
9+
10+
/**
11+
* @Revs(1000)
12+
* @Iterations(10)
13+
* @Warmup(2)
14+
*/
15+
class FetchNewServicesBench
16+
{
17+
/**
18+
* @var ServiceManager
19+
*/
20+
private $sm;
21+
22+
public function __construct()
23+
{
24+
$this->sm = new ServiceManager([
25+
'factories' => [
26+
'factory1' => BenchAsset\FactoryFoo::class,
27+
],
28+
'invokables' => [
29+
'invokable1' => BenchAsset\Foo::class,
30+
],
31+
'services' => [
32+
'service1' => new \stdClass(),
33+
],
34+
'aliases' => [
35+
'factoryAlias1' => 'factory1',
36+
'recursiveFactoryAlias1' => 'factoryAlias1',
37+
'recursiveFactoryAlias2' => 'recursiveFactoryAlias1',
38+
],
39+
'abstract_factories' => [
40+
BenchAsset\AbstractFactoryFoo::class
41+
],
42+
]);
43+
}
44+
45+
public function benchFetchFactory1()
46+
{
47+
// @todo @link https://github.com/phpbench/phpbench/issues/304
48+
$sm = clone $this->sm;
49+
50+
$sm->get('factory1');
51+
}
52+
53+
public function benchBuildFactory1()
54+
{
55+
// @todo @link https://github.com/phpbench/phpbench/issues/304
56+
$sm = clone $this->sm;
57+
58+
$sm->build('factory1');
59+
}
60+
61+
public function benchFetchInvokable1()
62+
{
63+
// @todo @link https://github.com/phpbench/phpbench/issues/304
64+
$sm = clone $this->sm;
65+
66+
$sm->get('invokable1');
67+
}
68+
69+
public function benchBuildInvokable1()
70+
{
71+
// @todo @link https://github.com/phpbench/phpbench/issues/304
72+
$sm = clone $this->sm;
73+
74+
$sm->build('invokable1');
75+
}
76+
77+
public function benchFetchService1()
78+
{
79+
// @todo @link https://github.com/phpbench/phpbench/issues/304
80+
$sm = clone $this->sm;
81+
82+
$sm->get('service1');
83+
}
84+
85+
public function benchFetchFactoryAlias1()
86+
{
87+
// @todo @link https://github.com/phpbench/phpbench/issues/304
88+
$sm = clone $this->sm;
89+
90+
$sm->build('factoryAlias1');
91+
}
92+
93+
public function benchBuildFactoryAlias1()
94+
{
95+
// @todo @link https://github.com/phpbench/phpbench/issues/304
96+
$sm = clone $this->sm;
97+
98+
$sm->build('factoryAlias1');
99+
}
100+
101+
public function benchFetchRecursiveFactoryAlias1()
102+
{
103+
// @todo @link https://github.com/phpbench/phpbench/issues/304
104+
$sm = clone $this->sm;
105+
106+
$sm->build('recursiveFactoryAlias1');
107+
}
108+
109+
public function benchBuildRecursiveFactoryAlias1()
110+
{
111+
// @todo @link https://github.com/phpbench/phpbench/issues/304
112+
$sm = clone $this->sm;
113+
114+
$sm->build('recursiveFactoryAlias1');
115+
}
116+
117+
public function benchFetchRecursiveFactoryAlias2()
118+
{
119+
// @todo @link https://github.com/phpbench/phpbench/issues/304
120+
$sm = clone $this->sm;
121+
122+
$sm->build('recursiveFactoryAlias2');
123+
}
124+
125+
public function benchBuildRecursiveFactoryAlias2()
126+
{
127+
// @todo @link https://github.com/phpbench/phpbench/issues/304
128+
$sm = clone $this->sm;
129+
130+
$sm->build('recursiveFactoryAlias2');
131+
}
132+
133+
public function benchFetchAbstractFactoryFoo()
134+
{
135+
// @todo @link https://github.com/phpbench/phpbench/issues/304
136+
$sm = clone $this->sm;
137+
138+
$sm->get('foo');
139+
}
140+
141+
public function benchBuildAbstractFactoryFoo()
142+
{
143+
// @todo @link https://github.com/phpbench/phpbench/issues/304
144+
$sm = clone $this->sm;
145+
146+
$sm->build('foo');
147+
}
148+
}

0 commit comments

Comments
 (0)