Skip to content

Commit

Permalink
Optimized performance. Moved result of __construct method exist chec…
Browse files Browse the repository at this point in the history
…k to internal cache.
  • Loading branch information
picamator committed Apr 1, 2017
1 parent 6e277b0 commit 2aa9e33
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
6 changes: 0 additions & 6 deletions .gitignore
@@ -1,8 +1,2 @@
vendor/
.idea/
nbproject/
.settings/
.buildpath
.project
*.*~
*.phar
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,6 +1,11 @@
CHANGELOG
=========

1.1.0 (2017-04-01)
------------------
* Optimized performance. Moved result of ``__construct`` method exist check to internal cache.
* Moved some ``.gitignore`` IDE specifics to global ignore

1.0.1 (2017-03-09)
------------------
* Fixed path to Composer badges
Expand Down
16 changes: 9 additions & 7 deletions src/ObjectManager.php
Expand Up @@ -25,11 +25,6 @@ public function create($className, array $arguments = [])
return new $className();
}

// construction does not available
if (method_exists($className, '__construct') === false) {
throw new RuntimeException(sprintf('Class "%s" does not have __construct', $className));
}

return $this->getReflection($className)
->newInstanceArgs($arguments);
}
Expand All @@ -43,10 +38,17 @@ public function create($className, array $arguments = [])
*/
private function getReflection($className)
{
if (empty($this->reflectionContainer[$className])) {
$this->reflectionContainer[$className] = new \ReflectionClass($className);
if (isset($this->reflectionContainer[$className])) {
return $this->reflectionContainer[$className];
}

// construction does not available
if (method_exists($className, '__construct') === false) {
throw new RuntimeException(sprintf('Class "%s" does not have __construct', $className));
}

$this->reflectionContainer[$className] = new \ReflectionClass($className);

return $this->reflectionContainer[$className];
}
}

0 comments on commit 2aa9e33

Please sign in to comment.