Ejemplo n.º 1
0
 /**
  * @see Sphpdox\Element.Element::__toString()
  */
 public function __toString()
 {
     $name = $this->reflection->getName();
     $title = str_replace('\\', '\\\\', $name);
     //$title = $name;
     $string = str_repeat('-', strlen($title)) . "\n";
     $string .= $title . "\n";
     $string .= str_repeat('-', strlen($title)) . "\n\n";
     $string .= $this->getNamespaceElement();
     if ($this->reflection->isInterface()) {
         $string .= '.. php:interface:: ';
     } elseif ($this->reflection->isTrait()) {
         $string .= '.. php:trait:: ';
     } else {
         $string .= '.. php:class:: ';
     }
     $string .= $this->reflection->getShortName();
     $parser = $this->getParser();
     if ($description = $parser->getDescription()) {
         $string .= "\n\n";
         $string .= $this->indent($description, 4);
     }
     foreach ($this->getSubElements() as $element) {
         $e = $element->__toString();
         if ($e) {
             $string .= "\n\n";
             $string .= $this->indent($e, 4);
         }
     }
     $string .= "\n\n";
     // Finally, fix some whitespace errors
     $string = preg_replace('/^\\s+$/m', '', $string);
     $string = preg_replace('/ +$/m', '', $string);
     return $string;
 }
Ejemplo n.º 2
0
 /**
  * @see Patgod85\Phpdoc2rst\Command\Process\Element.Element::__toString()
  */
 public function __toString()
 {
     $string = "====\n" . $this->reflection->getShortName() . "\n====";
     $parser = $this->getParser();
     if ($description = $parser->getDescription()) {
         $string .= "\n\n";
         $string .= $description;
     }
     /** @var Element $element */
     foreach ($this->getSubElements() as $element) {
         $e = $element->__toString();
         if ($e) {
             $string .= "\n\n";
             $string .= $e;
         }
     }
     $string .= "\n\n";
     // Finally, fix some whitespace errors
     $string = preg_replace('/^\\s+$/m', '', $string);
     $string = preg_replace('/ +$/m', '', $string);
     return $string;
 }
Ejemplo n.º 3
0
 /**
  * Generates an child code by parent class reflection and joinpoints for it
  *
  * @param ParsedClass $parent Parent class reflection
  * @param array|Advice[] $classAdvices List of advices for class
  * @param bool $useStaticForLsb Should proxy use 'static::class' instead of '\get_called_class()'
  *
  * @throws \InvalidArgumentException if there are unknown type of advices
  * @return ClassProxy
  */
 public function __construct(ParsedClass $parent, array $classAdvices, $useStaticForLsb = false)
 {
     parent::__construct($classAdvices, $useStaticForLsb);
     $this->class = $parent;
     $this->name = $parent->getShortName();
     $this->parentClassName = $parent->getShortName();
     $this->addInterface('\\Go\\Aop\\Proxy');
     $this->addJoinpointsProperty();
     foreach ($classAdvices as $type => $typedAdvices) {
         switch ($type) {
             case AspectContainer::METHOD_PREFIX:
             case AspectContainer::STATIC_METHOD_PREFIX:
                 foreach ($typedAdvices as $joinPointName => $advice) {
                     $method = $parent->getMethod($joinPointName);
                     if (!$method instanceof ParsedMethod) {
                         continue;
                     }
                     $this->overrideMethod($method);
                 }
                 break;
             case AspectContainer::PROPERTY_PREFIX:
                 foreach ($typedAdvices as $joinPointName => $advice) {
                     $property = $parent->getProperty($joinPointName);
                     if (!$property instanceof ParsedProperty) {
                         continue;
                     }
                     $this->interceptProperty($property);
                 }
                 break;
             case AspectContainer::INTRODUCTION_TRAIT_PREFIX:
                 foreach ($typedAdvices as $advice) {
                     /** @var $advice IntroductionInfo */
                     foreach ($advice->getInterfaces() as $interface) {
                         $this->addInterface($interface);
                     }
                     foreach ($advice->getTraits() as $trait) {
                         $this->addTrait($trait);
                     }
                 }
                 break;
             case AspectContainer::INIT_PREFIX:
             case AspectContainer::STATIC_INIT_PREFIX:
                 break;
                 // No changes for class
             // No changes for class
             default:
                 throw new \InvalidArgumentException("Unsupported point `{$type}`");
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * Adjust definition of original class source to enable extending
  *
  * @param ParsedClass $class Instance of class reflection
  * @param string $source Source code
  * @param string $newParentName New name for the parent class
  *
  * @return string Replaced code for class
  */
 private function adjustOriginalClass($class, $source, $newParentName)
 {
     $type = $this->kernel->hasFeature(Features::USE_TRAIT) && $class->isTrait() ? 'trait' : 'class';
     $source = preg_replace("/{$type}\\s+(" . $class->getShortName() . ')(\\b)/iS', "{$type} {$newParentName}\$2", $source);
     if ($class->isFinal()) {
         // Remove final from class, child will be final instead
         $source = str_replace("final {$type}", $type, $source);
     }
     return $source;
 }