Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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

Closed
dunglas wants to merge2 commits intosymfony:2.8fromdunglas:propertyinfo
Closed

Conversation

@dunglas
Copy link
Member

QA
Doc fix?no
New docs?yes (symfony/symfony#15858)
Applies to2.8, 3.0
Fixed ticketsn/a

@dupuchba
Copy link

👍

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
Copy link
MemberAuthor

@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
Copy link

👍

@xabbuh
Copy link
Member

The new file must also be added to the toctree in/components/index.rst.

Copy link
Member

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.

fabpot added a commit to symfony/symfony that referenced this pull requestSep 26, 2015
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
@weaverryanweaverryan added this to the2.8 milestoneSep 26, 2015
Copy link
Member

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
Copy link
Member

ping@dunglas

@javiereguiluz
Copy link
Member

I've finished this work in#6047.@dunglas I've reused your original commits so you'll get full credit for your work. Thanks!

@dunglasdunglas deleted the propertyinfo branchDecember 19, 2015 11:45
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

2.8

Development

Successfully merging this pull request may close these issues.

7 participants

@dunglas@dupuchba@xabbuh@weaverryan@javiereguiluz@catchamonkey@wouterj

[8]ページ先頭

©2009-2025 Movatter.jp