8000 [PropertyAccess] Added isReadable() and isWritable() by webmozart · Pull Request #10570 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[PropertyAccess] Added isReadable() and isWritable() #10570

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 31, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[PropertyAccess] Refactored PropertyAccessorTest
  • Loading branch information
webmozart committed Mar 28, 2014
commit 0488389d95033a60b3de14340c5a532c6a6af18f
11 changes: 6 additions & 5 deletions src/Symfony/Component/PropertyAccess/PropertyAccessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function setValue(&$objectOrArray, $propertyPath, $value)
*
* @throws UnexpectedTypeException If a value within the path is neither object nor array.
*/
private function &readPropertiesUntil(&$objectOrArray, PropertyPathInterface $propertyPath, $lastIndex, $throwExceptionOnNonexistantIndex = false)
private function &readPropertiesUntil(&$objectOrArray, PropertyPathInterface $propertyPath, $lastIndex, $throwExceptionOnInvalidIndex = false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing phpdoc for $throwExceptionOnInvalidIndex

{
$propertyValues = array();

Expand All @@ -131,9 +131,10 @@ private function &readPropertiesUntil(&$objectOrArray, PropertyPathInterface $pr

// Create missing nested arrays on demand
if ($isIndex && $isArrayAccess && !isset($objectOrArray[$property])) {
if ($throwExceptionOnNonexistantIndex) {
if ($throwExceptionOnInvalidIndex) {
throw new NoSuchIndexException(sprintf('Cannot read property "%s". Available properties are "%s"', $property, print_r(array_keys($objectOrArray), true)));
}

$objectOrArray[$property] = $i + 1 < $propertyPath->getLength() ? array() : null;
}

Expand Down Expand Up @@ -412,8 +413,8 @@ private function findAdderAndRemover(\ReflectionClass $reflClass, array $singula
$addMethod = 'add'.$singular;
$removeMethod = 'remove'.$singular;

$addMethodFound = $this->isAccessible($reflClass, $addMethod, 1);
$removeMethodFound = $this->isAccessible($reflClass, $removeMethod, 1);
$addMethodFound = $this->isMethodAccessible($reflClass, $addMethod, 1);
$removeMethodFound = $this->isMethodAccessible($reflClass, $removeMethod, 1);

if ($addMethodFound && $removeMethodFound) {
return array($addMethod, $removeMethod);
Expand Down Expand Up @@ -442,7 +443,7 @@ private function findAdderAndRemover(\ReflectionClass $reflClass, array $singula
* @return Boolean Whether the method is public and has $parameters
* required parameters
*/
private function isAccessible(\ReflectionClass $class, $methodName, $parameters)
private function isMethodAccessible(\ReflectionClass $class, $methodName, $parameters)
{
if ($class->hasMethod($methodName)) {
$method = $class->getMethod($methodName);
Expand Down
71 changes: 0 additions & 71 deletions src/Symfony/Component/PropertyAccess/Tests/Fixtures/Author.php

This file w 8000 as deleted.

27 changes: 0 additions & 27 deletions src/Symfony/Component/PropertyAccess/Tests/Fixtures/Magician.php

This file was deleted.

This file was deleted.

115 changes: 115 additions & 0 deletions src/Symfony/Component/PropertyAccess/Tests/Fixtures/TestClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?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 TestClass
{
public $publicProperty;
protected $protectedProperty;
private $privateProperty;

private $publicAccessor;
private $publicIsAccessor;
private $publicHasAccessor;

public function __construct($value)
{
$this->publicProperty = $value;
$this->publicAccessor = $value;
$this->publicIsAccessor = $value;
$this->publicHasAccessor = $value;
}

public function setPublicAccessor($value)
{
$this->publicAccessor = $value;
}

public function getPublicAccessor()
{
return $this->publicAccessor;
}

public function setPublicIsAccessor($value)
{
$this->publicIsAccessor = $value;
}

public function isPublicIsAccessor()
{
return $this->publicIsAccessor;
}

public function setPublicHasAccessor($value)
{
$this->publicHasAccessor = $value;
}

public function hasPublicHasAccessor()
{
return $this->publicHasAccessor;
}

protected function setProtectedAccessor($value)
{
}

protected function getProtectedAccessor()
{
return 'foobar';
}

protected function setProtectedIsAccessor($value)
{
}

protected function isProtectedIsAccessor()
{
return 'foobar';
}

protected function setProtectedHasAccessor($value)
{
}

protected function hasProtectedHasAccessor()
{
return 'foobar';
}

private function setPrivateAccessor($value)
{
}

private function getPrivateAccessor()
{
return 'foobar';
}

private function setPrivateIsAccessor($value)
{
}

private function isPrivateIsAccessor()
{
return 'foobar';
}

private function setPrivateHasAccessor($value)
{
}

private function hasPrivateHasAccessor()
{
return 'foobar';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?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 TestClassMagicCall
{
private $magicCallProperty;

public function __construct($value)
{
$this->magicCallProperty = $value;
}

public function __call($method, array $args)
{
if ('getMagicCallProperty' === $method) {
return $this->magicCallProperty;
}

if ('getConstantMagicCallProperty' === $method) {
return 'constant value';
}

if ('setMagicCallProperty' === $method) {
$this->magicCallProperty = reset($args);
}

return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?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 TestClassMagicGet
{
private $magicProperty;

public function __construct($value)
{
$this->magicProperty = $value;
}

public function __set($property, $value)
{
if ('magicProperty' === $property) {
$this->magicProperty = $value;
}
}

public function __get($property)
{
if ('magicProperty' === $property) {
return $this->magicProperty;
}

if ('constantMagicProperty' === $property) {
return 'constant value';
}

return null;
}
}
Loading
0