1+ /**
2+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
4+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
5+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
6+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
7+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
8+ * THE SOFTWARE.
9+ *
10+ * This software consists of voluntary contributions made by many individuals
11+ * and is licensed under the MIT license.
12+ *
13+ * Copyright (c) 2018-2019 Yuuki Takezawa
14+ */
15+
116namespace Nazg\Glue ;
217
318use namespace Nazg\Glue\Exception ;
@@ -15,11 +30,14 @@ class Container {
1530 }
1631
1732 public function add <T >(Bind <T > $bind ): void {
18- if (! $this -> isLock()) {
19- $bound = $bind -> getBound();
20- if ($bound is DependencyInterface ) {
21- $this -> bindings [$bind -> getId()] = tuple ($bound , $bind -> getScope());
22- }
33+ if ($this -> isLock()) {
34+ throw new Exception \ContainerNotLockedException (
35+ ' Cannot modify container when locked.'
36+ );
37+ }
38+ $bound = $bind -> getBound();
39+ if ($bound is DependencyInterface ) {
40+ $this -> bindings [$bind -> getId()] = tuple ($bound , $bind -> getScope());
2341 }
2442 }
2543
@@ -49,12 +67,7 @@ class Container {
4967 }
5068
5169 public function has <T >(typename <T > $id ): bool {
52- if ($this -> isLock()) {
53- return C \contains_key ($this -> bindings , $id );
54- }
55- throw new Exception \ContainerNotLockedException (
56- ' Cannot modify container when locked.'
57- );
70+ return C \contains_key ($this -> bindings , $id );
5871 }
5972
6073 public function registerModule (
0 commit comments