Inheritance: extends phpDocumentor\Descriptor\DescriptorAbstract, implements phpDocumentor\Descriptor\Interfaces\TraitInterface
コード例 #1
0
 /**
  * @covers phpDocumentor\Descriptor\TraitDescriptor::setMethods
  * @covers phpDocumentor\Descriptor\TraitDescriptor::getMethods
  */
 public function testSettingAndGettingMethods()
 {
     $this->assertInstanceOf('phpDocumentor\\Descriptor\\Collection', $this->fixture->getMethods());
     $mock = m::mock('phpDocumentor\\Descriptor\\Collection');
     $this->fixture->setMethods($mock);
     $this->assertSame($mock, $this->fixture->getMethods());
 }
コード例 #2
0
 /**
  * Checks if the passed value is valid.
  *
  * @param FileDescriptor|ClassDescriptor|InterfaceDescriptor|TraitDescriptor $value      The value that should
  *     be validated.
  * @param Constraint                                                         $constraint The constraint for
  *     the validation.
  *
  * @throws ConstraintDefinitionException if this is not a constraint on a PropertyDescriptor object.
  */
 public function validate($value, Constraint $constraint)
 {
     if (!$value instanceof FileDescriptor && !$value instanceof ClassDescriptor && !$value instanceof InterfaceDescriptor && !$value instanceof TraitDescriptor) {
         throw new ConstraintDefinitionException('The HasPackageWithSubpackageValidator validator may only be used on files, classes, ' . 'interfaces and traits');
     }
     if ($value->getTags()->get('subpackage', new Collection())->count() > 0 && $value->getTags()->get('package', new Collection())->count() < 1) {
         $this->context->addViolationAt('package', $constraint->message, array(), null, null, $constraint->code);
     }
 }
コード例 #3
0
 /**
  * Checks if the passed value is valid.
  *
  * @param FileDescriptor|ClassDescriptor|InterfaceDescriptor|TraitDescriptor $value      The value that should
  *     be validated.
  * @param Constraint                                                         $constraint The constraint for
  *     the validation.
  *
  * @throws ConstraintDefinitionException if this is not a constraint on a PropertyDescriptor object.
  */
 public function validate($value, Constraint $constraint)
 {
     if (!$value instanceof FileDescriptor && !$value instanceof ClassDescriptor && !$value instanceof InterfaceDescriptor && !$value instanceof TraitDescriptor) {
         throw new ConstraintDefinitionException('The HasSinglePackage validator may only be used on files, classes, interfaces and traits');
     }
     if ($value->getTags()->get('package', new Collection())->count() > 1) {
         $this->context->addViolationAt('package', $constraint->message);
     }
 }
コード例 #4
0
 /**
  * @covers phpDocumentor\Descriptor\TraitDescriptor::getUsedTraits
  * @covers phpDocumentor\Descriptor\TraitDescriptor::setUsedTraits
  */
 public function testSettingAndGettingUsedTraits()
 {
     $this->assertInstanceOf('phpDocumentor\\Descriptor\\Collection', $this->fixture->getUsedTraits());
     $usedTraitsCollection = new Collection();
     $this->fixture->setUsedTraits($usedTraitsCollection);
     $this->assertSame($usedTraitsCollection, $this->fixture->getUsedTraits());
 }
コード例 #5
0
 /**
  * Creates a Descriptor from the provided data.
  *
  * @param TraitReflector $data
  *
  * @return TraitDescriptor
  */
 public function create($data)
 {
     $traitDescriptor = new TraitDescriptor();
     $traitDescriptor->setFullyQualifiedStructuralElementName($data->getName());
     $traitDescriptor->setName($data->getShortName());
     $traitDescriptor->setLine($data->getLinenumber());
     $traitDescriptor->setPackage($this->extractPackageFromDocBlock($data->getDocBlock()) ?: '');
     // Reflection library formulates namespace as global but this is not wanted for phpDocumentor itself
     $traitDescriptor->setNamespace('\\' . (strtolower($data->getNamespace()) == 'global' ? '' : $data->getNamespace()));
     $this->assembleDocBlock($data->getDocBlock(), $traitDescriptor);
     $this->addProperties($data->getProperties(), $traitDescriptor);
     $this->addMethods($data->getMethods(), $traitDescriptor);
     return $traitDescriptor;
 }
コード例 #6
0
 /**
  * Export the given reflected Trait definition to the provided parent element.
  *
  * This method creates a new child element on the given parent XML element
  * and takes the properties of the Reflection argument and sets the
  * elements and attributes on the child.
  *
  * If a child DOMElement is provided then the properties and attributes are
  * set on this but the child element is not appended onto the parent. This
  * is the responsibility of the invoker. Essentially this means that the
  * $parent argument is ignored in this case.
  *
  * @param \DOMElement        $parent Element to augment.
  * @param TraitDescriptor $trait Element to export.
  *
  * @return \DOMElement
  */
 public function convert(\DOMElement $parent, TraitDescriptor $trait)
 {
     $child = new \DOMElement('trait');
     $parent->appendChild($child);
     $namespace = $trait->getNamespace()->getFullyQualifiedStructuralElementName();
     $child->setAttribute('namespace', ltrim($namespace, '\\'));
     $child->setAttribute('line', $trait->getLine());
     $child->appendChild(new \DOMElement('name', $trait->getName()));
     $child->appendChild(new \DOMElement('full_name', $trait->getFullyQualifiedStructuralElementName()));
     $this->docBlockConverter->convert($child, $trait);
     foreach ($trait->getProperties() as $property) {
         $this->propertyConverter->convert($child, $property);
     }
     foreach ($trait->getMethods() as $method) {
         $this->methodConverter->convert($child, $method);
     }
     return $child;
 }
