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

Appearance settings

[PropertyAccess] Major performance improvement #16294

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

Closed
wants to merge 8 commits into from
Closed
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
Prev Previous commit
Next Next commit
Fix CS
  • Loading branch information
dunglas committed Oct 20, 2015
commit 50d7c0f6341f8265b31703b2f8da10ee8f8371d1
16 changes: 8 additions & 8 deletions 16 src/Symfony/Component/PropertyAccess/PropertyAccessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,9 @@ private function &readProperty(&$object, $property)

$access[self::ACCESS_REFLECTION_CLASS] = $reflClass = new \ReflectionClass($object);
Copy link
Member

Choose a reason for hiding this comment

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

putting the ReflectionClass in the cached data would make it much harder to persist the cache across requests. I suggest caching $classHasProperty instead (as this is the only thing you need actually)

$camelProp = $this->camelize($property);
$getter = 'get' . $camelProp;
$isser = 'is' . $camelProp;
$hasser = 'has' . $camelProp;
$getter = 'get'.$camelProp;
$isser = 'is'.$camelProp;
$hasser = 'has'.$camelProp;
$classHasProperty = $reflClass->hasProperty($property);

if ($reflClass->hasMethod($getter) && $reflClass->getMethod($getter)->isPublic()) {
Expand Down Expand Up @@ -261,7 +261,7 @@ private function &readProperty(&$object, $property)

$access[self::ACCESS_TYPE] = self::ACCESS_TYPE_NOT_FOUND;
$access[self::ACCESS_NAME] = sprintf(
'Neither the property "%s" nor one of the methods "%s()" ' .
'Neither the property "%s" nor one of the methods "%s()" '.
'exist and have public access in class "%s".',
$property,
implode('()", "', $methods),
Expand Down Expand Up @@ -353,7 +353,7 @@ private function writeProperty(&$object, $property, $singular, $value)
$plural = $this->camelize($property);

// Any of the two methods is required, but not yet known
$singulars = null !== $singular ? array($singular) : (array)StringUtil::singularify($plural);
$singulars = null !== $singular ? array($singular) : (array) StringUtil::singularify($plural);

if (is_array($value) || $value instanceof \Traversable) {
$methods = $this->findAdderAndRemover($reflClass, $singulars);
Expand All @@ -363,7 +363,7 @@ private function writeProperty(&$object, $property, $singular, $value)
// message. If the user implements the adder but not the remover,
// an exception will be thrown in findAdderAndRemover() that
// the remover has to be implemented as well.
$guessedAdders = '"add' . implode('()", "add', $singulars) . '()", ';
$guessedAdders = '"add'.implode('()", "add', $singulars).'()", ';
} else {
$access[self::ACCESS_TYPE] = self::ACCESS_TYPE_ADDER_AND_REMOVER;
$access[self::ACCESS_ADDER] = $methods[0];
Expand All @@ -372,7 +372,7 @@ private function writeProperty(&$object, $property, $singular, $value)
}

if (!isset($access[self::ACCESS_TYPE])) {
$setter = 'set' . $this->camelize($property);
$setter = 'set'.$this->camelize($property);
$classHasProperty = $reflClass->hasProperty($property);

if ($reflClass->hasMethod($setter) && $reflClass->getMethod($setter)->isPublic()) {
Expand All @@ -391,7 +391,7 @@ private function writeProperty(&$object, $property, $singular, $value)
} else {
$access[self::ACCESS_TYPE] = self::ACCESS_TYPE_NOT_FOUND;
$access[self::ACCESS_NAME] = sprintf(
'Neither the property "%s" nor one of the methods %s"%s()", ' .
'Neither the property "%s" nor one of the methods %s"%s()", '.
'"__set()" or "__call()" exist and have public access in class "%s".',
$property,
$guessedAdders,
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.