forked from liip/LiipImagineBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
InvalidOptionException.php
65 lines (54 loc) · 1.61 KB
/
InvalidOptionException.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/*
* This file is part of the `liip/LiipImagineBundle` project.
*
* (c) https://github.com/liip/LiipImagineBundle/graphs/contributors
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/
namespace Liip\ImagineBundle\Exception\Imagine\Filter\PostProcessor;
use Liip\ImagineBundle\Exception\ExceptionInterface;
class InvalidOptionException extends \RuntimeException implements ExceptionInterface
{
/**
* @param string $message
* @param array $options
*/
public function __construct($message, array $options = array())
{
parent::__construct(sprintf('Invalid post-processor configuration provided (%s) with options %s.',
$message, $this->stringifyOptions($options)));
}
/**
* @param array $options
*
* @return string
*/
private function stringifyOptions(array $options = array())
{
if (0 === count($options)) {
return '[]';
}
$options = array_map(array($this, 'stringifyOptionValue'), $options);
array_walk($options, function (&$o, $name) {
$o = sprintf('%s="%s"', $name, $o);
});
return sprintf('[%s]', implode(', ', $options));
}
/**
* @param mixed $value
*
* @return string
*/
private function stringifyOptionValue($value)
{
if (is_array($value)) {
return json_encode($value);
}
if (is_scalar($value)) {
return $value;
}
return str_replace("\n", '', var_export($value, true));
}
}