8000 bug #16911 [PropertyInfo] Update List Information from ReflectionExtr… · symfony/symfony@f50f92a · GitHub
[go: up one dir, main page]

Skip to content

Commit f50f92a

Browse files
committed
bug #16911 [PropertyInfo] Update List Information from ReflectionExtractor (zanderbaldwin)
This PR was squashed before being merged into the 2.8 branch (closes #16911). Discussion ---------- [PropertyInfo] Update List Information from ReflectionExtractor | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #16889 | License | MIT | Doc PR | symfony/symfony-docs#5974 Unless a property with the same casing exists, lowercase the first letter of a property name extracted from a method. From what I understand, we don't actually need to support `snake_case` at all in the PropertyInfo component. I cannot think of any use-case where PropertyAccess would be used to get/set a property value *before* using PropertyInfo to find out information about the property and the values it supports. Since PropertyInfo supports the discovery of property names, which can then be used as identifiers in PropertyAccess, there should be no need to support a naming strategy to map property identifiers from one naming convention to another. --- Running `$reflectionExtractor->getProperties($class)` with the following classes: ```php class X { public $a; public $b; public function getA() {} } // Result: array('a', 'b'); ``` ```php class Y { public $A; public $b; public function setA() {} } // Result: array('A', 'b'); ``` ```php class Y { public $username; protected $emailAddress; public $password; public function getEmailAddress() {} public function isActive() {} } // Result: array('username', 'emailAddress', 'password', 'active'); ``` Commits ------- b2da76c [PropertyInfo] Update List Information from ReflectionExtractor
2 parents 25b89d4 + b2da76c commit f50f92a

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,13 @@ public function getProperties($class, array $context = array())
6262

6363
foreach ($reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $reflectionMethod) {
6464
$propertyName = $this->getPropertyName($reflectionMethod->name);
65-
if ($propertyName) {
66-
$properties[$propertyName] = true;
65+
if (!$propertyName || isset($properties[$propertyName])) {
66+
continue;
6767
}
68+
if (!preg_match('/^[A-Z]{2,}/', $propertyName)) {
69+
$propertyName = lcfirst($propertyName);
70+
}
71+
$properties[$propertyName] = true;
6872
}
6973

7074
return array_keys($properties);

src/Symfony/Component/PropertyInfo/Tests/Extractors/ReflectionExtractorTest.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,19 @@ public function testGetProperties()
3636
'bal',
3737
'parent',
3838
'collection',
39+
'B',
3940
'foo',
4041
'foo2',
4142
'foo3',
4243
'foo4',
4344
'foo5',
4445
'files',
45-
'A',
46-
'B',
47-
'C',
48-
'D',
49-
'E',
50-
'F',
46+
'a',
47+
'DOB',
48+
'c',
49+
'd',
50+
'e',
51+
'f',
5152
),
5253
$this->extractor->getProperties('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy')
5354
);

src/Symfony/Component/PropertyInfo/Tests/Fixtures/Dummy.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ class Dummy extends ParentDummy
4646
*/
4747
public $collection;
4848

49+
/**
50+
* @var ParentDummy
51+
*/
52+
public $B;
53+
4954
/**
5055
* A.
5156
*
@@ -63,4 +68,13 @@ public function getA()
6368
public function setB(ParentDummy $parent = null)
6469
{
6570
}
< 6687 code>71+
72+
/**
73+
* Date of Birth.
74+
*
75+
* @return \DateTime
76+
*/
77+
public function getDOB()
78+
{
79+
}
6680
}

0 commit comments

Comments
 (0)
0