Created
February 16, 2015 18:04
-
-
Save dunglas/0a4982e4635c9514aede to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
<<<CONFIG | |
packages: | |
- "dunglas/php-property-info: dev-master" | |
- "doctrine/orm: ~2.3" | |
- "phpdocumentor/reflection: ~1.0" | |
CONFIG; | |
use Doctrine\ORM\EntityManager; | |
use Doctrine\ORM\Tools\Setup; | |
use Doctrine\ORM\Mapping\Column; | |
use Doctrine\ORM\Mapping\Entity; | |
use Doctrine\ORM\Mapping\Id; | |
// PropoertyInfo uses | |
use PropertyInfo\Extractors\DoctrineExtractor; | |
use PropertyInfo\Extractors\PhpDocExtractor; | |
use PropertyInfo\Extractors\SetterExtractor; | |
use PropertyInfo\PropertyInfo; | |
/** | |
* @Entity | |
*/ | |
class MyTestClass | |
{ | |
/** | |
* @Id | |
* @Column(type="integer") | |
*/ | |
public $id; | |
/** | |
* This is a date (short description). | |
* | |
* With a long description. | |
* | |
* @var \DateTime | |
*/ | |
public $foo; | |
private $bar; | |
public function setBar(\SplFileInfo $bar) | |
{ | |
$this->bar = $bar; | |
} | |
} | |
// Doctrine initialization (necessary only to use the Doctrine Extractor) | |
$config = Setup::createAnnotationMetadataConfiguration([__DIR__], true); | |
$entityManager = EntityManager::create([ | |
'driver' => 'pdo_sqlite', | |
// ... | |
], $config); | |
$doctrineExtractor = new DoctrineExtractor($entityManager->getMetadataFactory()); | |
$phpDocExtractor = new PhpDocExtractor(); | |
$setterExtractor = new SetterExtractor(); | |
$propertyInfo = new PropertyInfo([$doctrineExtractor, $setterExtractor, $phpDocExtractor], [$phpDocExtractor]); | |
$fooProperty = new \ReflectionProperty('MyTestClass', 'foo'); | |
var_dump($propertyInfo->getShortDescription($fooProperty)); | |
var_dump($propertyInfo->getLongDescription($fooProperty)); | |
var_dump($propertyInfo->getTypes($fooProperty)); | |
var_dump($propertyInfo->getTypes(new \ReflectionProperty('MyTestClass', 'id'))); | |
var_dump($propertyInfo->getTypes(new \ReflectionProperty('MyTestClass', 'bar'))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment