Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork5.3k
[PropertyInfo] Add the doc#5717
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
dunglas commentedSep 22, 2015
| Q | A |
|---|---|
| Doc fix? | no |
| New docs? | yes (symfony/symfony#15858) |
| Applies to | 2.8, 3.0 |
| Fixed tickets | n/a |
dupuchba commentedSep 22, 2015
👍 IMO, it would be worthy to add at least one use case in which PropertyInfo component could be use (typically the api-platform usage for example) |
dunglas commentedSep 22, 2015
@dupuchba IMO it's out of scope of this document but as I'll use it in the Serializer Component I'll add this use case as an example when it will be done. |
dupuchba commentedSep 23, 2015
👍 |
xabbuh commentedSep 23, 2015
The new file must also be added to the toctree in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
The reference to Packagist at the bottom of the file is missing.
This PR was squashed before being merged into the 2.8 branch (closes#15858).Discussion----------[PropertyInfo] Import the component| Q | A| ------------- | ---| Bug fix? | no| New feature? | yes| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets | n/a| License | MIT| Doc PR |symfony/symfony-docs#5717As discussed with@fabpot (see#14844), this PR moves [dunglas/php-property-info](https://github.com/dunglas/php-property-info) under the Symfony umbrella.Rationale behind this new component (extracted from README.md):PHP doesn't support explicit type definition. This is annoying, especially when doing meta programming.Various libraries including but not limited to Doctrine ORM and the Symfony Validator provide their own type managingsystem.This library extracts various information including the type and documentation from PHP class property from metadata of popular sources:* Setter method with type hint* PHPDoc DocBlock* Doctrine ORM mapping (annotation, XML, YML or custom format)* PHP 7 scalar typehint and return type* Serializer metadata**Usage:**```php<?php// Use Composer autoloadrequire 'vendor/autoload.php';use Doctrine\ORM\EntityManager;use Doctrine\ORM\Tools\Setup;use Doctrine\ORM\Mapping\Column;use Doctrine\ORM\Mapping\Entity;use Doctrine\ORM\Mapping\Id;use Symfony\Component\PropertyInfo\Extractors\DoctrineExtractor;use Symfony\Component\PropertyInfo\Extractors\PhpDocExtractor;use Symfony\Component\PropertyInfo\Extractors\ReflectionExtractor;use Symfony\Component\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();$reflectionExtractor = new ReflectionExtractor();$propertyInfo = new PropertyInfo( array($reflectionExtractor), array($doctrineExtractor, $phpDocExtractor, $reflectionExtractor), array($phpDocExtractor), array($reflectionExtractor));var_dump($propertyInfo->getProperties('MyTestClass'));var_dump($propertyInfo->getTypes('MyTestClass', 'foo'));var_dump($propertyInfo->getTypes('MyTestClass', 'id'));var_dump($propertyInfo->getTypes('MyTestClass', 'bar'));var_dump($propertyInfo->isReadable('MyTestClass', 'id'));var_dump($propertyInfo->isReadable('MyTestClass', 'bar'));var_dump($propertyInfo->isWritable('MyTestClass', 'foo'));var_dump($propertyInfo->isWritable('MyTestClass', 'bar'));var_dump($propertyInfo->getShortDescription('MyTestClass', 'foo'));var_dump($propertyInfo->getLongDescription('MyTestClass', 'foo'));```Output:```array(3) { [0] => string(2) "id" [1] => string(3) "foo" [2] => string(3) "Bar"}array(1) { [0] => class Symfony\Component\PropertyInfo\Type#36 (6) { private $builtinType => string(6) "object" private $nullable => bool(false) private $class => string(8) "DateTime" private $collection => bool(false) private $collectionKeyType => NULL private $collectionValueType => NULL }}array(1) { [0] => class Symfony\Component\PropertyInfo\Type#36 (6) { private $builtinType => string(3) "int" private $nullable => bool(false) private $class => NULL private $collection => bool(false) private $collectionKeyType => NULL private $collectionValueType => NULL }}array(1) { [0] => class Symfony\Component\PropertyInfo\Type#245 (6) { private $builtinType => string(6) "object" private $nullable => bool(false) private $class => string(11) "SplFileInfo" private $collection => bool(false) private $collectionKeyType => NULL private $collectionValueType => NULL }}bool(true)bool(false)bool(true)bool(true)string(35) "This is a date (short description)."string(24) "With a long description."```Commits-------f1eb185 [PropertyInfo] Import the component
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I would say it's "properties of the PHP class", but I'm not sure (I remember having the same discussion with "the classes constructor").
weaverryan commentedNov 27, 2015
ping@dunglas |