Skip to content

Commit

Permalink
Merge branch '5.3' into 5.4
Browse files Browse the repository at this point in the history
* 5.3:
  [HttpClient] Don't ignore errors from curl_multi_exec()
  [HttpClient] Double check if handle is complete
  CI for macOS
  [DependencyInjection] Resolve ChildDefinition in AbstractRecursivePass
  [Translation] [Bridge] [Lokalise] Fix push keys to lokalise. Closes #…
  [PropertyAccess] Fix accessing public property in Object
  [Process] fixed uppercase ARGC and ARGV should also be skipped
  [PropertyAccess] Add tests accessing public (dynamic) properties
  [Mailer] Update docs for sendmail -t
  [FrameworkBundle] Fix cache pool configuration with one adapter and one provider
  [FrameworkBundle] Use correct cookie domain in loginUser()
  Missing translations for Belarusian (be) #41032
  • Loading branch information
derrabus committed Dec 11, 2021
2 parents 07db4e9 + 8d01a4f commit 133c62a
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 2 deletions.
4 changes: 2 additions & 2 deletions PropertyAccessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ private function readProperty(array $zval, string $property, bool $ignoreInvalid
throw $e;
}
} elseif (PropertyReadInfo::TYPE_PROPERTY === $type) {
if (!method_exists($object, '__get') && !isset($object->$name) && !\array_key_exists($name, (array) $object) && (\PHP_VERSION_ID < 70400 || !(new \ReflectionProperty($class, $name))->hasType())) {
if ($access->canBeReference() && !isset($object->$name) && !\array_key_exists($name, (array) $object) && (\PHP_VERSION_ID < 70400 || !(new \ReflectionProperty($class, $name))->hasType())) {
throw new UninitializedPropertyException(sprintf('The property "%s::$%s" is not initialized.', $class, $name));
}

Expand All @@ -491,7 +491,7 @@ private function readProperty(array $zval, string $property, bool $ignoreInvalid

throw $e;
}
} elseif ($object instanceof \stdClass && property_exists($object, $property)) {
} elseif (property_exists($object, $property) && \array_key_exists($property, (array) $object)) {
$result[self::VALUE] = $object->$property;
if (isset($zval[self::REF])) {
$result[self::REF] = &$object->$property;
Expand Down
21 changes: 21 additions & 0 deletions Tests/Fixtures/TestPublicPropertyDynamicallyCreated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\PropertyAccess\Tests\Fixtures;

#[\AllowDynamicProperties]
class TestPublicPropertyDynamicallyCreated
{
public function __construct(string $bar)
{
$this->foo = $bar;
}
}
18 changes: 18 additions & 0 deletions Tests/Fixtures/TestPublicPropertyGetterOnObject.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\PropertyAccess\Tests\Fixtures;

class TestPublicPropertyGetterOnObject
{
public $a = 'A';
private $b = 'B';
}
25 changes: 25 additions & 0 deletions Tests/Fixtures/TestPublicPropertyGetterOnObjectMagicGet.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\PropertyAccess\Tests\Fixtures;

class TestPublicPropertyGetterOnObjectMagicGet
{
public $a = 'A';
private $b = 'B';

public function __get($property)
{
if ('b' === $property) {
return $this->b;
}
}
}
47 changes: 47 additions & 0 deletions Tests/PropertyAccessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
use Symfony\Component\PropertyAccess\Tests\Fixtures\TestClassMagicGet;
use Symfony\Component\PropertyAccess\Tests\Fixtures\TestClassSetValue;
use Symfony\Component\PropertyAccess\Tests\Fixtures\TestClassTypeErrorInsideCall;
use Symfony\Component\PropertyAccess\Tests\Fixtures\TestPublicPropertyDynamicallyCreated;
use Symfony\Component\PropertyAccess\Tests\Fixtures\TestPublicPropertyGetterOnObject;
use Symfony\Component\PropertyAccess\Tests\Fixtures\TestPublicPropertyGetterOnObjectMagicGet;
use Symfony\Component\PropertyAccess\Tests\Fixtures\TestSingularAndPluralProps;
use Symfony\Component\PropertyAccess\Tests\Fixtures\Ticket5775Object;
use Symfony\Component\PropertyAccess\Tests\Fixtures\TypeHinted;
Expand Down Expand Up @@ -946,4 +949,48 @@ public function testSetterNeedsPublicAccess()
$object = new TestClassSetValue(0);
$this->propertyAccessor->setValue($object, 'foo', 1);
}

public function testGetPublicProperty()
{
$value = 'A';
$path = 'a';
$object = new TestPublicPropertyGetterOnObject();

$this->assertSame($value, $this->propertyAccessor->getValue($object, $path));
}

public function testGetPrivateProperty()
{
$object = new TestPublicPropertyGetterOnObject();

$this->expectException(NoSuchPropertyException::class);
$this->expectExceptionMessageMatches('/.*Can\'t get a way to read the property "b" in class "Symfony\\\Component\\\PropertyAccess\\\Tests\\\Fixtures\\\TestPublicPropertyGetterOnObject./');
$this->propertyAccessor->getValue($object, 'b');
}

public function testGetDynamicPublicProperty()
{
$value = 'Bar';
$path = 'foo';
$object = new TestPublicPropertyDynamicallyCreated('Bar');

$this->assertSame($value, $this->propertyAccessor->getValue($object, $path));
}

public function testGetDynamicPublicPropertyWithMagicGetterDisallow()
{
$object = new TestPublicPropertyGetterOnObjectMagicGet();
$propertyAccessor = new PropertyAccessor(PropertyAccessor::DISALLOW_MAGIC_METHODS);

$this->expectException(NoSuchPropertyException::class);
$propertyAccessor->getValue($object, 'c');
}

public function testGetDynamicPublicPropertyWithMagicGetterAllow()
{
$value = 'B';
$path = 'b';
$object = new TestPublicPropertyGetterOnObjectMagicGet();
$this->assertSame($value, $this->propertyAccessor->getValue($object, $path));
}
}

0 comments on commit 133c62a

Please sign in to comment.