Skip to content

Instantly share code, notes, and snippets.

@dunglas
Created February 16, 2015 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dunglas/0a4982e4635c9514aede to your computer and use it in GitHub Desktop.
Save dunglas/0a4982e4635c9514aede to your computer and use it in GitHub Desktop.
<?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