Debian Codegraph @

lib/3rdParty/composer/symfony/serializer/Exception/NotNormalizableValueException.php

raw symbols SCIP
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <[email protected]>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Symfony\Component\Serializer\Exception;
13
14 /**
15 * @author Christian Flothmann <[email protected]>
16 */
17 class NotNormalizableValueException extends UnexpectedValueException
18 {
19 private ?string $currentType = null;
20 private ?array $expectedTypes = null;
21 private ?string $path = null;
22 private bool $useMessageForUser = false;
23
24 /**
25 * @param list<string|\Stringable>|null $expectedTypes
26 */
27 public function __construct(string $message = '', int $code = 0, ?\Throwable $previous = null, ?string $currentType = null, ?array $expectedTypes = null, ?string $path = null, bool $useMessageForUser = false)
28 {
29 parent::__construct($message, $code, $previous);
30
31 $this->currentType = $currentType;
32 $this->expectedTypes = $expectedTypes ? array_map(strval(...), $expectedTypes) : $expectedTypes;
33 $this->path = $path;
34 $this->useMessageForUser = $useMessageForUser;
35 }
36
37 /**
38 * @param list<string|\Stringable> $expectedTypes
39 * @param bool $useMessageForUser If the message passed to this exception is something that can be shown
40 * safely to your user. In other words, avoid catching other exceptions and
41 * passing their message directly to this class.
42 */
43 public static function createForUnexpectedDataType(string $message, mixed $data, array $expectedTypes, ?string $path = null, bool $useMessageForUser = false, int $code = 0, ?\Throwable $previous = null): self
44 {
45 return new self($message, $code, $previous, get_debug_type($data), $expectedTypes, $path, $useMessageForUser);
46 }
47
48 public function getCurrentType(): ?string
49 {
50 return $this->currentType;
51 }
52
53 /**
54 * @return string[]|null
55 */
56 public function getExpectedTypes(): ?array
57 {
58 return $this->expectedTypes;
59 }
60
61 public function getPath(): ?string
62 {
63 return $this->path;
64 }
65
66 public function canUseMessageForUser(): ?bool
67 {
68 return $this->useMessageForUser;
69 }
70 }