FriendsOfSymfony /
FOSRestBundle
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | /* |
||
| 4 | * This file is part of the FOSRestBundle package. |
||
| 5 | * |
||
| 6 | * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> |
||
| 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 FOS\RestBundle\Util; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * Stores map of values mapped to exception class |
||
| 16 | * Resolves value by exception. |
||
| 17 | * |
||
| 18 | * @author Mikhail Shamin <[email protected]> |
||
| 19 | * |
||
| 20 | * @internal |
||
| 21 | */ |
||
| 22 | class ExceptionValueMap |
||
| 23 | { |
||
| 24 | /** |
||
| 25 | * Map of values mapped to exception class |
||
| 26 | * key => exception class |
||
| 27 | * value => value associated with exception. |
||
| 28 | */ |
||
| 29 | private $map; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @param array<string,bool>|array<string,int> $map |
||
| 33 | */ |
||
| 34 | 45 | public function __construct(array $map) |
|
| 35 | { |
||
| 36 | 45 | $this->map = $map; |
|
| 37 | 45 | } |
|
| 38 | |||
| 39 | /** |
||
| 40 | * @return bool|int|null null if not found |
||
| 41 | */ |
||
| 42 | public function resolveFromClassName(string $className) |
||
| 43 | { |
||
| 44 | 3 | foreach ($this->map as $mapClass => $value) { |
|
| 45 | if (!$value) { |
||
| 46 | 3 | continue; |
|
| 47 | } |
||
| 48 | |||
| 49 | if ($className === $mapClass || is_subclass_of($className, $mapClass)) { |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 50 | return $value; |
||
| 51 | } |
||
| 52 | } |
||
| 53 | |||
| 54 | return null; |
||
| 55 | } |
||
| 56 | } |
||
| 57 |