8000 Allow Upper Case property names · symfony/symfony@2fe1631 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2fe1631

Browse files
insekticidfabpot
authored andcommitted
Allow Upper Case property names
ReflectionExtractor::getProperties() returns $id instead of $Id. It is bad naming convention, but is possible ``` class Entity { protected $Id; public function getId() { return $this->Id; } } ``` # Conflicts: # src/Symfony/Component/PropertyInfo/Tests/Extractors/ReflectionExtractorTest.php # src/Symfony/Component/PropertyInfo/Tests/Fixtures/Dummy.php
1 parent 6b862e8 commit 2fe1631

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function getProperties($class, array $context = array())
7676
if (!$propertyName || isset($properties[$propertyName])) {
7777
continue;
7878
}
79-
if (!preg_match('/^[A-Z]{2,}/', $propertyName)) {
79+
if (!$reflectionClass->hasProperty($propertyName) && !preg_match('/^[A-Z]{2,}/', $propertyName)) {
8080
$propertyName = lcfirst($propertyName);
8181
}
8282
$properties[$propertyName] = true;

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public function testGetProperties()
3838
'parent',
3939
'collection',
4040
'B',
41+
'Guid',
4142
'g',
4243
'foo',
4344
'foo2',
@@ -47,6 +48,7 @@ public function testGetProperties()
4748
'files',
4849
'a',
4950
'DOB',
51+
'Id',
5052
'c',
5153
'd',
5254
'e',
@@ -129,6 +131,10 @@ public function testIsReadable()
129131
$this->assertTrue($this->extractor->isReadable('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', 'd', array()));
130132
$this->assertFalse($this->extractor->isReadable('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', 'e', array()));
131133
$this->assertFalse($this->extractor->isReadable('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', 'f', array()));
134+
$this->assertTrue($this->extractor->isReadable('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', 'Id', array()));
135+
$this->assertTrue($this->extractor->isReadable('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', 'id', array()));
136+
$this->assertTrue($this->extractor->isReadable('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', 'Guid', array()));
137+
$this->assertFalse($this->extractor->isReadable('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', 'guid', array()));
132138
}
133139

134140
public function testIsWritable()
@@ -142,5 +148,8 @@ public function testIsWritable()
142148
$this->assertFalse($this->extractor->isWritable('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', 'd', array()));
143149
$this->assertTrue($this->extractor->isWritable('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', 'e', array()));
144150
$this->assertTrue($this->extractor->isWritable('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', 'f', array()));
151+
$this->assertFalse($this->extractor->isWritable('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', 'Id', array()));
152+
$this->assertTrue($this->extractor->isWritable('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', 'Guid', array()));
153+
$this->assertFalse($this->extractor->isWritable('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', 'guid', array()));
145154
}
146155
}

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ class Dummy extends ParentDummy
5151
*/
5252
public $B;
5353

54+
/**
55+
* @var int
56+
*/
57+
protected $Id;
58+
59+
/**
60+
* @var string
61+
*/
62+
public $Guid;
63+
5464
/**
5565
* Nullable array.
5666
*
@@ -99,4 +109,11 @@ public function setB(ParentDummy $parent = null)
99109
public function getDOB()
100110
{
101111
}
112+
113+
/**
114+
* @return int
115+
*/
116+
public function getId()
117+
{
118+
}
102119
}

0 commit comments

Comments
 (0)
0