Skip to content

Commit a06dc64

Browse files
committed
[Translatable] Fix property existence check at TranslatableListener::getTranslatableLocale()
1 parent af47302 commit a06dc64

File tree

3 files changed

+7
-13
lines changed

3 files changed

+7
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ a release.
2828
### Fixed
2929
- Sortable: Fix return value check of Comparable interface (#2541)
3030
- Uploadable: Retrieve the correct metadata when uploading entities of different classes (#2071)
31+
- Translatable: Fix property existence check at `TranslatableListener::getTranslatableLocale()`
3132

3233
### Deprecated
3334
- In order to close the API, `@final` and `@internal` annotations were added to all non base classes, which means that extending

phpstan-baseline.neon

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -510,11 +510,6 @@ parameters:
510510
count: 4
511511
path: src/Translatable/TranslatableListener.php
512512

513-
-
514-
message: "#^Negated boolean expression is always false\\.$#"
515-
count: 1
516-
path: src/Translatable/TranslatableListener.php
517-
518513
-
519514
message: "#^Call to an undefined method Gedmo\\\\Tree\\\\Strategy\\:\\:updateNode\\(\\)\\.$#"
520515
count: 1

src/Translatable/TranslatableListener.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -345,19 +345,17 @@ public function getListenerLocale()
345345
public function getTranslatableLocale($object, $meta, $om = null)
346346
{
347347
$locale = $this->locale;
348-
if (isset(self::$configurations[$this->name][$meta->getName()]['locale'])) {
349-
/** @var \ReflectionClass $class */
348+
$configurationLocale = self::$configurations[$this->name][$meta->getName()]['locale'] ?? null;
349+
if (null !== $configurationLocale) {
350350
$class = $meta->getReflectionClass();
351-
$reflectionProperty = $class->getProperty(self::$configurations[$this->name][$meta->getName()]['locale']);
352-
if (!$reflectionProperty) {
353-
$column = self::$configurations[$this->name][$meta->getName()]['locale'];
354-
355-
throw new \Gedmo\Exception\RuntimeException("There is no locale or language property ({$column}) found on object: {$meta->getName()}");
351+
if (!$class->hasProperty($configurationLocale)) {
352+
throw new \Gedmo\Exception\RuntimeException("There is no locale or language property ({$configurationLocale}) found on object: {$meta->getName()}");
356353
}
354+
$reflectionProperty = $class->getProperty($configurationLocale);
357355
$reflectionProperty->setAccessible(true);
358356
$value = $reflectionProperty->getValue($object);
359357
if (is_object($value) && method_exists($value, '__toString')) {
360-
$value = (string) $value;
358+
$value = $value->__toString();
361359
}
362360
if ($this->isValidLocale($value)) {
363361
$locale = $value;

0 commit comments

Comments
 (0)