PHP code example of dunglas / php-property-info

1. Go to this page and download the library: Download dunglas/php-property-info library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dunglas / php-property-info example snippets




// Use Composer autoload
;
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')));