8000 [Serializer] Improve perf a bit by not using a signaling exception when not needed by nicolas-grekas · Pull Request #28910 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
[Serializer] Improve perf a bit by not using a signaling exception wh…
…en not needed
  • Loading branch information
nicolas-grekas committed Oct 17, 2018
commit 2a2914e20880ded497f9347b1b827ce24a4047ab
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
->prototype('scalar')
->cannotBeEmpty()
->validate()
->ifTrue(function ($v) { return !class_exists($v) && !interface_exists($v); })
->ifTrue(function ($v) { return !class_exists($v) && !interface_exists($v, false); })
->thenInvalid('The supported class or interface "%s" does not exist.')
->end()
->end()
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Form/FormConfigBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public function __construct($name, ?string $dataClass, EventDispatcherInterface
{
self::validateName($name);

if (null !== $dataClass && !class_exists($dataClass) && !interface_exists($dataClass)) {
if (null !== $dataClass && !class_exists($dataClass) && !interface_exists($dataClass, false)) {
throw new InvalidArgumentException(sprintf('Class "%s" not found. Is the "data_class" form option set correctly?', $dataClass));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private function registerHandlers(ContainerBuilder $container, array $busIds)
$method = $method['method'] ?? '__invoke';
}

if (!\class_exists($messageClass) && !\interface_exists($messageClass)) {
if (!\class_exists($messageClass) && !\interface_exists($messageClass, false)) {
$messageClassLocation = isset($tag['handles']) ? 'declared in your tag attribute "handles"' : $r->implementsInterface(MessageSubscriberInterface::class) ? sprintf('returned by method "%s::getHandledMessages()"', $r->getName()) : sprintf('used as argument type in method "%s::%s()"', $r->getName(), $method);

throw new RuntimeException(sprintf('Invalid handler service "%s": message class "%s" %s does not exist.', $serviceId, $messageClass, $messageClassLocation));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Symfony\Component\Serializer\Mapping\Factory;

use Symfony\Component\Serializer\Exception\InvalidArgumentException;
use Symfony\Component\Serializer\Mapping\ClassMetadata;
use Symfony\Component\Serializer\Mapping\Loader\LoaderInterface;

Expand Down Expand Up @@ -70,14 +69,6 @@ public function getMetadataFor($value)
*/
public function hasMetadataFor($value)
{
try {
$this->getClass($value);

return true;
} catch (InvalidArgumentException $invalidArgumentException) {
// Return false in case of exception
}

return false;
return \is_object($value) || (\is_string($value) && (\class_exists($value) || \interface_exists($value, false)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ trait ClassResolverTrait
private function getClass($value)
{
if (\is_string($value)) {
if (!class_exists($value) && !interface_exists($value)) {
if (!class_exists($value) && !interface_exists($value, false)) {
throw new InvalidArgumentException(sprintf('The class or interface "%s" does not exist.', $value));
}

Expand Down
0