Skip to content

Commit

Permalink
use CodeGenerator from ZF 2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
fooman committed May 20, 2015
1 parent a2c4e7a commit d596078
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 98 deletions.
94 changes: 0 additions & 94 deletions lib/internal/Magento/Framework/Code/Generator/ClassGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,27 +61,6 @@ class ClassGenerator extends \Zend\Code\Generator\ClassGenerator implements
'passedByReference' => 'setPassedByReference',
];

/**
* @var array Array of string names
*/
protected $traits = array();

public function setTraits(array $traits)
{
$this->traits = $traits;
return $this;
}

/**
* Returns the "traits" classes
*
* @return array
*/
public function getTraits()
{
return $this->traits;
}

/**
* @param object $object
* @param array $data
Expand Down Expand Up @@ -230,77 +209,4 @@ public function getNamespaceName()
{
return ltrim(parent::getNamespaceName(), '\\');
}

/**
* @return string
*/
public function generate()
{
if (!$this->isSourceDirty()) {
$output = $this->getSourceContent();
if (!empty($output)) {
return $output;
}
}

$output = '';

if (null !== ($namespace = $this->getNamespaceName())) {
$output .= 'namespace ' . $namespace . ';' . self::LINE_FEED . self::LINE_FEED;
}

$uses = $this->getUses();
if (!empty($uses)) {
foreach ($uses as $use) {
$output .= 'use ' . $use . ';' . self::LINE_FEED;
}
$output .= self::LINE_FEED;
}

if (null !== ($docBlock = $this->getDocBlock())) {
$docBlock->setIndentation('');
$output .= $docBlock->generate();
}

if ($this->isAbstract()) {
$output .= 'abstract ';
}

$output .= 'class ' . $this->getName();

if (!empty($this->extendedClass)) {
$output .= ' extends ' . $this->extendedClass;
}

$implemented = $this->getImplementedInterfaces();
if (!empty($implemented)) {
$output .= ' implements ' . implode(', ', $implemented);
}

$output .= self::LINE_FEED . '{' . self::LINE_FEED . self::LINE_FEED;

$traits = $this->getTraits();
if (!empty($traits)) {
$output .= self::LINE_FEED . $this->indentation
. 'use ' . (implode(', ', $traits)) . ';' . self::LINE_FEED . self::LINE_FEED;
}

$properties = $this->getProperties();
if (!empty($properties)) {
foreach ($properties as $property) {
$output .= $property->generate() . self::LINE_FEED . self::LINE_FEED;
}
}

$methods = $this->getMethods();
if (!empty($methods)) {
foreach ($methods as $method) {
$output .= $method->generate() . self::LINE_FEED;
}
}

$output .= self::LINE_FEED . '}' . self::LINE_FEED;

return $output;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ public function setExtendedClass($extendedClass);
public function setImplementedInterfaces(array $interfaces);

/**
* Set a list of traits.
* Add a trait to the class.
*
* @param array $traits
* @param $trait
* @return $this
*/
public function setTraits(array $traits);
public function addTrait($trait);
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ protected function _generateCode()
} else {
$this->_classGenerator->setExtendedClass($typeName);
}
$this->_classGenerator->setTraits(['\Magento\Framework\Interception\Interceptor']);
$this->_classGenerator->addTrait('\Magento\Framework\Interception\Interceptor');
return parent::_generateCode();
}

Expand Down

0 comments on commit d596078

Please sign in to comment.