Skip to content

Commit cb884df

Browse files
committed
Improve runtime container changes
1 parent c746f0f commit cb884df

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## [Unreleased]
88

9+
## [0.3.1] - 2018-10-17
10+
### Fixed
11+
- The container can now be modified on runtime without losing benefits of static array opcache optimization
12+
913
## [0.3.0] - 2018-10-17
1014
### Added
1115
- The `Container::getCacheFile()` now accepts an optional callable parameter for encoding values.
@@ -32,7 +36,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
3236
### Added
3337
- Initial development release
3438

35-
[Unreleased]: https://github.com/simply-framework/container/compare/v0.3.0...HEAD
39+
[Unreleased]: https://github.com/simply-framework/container/compare/v0.3.1...HEAD
40+
[0.3.1]: https://github.com/simply-framework/container/compare/v0.3.0...v0.3.1
3641
[0.3.0]: https://github.com/simply-framework/container/compare/v0.2.1...v0.3.0
3742
[0.2.1]: https://github.com/simply-framework/container/compare/v0.2.0...v0.2.1
3843
[0.2.0]: https://github.com/simply-framework/container/compare/v0.1.0...v0.2.0

src/Container.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Container implements ContainerInterface, \ArrayAccess
2222
/** @var array[] Information about cached container entries */
2323
protected $entries = [];
2424

25-
/** @var EntryInterface[] Cached entries used to resolve values */
25+
/** @var EntryInterface[] Cached entry instances used to resolve values */
2626
private $entryCache;
2727

2828
/** @var array Cached values for container entries */
@@ -81,18 +81,14 @@ public function getCacheFile(callable $encoder = null): string
8181
*/
8282
private function loadCacheParameters(): void
8383
{
84-
foreach ($this->entries as $id => $data) {
85-
if (!isset($this->entryCache[$id])) {
86-
continue;
87-
}
88-
89-
$parameters = $this->entryCache[$id]->getCacheParameters();
84+
foreach ($this->entryCache as $id => $entry) {
85+
$parameters = $entry->getCacheParameters();
9086

9187
if (!$this->isConstantValue($parameters)) {
9288
throw new ContainerException("Unable to cache entry '$id', the cache parameters are not static");
9389
}
9490

95-
$this->entries[$id] = [\get_class($this->entryCache[$id]), $parameters];
91+
$this->entries[$id] = [\get_class($entry), $parameters];
9692
}
9793
}
9894

@@ -124,11 +120,10 @@ private function isConstantValue($value): bool
124120
*/
125121
public function addEntry(string $id, EntryInterface $type): void
126122
{
127-
if (isset($this->entries[$id])) {
123+
if (isset($this[$id])) {
128124
throw new ContainerException("Entry for identifier '$id' already exists");
129125
}
130126

131-
$this->entries[$id] = [];
132127
$this->entryCache[$id] = $type;
133128
}
134129

@@ -186,7 +181,7 @@ private function getEntry(string $id): EntryInterface
186181
*/
187182
public function has($id): bool
188183
{
189-
return isset($this->entries[$id]);
184+
return isset($this->entries[$id]) || isset($this->entryCache[$id]);
190185
}
191186

192187
/**

0 commit comments

Comments
 (0)