Skip to content

Commit

Permalink
Fix incorrect creating instance by fromArray
Browse files Browse the repository at this point in the history
  • Loading branch information
neeckeloo committed Dec 12, 2012
1 parent 0ef37c6 commit 457128c
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 98 deletions.
82 changes: 29 additions & 53 deletions library/Zend/Code/Generator/ClassGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class ClassGenerator extends AbstractGenerator
protected $methods = array();

/**
* fromReflection() - build a Code Generation Php Object from a Class Reflection
* Build a Code Generation Php Object from a Class Reflection
*
* @param ClassReflection $classReflection
* @return ClassGenerator
Expand Down Expand Up @@ -141,7 +141,6 @@ public static function fromReflection(ClassReflection $classReflection)
* @configkey properties
* @configkey methods
*
*
* @throws Exception\InvalidArgumentException
* @param array $array
* @return ClassGenerator
Expand All @@ -151,6 +150,7 @@ public static function fromArray(array $array)
if (!isset($array['name'])) {
throw new Exception\InvalidArgumentException('Class generator requires that a name is provided for this object');
}

$cg = new static($array['name']);
foreach ($array as $name => $value) {
// normalize key
Expand All @@ -162,7 +162,8 @@ public static function fromArray(array $array)
$cg->setNamespaceName($value);
break;
case 'docblock':
$cg->setDocBlock((!$value instanceof DocBlockGenerator) ? : DocBlockGenerator::fromArray($value));
$docBlock = ($value instanceof DocBlockGenerator) ? $value : DocBlockGenerator::fromArray($value);
$cg->setDocBlock($docBlock);
break;
case 'flags':
$cg->setFlags($value);
Expand All @@ -181,9 +182,20 @@ public static function fromArray(array $array)
break;
}
}

return $cg;
}

/**
* @param string $name
* @param string $namespaceName
* @param array|string $flags
* @param string $extends
* @param array $interfaces
* @param array $properties
* @param array $methods
* @param DocBlockGenerator $docBlock
*/
public function __construct($name = null, $namespaceName = null, $flags = null, $extends = null,
$interfaces = array(), $properties = array(), $methods = array(), $docBlock = null)
{
Expand Down Expand Up @@ -214,8 +226,6 @@ public function __construct($name = null, $namespaceName = null, $flags = null,
}

/**
* setName()
*
* @param string $name
* @return ClassGenerator
*/
Expand All @@ -232,8 +242,6 @@ public function setName($name)
}

/**
* getName()
*
* @return string
*/
public function getName()
Expand All @@ -242,8 +250,6 @@ public function getName()
}

/**
* getNamespaceName()
*
* @return string
*/
public function getNamespaceName()
Expand All @@ -252,9 +258,7 @@ public function getNamespaceName()
}

/**
* setNamespaceName()
*
* @param $namespaceName
* @param string $namespaceName
* @return ClassGenerator
*/
public function setNamespaceName($namespaceName)
Expand Down Expand Up @@ -294,17 +298,18 @@ public function setDocBlock(DocBlockGenerator $docBlock)
return $this;
}


/**
* getDocBlock()
*
* @return DocBlockGenerator
*/
public function getDocBlock()
{
return $this->docBlock;
}

/**
* @param array|string $flags
* @return \Zend\Code\Generator\ClassGenerator
*/
public function setFlags($flags)
{
if (is_array($flags)) {
Expand All @@ -319,21 +324,27 @@ public function setFlags($flags)
return $this;
}

/**
* @param string $flag
* @return ClassGenerator
*/
public function addFlag($flag)
{
$this->setFlags($this->flags | $flag);
return $this;
}

/**
* @param string $flag
* @return ClassGenerator
*/
public function removeFlag($flag)
{
$this->setFlags($this->flags & ~$flag);
return $this;
}

/**
* setAbstract()
*
* @param bool $isAbstract
* @return AbstractMemberGenerator
*/
Expand All @@ -343,8 +354,6 @@ public function setAbstract($isAbstract)
}

/**
* isAbstract()
*
* @return bool
*/
public function isAbstract()
Expand All @@ -353,8 +362,6 @@ public function isAbstract()
}

/**
* setFinal()
*
* @param bool $isFinal
* @return AbstractMemberGenerator
*/
Expand All @@ -364,8 +371,6 @@ public function setFinal($isFinal)
}

/**
* isFinal()
*
* @return bool
*/
public function isFinal()
Expand All @@ -374,8 +379,6 @@ public function isFinal()
}

/**
* setExtendedClass()
*
* @param string $extendedClass
* @return ClassGenerator
*/
Expand All @@ -386,8 +389,6 @@ public function setExtendedClass($extendedClass)
}

/**
* getExtendedClass()
*
* @return string
*/
public function getExtendedClass()
Expand All @@ -396,8 +397,6 @@ public function getExtendedClass()
}

/**
* setImplementedInterfaces()
*
* @param array $implementedInterfaces
* @return ClassGenerator
*/
Expand All @@ -408,8 +407,6 @@ public function setImplementedInterfaces(array $implementedInterfaces)
}

/**
* getImplementedInterfaces
*
* @return array
*/
public function getImplementedInterfaces()
Expand All @@ -418,8 +415,6 @@ public function getImplementedInterfaces()
}

/**
* addProperties()
*
* @param array $properties
* @return ClassGenerator
*/
Expand Down Expand Up @@ -461,7 +456,7 @@ public function addProperty($name, $defaultValue = null, $flags = PropertyGenera
}

/**
* add property from PropertyGenerator
* Add property from PropertyGenerator
*
* @param string|PropertyGenerator $property
* @throws Exception\InvalidArgumentException
Expand All @@ -480,8 +475,6 @@ public function addPropertyFromGenerator(PropertyGenerator $property)
}

/**
* getProperties()
*
* @return PropertyGenerator[]
*/
public function getProperties()
Expand All @@ -490,8 +483,6 @@ public function getProperties()
}

/**
* getProperty()
*
* @param string $propertyName
* @return PropertyGenerator|false
*/
Expand All @@ -506,8 +497,6 @@ public function getProperty($propertyName)
}

/**
* hasProperty()
*
* @param string $propertyName
* @return bool
*/
Expand All @@ -517,8 +506,6 @@ public function hasProperty($propertyName)
}

/**
* addMethods()
*
* @param array $methods
* @return ClassGenerator
*/
Expand Down Expand Up @@ -561,7 +548,6 @@ public function addMethod($name = null, array $parameters = array(), $flags = Me
return $this->addMethodFromGenerator(new MethodGenerator($name, $parameters, $flags, $body, $docBlock));
}


/**
* Add Method from MethodGenerator
*
Expand All @@ -582,8 +568,6 @@ public function addMethodFromGenerator(MethodGenerator $method)
}

/**
* getMethods()
*
* @return MethodGenerator[]
*/
public function getMethods()
Expand All @@ -592,8 +576,6 @@ public function getMethods()
}

/**
* getMethod()
*
* @param string $methodName
* @return MethodGenerator|false
*/
Expand All @@ -608,8 +590,6 @@ public function getMethod($methodName)
}

/**
* hasMethod()
*
* @param string $methodName
* @return bool
*/
Expand All @@ -619,8 +599,6 @@ public function hasMethod($methodName)
}

/**
* isSourceDirty()
*
* @return bool
*/
public function isSourceDirty()
Expand All @@ -645,8 +623,6 @@ public function isSourceDirty()
}

/**
* generate()
*
* @return string
*/
public function generate()
Expand Down
Loading

0 comments on commit 457128c

Please sign in to comment.