コード例 #7
0
 /**
  * @param ClassDescriptor|TraitDescriptor $parent
  */
 public function setParent($parent)
 {
     $this->setFullyQualifiedStructuralElementName($parent->getFullyQualifiedStructuralElementName() . '::' . $this->getName());
     $this->parent = $parent;
 }
コード例 #8
0
ファイル: Xml.php プロジェクト: michaelyin1/Modern-Toolkit
 /**
  * Exports the given reflection object to the parent XML element.
  *
  * This method creates a new child element on the given parent XML element
  * and takes the properties of the Reflection argument and sets the
  * elements and attributes on the child.
  *
  * If a child DOMElement is provided then the properties and attributes are
  * set on this but the child element is not appended onto the parent. This
  * is the responsibility of the invoker. Essentially this means that the
  * $parent argument is ignored in this case.
  *
  * @param \DOMElement     $parent The parent element to augment.
  * @param ClassDescriptor $trait  The data source.
  * @param \DOMElement     $child  Optional: child element to use instead of creating a
  *      new one on the $parent.
  *
  * @return void
  */
 public function buildTrait(\DOMElement $parent, TraitDescriptor $trait, \DOMElement $child = null)
 {
     if (!$child) {
         $child = new \DOMElement('trait');
         $parent->appendChild($child);
     }
     $child->setAttribute('final', $trait->isFinal() ? 'true' : 'false');
     $child->setAttribute('abstract', $trait->isAbstract() ? 'true' : 'false');
     $namespace = $trait->getNamespace();
     $child->setAttribute('namespace', ltrim($namespace, '\\'));
     $child->setAttribute('line', $trait->getLine());
     $child->appendChild(new \DOMElement('name', $trait->getName()));
     $child->appendChild(new \DOMElement('full_name', $trait->getFullyQualifiedStructuralElementName()));
     $this->buildDocBlock($child, $trait);
     foreach ($trait->getProperties() as $property) {
         $this->buildProperty($child, $property);
     }
     foreach ($trait->getMethods() as $method) {
         $this->buildMethod($child, $method);
     }
 }
コード例 #9
0
 /**
  * @covers phpDocumentor\Compiler\Pass\PackageTreeBuilder::execute
  * @covers phpDocumentor\Compiler\Pass\PackageTreeBuilder::addElementsOfTypeToPackage
  */
 public function testAddTraitToNamespace()
 {
     $trait = new TraitDescriptor();
     $trait->setPackage('My\\Space');
     $trait->setFullyQualifiedStructuralElementName('My\\Space\\Trait1');
     $this->project->getFiles()->get(0)->getTraits()->add($trait);
     // double check if a second trait in the same deep namespace ends up at the right location
     $trait2 = new TraitDescriptor();
     $trait2->setPackage('My\\Space');
     $trait2->setFullyQualifiedStructuralElementName('My\\Space\\Trait2');
     $this->project->getFiles()->get(0)->getTraits()->add($trait2);
     $this->fixture->execute($this->project);
     $this->assertSame(array($trait, $trait2), $this->project->getIndexes()->get('packages')->get('\\My\\Space')->getTraits()->getAll());
 }
コード例 #10
0
 /**
  * @covers phpDocumentor\Compiler\Pass\ElementsIndexBuilder::execute
  * @covers phpDocumentor\Compiler\Pass\ElementsIndexBuilder::addElementsToIndexes
  * @covers phpDocumentor\Compiler\Pass\ElementsIndexBuilder::getIndexKey
  */
 public function testAddTraitsToIndex()
 {
     $file1 = $this->project->getFiles()->get(0);
     $traitDescriptor1 = new TraitDescriptor();
     $traitDescriptor1->setFullyQualifiedStructuralElementName('My\\Space\\Trait1');
     $file1->getTraits()->add($traitDescriptor1);
     $file2 = $this->project->getFiles()->get(1);
     $traitDescriptor2 = new TraitDescriptor();
     $traitDescriptor2->setFullyQualifiedStructuralElementName('My\\Space\\Trait2');
     $file2->getTraits()->add($traitDescriptor2);
     $this->fixture->execute($this->project);
     $elements = $this->project->getIndexes()->get('elements')->getAll();
     $this->assertCount(2, $elements);
     $this->assertSame(array('My\\Space\\Trait1', 'My\\Space\\Trait2'), array_keys($elements));
     $this->assertSame(array($traitDescriptor1, $traitDescriptor2), array_values($elements));
     $elements = $this->project->getIndexes()->get('traits')->getAll();
     $this->assertCount(2, $elements);
     $this->assertSame(array('My\\Space\\Trait1', 'My\\Space\\Trait2'), array_keys($elements));
     $this->assertSame(array($traitDescriptor1, $traitDescriptor2), array_values($elements));
 }