[ Index ]

PHP Cross Reference of phpBB-3.3.3-deutsch

title

Body

[close]

/vendor/symfony/config/Exception/ -> FileLoaderLoadException.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of the Symfony package.
   5   *
   6   * (c) Fabien Potencier <fabien@symfony.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 Symfony\Component\Config\Exception;
  13  
  14  /**
  15   * Exception class for when a resource cannot be loaded or imported.
  16   *
  17   * @author Ryan Weaver <ryan@thatsquality.com>
  18   */
  19  class FileLoaderLoadException extends \Exception
  20  {
  21      /**
  22       * @param string     $resource       The resource that could not be imported
  23       * @param string     $sourceResource The original resource importing the new resource
  24       * @param int        $code           The error code
  25       * @param \Exception $previous       A previous exception
  26       * @param string     $type           The type of resource
  27       */
  28      public function __construct($resource, $sourceResource = null, $code = null, $previous = null, $type = null)
  29      {
  30          $message = '';
  31          if ($previous) {
  32              // Include the previous exception, to help the user see what might be the underlying cause
  33  
  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  
  43              // show tweaked trace to complete the human readable sentence
  44              if (null === $sourceResource) {
  45                  $message .= sprintf('(which is loaded in resource "%s")', $this->varToString($resource));
  46              } else {
  47                  $message .= sprintf('(which is being imported from "%s")', $this->varToString($sourceResource));
  48              }
  49              $message .= '.';
  50  
  51          // if there's no previous message, present it the default way
  52          } elseif (null === $sourceResource) {
  53              $message .= sprintf('Cannot load resource "%s".', $this->varToString($resource));
  54          } else {
  55              $message .= sprintf('Cannot import resource "%s" from "%s".', $this->varToString($resource), $this->varToString($sourceResource));
  56          }
  57  
  58          // Is the resource located inside a bundle?
  59          if ('@' === $resource[0]) {
  60              $parts = explode(\DIRECTORY_SEPARATOR, $resource);
  61              $bundle = substr($parts[0], 1);
  62              $message .= sprintf(' Make sure the "%s" bundle is correctly registered and loaded in the application kernel class.', $bundle);
  63              $message .= sprintf(' If the bundle is registered, make sure the bundle path "%s" is not empty.', $resource);
  64          } elseif (null !== $type) {
  65              // maybe there is no loader for this specific type
  66              if ('annotation' === $type) {
  67                  $message .= ' Make sure annotations are installed and enabled.';
  68              } else {
  69                  $message .= sprintf(' Make sure there is a loader supporting the "%s" type.', $type);
  70              }
  71          }
  72  
  73          parent::__construct($message, $code, $previous);
  74      }
  75  
  76      protected function varToString($var)
  77      {
  78          if (\is_object($var)) {
  79              return sprintf('Object(%s)', \get_class($var));
  80          }
  81  
  82          if (\is_array($var)) {
  83              $a = [];
  84              foreach ($var as $k => $v) {
  85                  $a[] = sprintf('%s => %s', $k, $this->varToString($v));
  86              }
  87  
  88              return sprintf('Array(%s)', implode(', ', $a));
  89          }
  90  
  91          if (\is_resource($var)) {
  92              return sprintf('Resource(%s)', get_resource_type($var));
  93          }
  94  
  95          if (null === $var) {
  96              return 'null';
  97          }
  98  
  99          if (false === $var) {
 100              return 'false';
 101          }
 102  
 103          if (true === $var) {
 104              return 'true';
 105          }
 106  
 107          return (string) $var;
 108      }
 109  }


Generated: Sun Feb 14 20:08:31 2021 Cross-referenced by PHPXref 0.7.1