Fix bug in style changes for the Use cases on the live site.
[yaffs-website] / vendor / symfony / config / Exception / FileLoaderLoadException.php
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      */
27     public function __construct($resource, $sourceResource = null, $code = null, $previous = null)
28     {
29         $message = '';
30         if ($previous) {
31             // Include the previous exception, to help the user see what might be the underlying cause
32
33             // Trim the trailing period of the previous message. We only want 1 period remove so no rtrim...
34             if ('.' === substr($previous->getMessage(), -1)) {
35                 $trimmedMessage = substr($previous->getMessage(), 0, -1);
36                 $message .= sprintf('%s', $trimmedMessage).' in ';
37             } else {
38                 $message .= sprintf('%s', $previous->getMessage()).' in ';
39             }
40             $message .= $resource.' ';
41
42             // show tweaked trace to complete the human readable sentence
43             if (null === $sourceResource) {
44                 $message .= sprintf('(which is loaded in resource "%s")', $this->varToString($resource));
45             } else {
46                 $message .= sprintf('(which is being imported from "%s")', $this->varToString($sourceResource));
47             }
48             $message .= '.';
49
50         // if there's no previous message, present it the default way
51         } elseif (null === $sourceResource) {
52             $message .= sprintf('Cannot load resource "%s".', $this->varToString($resource));
53         } else {
54             $message .= sprintf('Cannot import resource "%s" from "%s".', $this->varToString($resource), $this->varToString($sourceResource));
55         }
56
57         // Is the resource located inside a bundle?
58         if ('@' === $resource[0]) {
59             $parts = explode(DIRECTORY_SEPARATOR, $resource);
60             $bundle = substr($parts[0], 1);
61             $message .= sprintf(' Make sure the "%s" bundle is correctly registered and loaded in the application kernel class.', $bundle);
62             $message .= sprintf(' If the bundle is registered, make sure the bundle path "%s" is not empty.', $resource);
63         }
64
65         parent::__construct($message, $code, $previous);
66     }
67
68     protected function varToString($var)
69     {
70         if (is_object($var)) {
71             return sprintf('Object(%s)', get_class($var));
72         }
73
74         if (is_array($var)) {
75             $a = array();
76             foreach ($var as $k => $v) {
77                 $a[] = sprintf('%s => %s', $k, $this->varToString($v));
78             }
79
80             return sprintf('Array(%s)', implode(', ', $a));
81         }
82
83         if (is_resource($var)) {
84             return sprintf('Resource(%s)', get_resource_type($var));
85         }
86
87         if (null === $var) {
88             return 'null';
89         }
90
91         if (false === $var) {
92             return 'false';
93         }
94
95         if (true === $var) {
96             return 'true';
97         }
98
99         return (string) $var;
100     }
101 }