vendor/symfony/config/Exception/LoaderLoadException.php line 19

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\Config\Exception;
  11. /**
  12.  * Exception class for when a resource cannot be loaded or imported.
  13.  *
  14.  * @author Ryan Weaver <ryan@thatsquality.com>
  15.  */
  16. class LoaderLoadException extends \Exception
  17. {
  18.     /**
  19.      * @param string          $resource       The resource that could not be imported
  20.      * @param string|null     $sourceResource The original resource importing the new resource
  21.      * @param int|null        $code           The error code
  22.      * @param \Throwable|null $previous       A previous exception
  23.      * @param string|null     $type           The type of resource
  24.      */
  25.     public function __construct(string $resource, ?string $sourceResource null, ?int $code 0, ?\Throwable $previous null, ?string $type null)
  26.     {
  27.         if (null === $code) {
  28.             trigger_deprecation('symfony/config''5.3''Passing null as $code to "%s()" is deprecated, pass 0 instead.'__METHOD__);
  29.             $code 0;
  30.         }
  31.         $message '';
  32.         if ($previous) {
  33.             // Include the previous exception, to help the user see what might be the underlying cause
  34.             // Trim the trailing period of the previous message. We only want 1 period remove so no rtrim...
  35.             if ('.' === substr($previous->getMessage(), -1)) {
  36.                 $trimmedMessage substr($previous->getMessage(), 0, -1);
  37.                 $message .= sprintf('%s'$trimmedMessage).' in ';
  38.             } else {
  39.                 $message .= sprintf('%s'$previous->getMessage()).' in ';
  40.             }
  41.             $message .= $resource.' ';
  42.             // show tweaked trace to complete the human readable sentence
  43.             if (null === $sourceResource) {
  44.                 $message .= sprintf('(which is loaded in resource "%s")'$resource);
  45.             } else {
  46.                 $message .= sprintf('(which is being imported from "%s")'$sourceResource);
  47.             }
  48.             $message .= '.';
  49.         // if there's no previous message, present it the default way
  50.         } elseif (null === $sourceResource) {
  51.             $message .= sprintf('Cannot load resource "%s".'$resource);
  52.         } else {
  53.             $message .= sprintf('Cannot import resource "%s" from "%s".'$resource$sourceResource);
  54.         }
  55.         // Is the resource located inside a bundle?
  56.         if ('@' === $resource[0]) {
  57.             $parts explode(\DIRECTORY_SEPARATOR$resource);
  58.             $bundle substr($parts[0], 1);
  59.             $message .= sprintf(' Make sure the "%s" bundle is correctly registered and loaded in the application kernel class.'$bundle);
  60.             $message .= sprintf(' If the bundle is registered, make sure the bundle path "%s" is not empty.'$resource);
  61.         } elseif (null !== $type) {
  62.             // maybe there is no loader for this specific type
  63.             if ('annotation' === $type) {
  64.                 $message .= ' Make sure to use PHP 8+ or that annotations are installed and enabled.';
  65.             } else {
  66.                 $message .= sprintf(' Make sure there is a loader supporting the "%s" type.'$type);
  67.             }
  68.         }
  69.         parent::__construct($message$code$previous);
  70.     }
  71.     protected function varToString($var)
  72.     {
  73.         if (\is_object($var)) {
  74.             return sprintf('Object(%s)', \get_class($var));
  75.         }
  76.         if (\is_array($var)) {
  77.             $a = [];
  78.             foreach ($var as $k => $v) {
  79.                 $a[] = sprintf('%s => %s'$k$this->varToString($v));
  80.             }
  81.             return sprintf('Array(%s)'implode(', '$a));
  82.         }
  83.         if (\is_resource($var)) {
  84.             return sprintf('Resource(%s)'get_resource_type($var));
  85.         }
  86.         if (null === $var) {
  87.             return 'null';
  88.         }
  89.         if (false === $var) {
  90.             return 'false';
  91.         }
  92.         if (true === $var) {
  93.             return 'true';
  94.         }
  95.         return (string) $var;
  96.     }
  97. }