aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Enderlin <ivan.enderlin@hoa-project.net>2014-08-25 10:23:21 +0200
committerIvan Enderlin <ivan.enderlin@hoa-project.net>2014-08-25 10:23:21 +0200
commitb2dda6cc153f819a1d40d5d1906a8cb1f45f7ed4 (patch)
tree04ccaac6791298dd1729e17ef319c730da9fb9d2
parent20d62e3063b00cdac780c5062f2ab78f01a0e249 (diff)
downloadPraspel-b2dda6cc153f819a1d40d5d1906a8cb1f45f7ed4.zip
Praspel-b2dda6cc153f819a1d40d5d1906a8cb1f45f7ed4.tar.gz
Praspel-b2dda6cc153f819a1d40d5d1906a8cb1f45f7ed4.tar.bz2
Generate an object without a constructor.
-rw-r--r--Preambler/EncapsulationShunter.php65
1 files changed, 36 insertions, 29 deletions
diff --git a/Preambler/EncapsulationShunter.php b/Preambler/EncapsulationShunter.php
index 3ec65a7..0b365fc 100644
--- a/Preambler/EncapsulationShunter.php
+++ b/Preambler/EncapsulationShunter.php
@@ -109,49 +109,56 @@ class EncapsulationShunter {
$callable = $preambler->__getCallable();
$reflection = $callable->getReflection();
+ $registry = \Hoa\Praspel::getRegistry();
- if(!($reflection instanceof \ReflectionMethod))
+ if($reflection instanceof \ReflectionClass) {
+
+ $_object = $reflection->newInstance();
+ $preambler->__setCallable(xcallable($_object, '__construct'));
+ }
+ elseif(!($reflection instanceof \ReflectionMethod))
throw new \Hoa\Praspel\Exception\Preambler(
'The callable must be a class and a (dynamic) method name.', 0);
+ else {
- $registry = \Hoa\Praspel::getRegistry();
- $callback = $callable->getValidCallback();
+ $callback = $callable->getValidCallback();
- if(!is_object($callback[0])) {
+ if(!is_object($callback[0])) {
- $reflectionClass = $reflection->getDeclaringClass();
- $_reflectionClass = $reflectionClass;
+ $reflectionClass = $reflection->getDeclaringClass();
+ $_reflectionClass = $reflectionClass;
- while(
- ( null === $constructor = $_reflectionClass->getConstructor())
- && (false !== $_reflectionClass = $_reflectionClass->getParentClass())
- );
+ while(
+ ( null === $constructor = $_reflectionClass->getConstructor())
+ && (false !== $_reflectionClass = $_reflectionClass->getParentClass())
+ );
- if(null === $constructor)
- $_object = $reflectionClass->newInstance();
- else {
+ if(null === $constructor)
+ $_object = $reflectionClass->newInstance();
+ else {
- $className = $_reflectionClass->getName();
- $id = $className . '::__construct';
+ $className = $_reflectionClass->getName();
+ $id = $className . '::__construct';
- if(!isset($registry[$id]))
- $registry[$id] = \Hoa\Praspel::interprete(
- \Hoa\Praspel::extractFromComment(
- $constructor->getDocComment()
- ),
- $className
- );
+ if(!isset($registry[$id]))
+ $registry[$id] = \Hoa\Praspel::interprete(
+ \Hoa\Praspel::extractFromComment(
+ $constructor->getDocComment()
+ ),
+ $className
+ );
- $assertionChecker = $this->getAssertionChecker();
+ $assertionChecker = $this->getAssertionChecker();
- if(null === $assertionChecker)
- $assertionChecker = '\Hoa\Praspel\AssertionChecker';
+ if(null === $assertionChecker)
+ $assertionChecker = '\Hoa\Praspel\AssertionChecker';
- $arguments = $assertionChecker::generateData($registry[$id]);
- $_object = $reflectionClass->newInstanceArgs($arguments);
- }
+ $arguments = $assertionChecker::generateData($registry[$id]);
+ $_object = $reflectionClass->newInstanceArgs($arguments);
+ }
- $preambler->__setCallable(xcallable($_object, $callback[1]));
+ $preambler->__setCallable(xcallable($_object, $callback[1]));
+ }
}
$reflectionObject = $preambler->__getReflectionObject($object);