forked from ezsystems/ezpublish-kernel
/
Image.php
140 lines (133 loc) · 6.53 KB
/
Image.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
/**
* File containing the Image class.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\Parser;
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\AbstractParser;
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\SiteAccessAware\ContextualizerInterface;
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\Suggestion\Collector\SuggestionCollectorAwareInterface;
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\Suggestion\Collector\SuggestionCollectorInterface;
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\Suggestion\ConfigSuggestion;
use Symfony\Component\Config\Definition\Builder\NodeBuilder;
/**
* Configuration parser handling all basic configuration (aka "Image").
*/
class Image extends AbstractParser implements SuggestionCollectorAwareInterface
{
/**
* @var SuggestionCollectorInterface
*/
private $suggestionCollector;
public function setSuggestionCollector(SuggestionCollectorInterface $suggestionCollector)
{
$this->suggestionCollector = $suggestionCollector;
}
/**
* Adds semantic configuration definition.
*
* @param \Symfony\Component\Config\Definition\Builder\NodeBuilder $nodeBuilder Node just under ezpublish.system.<siteaccess>
*/
public function addSemanticConfig(NodeBuilder $nodeBuilder)
{
$nodeBuilder
->arrayNode('imagemagick')
->info('DEPRECATED.')
->children()
->scalarNode('pre_parameters')->info('Parameters that must be run BEFORE the filenames and filters')->end()
->scalarNode('post_parameters')->info('Parameters that must be run AFTER the filenames and filters')->end()
->end()
->end()
->arrayNode('image_variations')
->info('Configuration for your image variations (aka "image aliases")')
->example(
array(
'my_image_variation' => array(
'reference' => '~',
'filters' => array(
array(
'name' => 'geometry/scaledownonly',
'params' => array(400, 350),
),
),
),
'my_cropped_variation' => array(
'reference' => 'my_image_variation',
'filters' => array(
array(
'name' => 'geometry/scalewidthdownonly',
'params' => array(300),
),
array(
'name' => 'geometry/crop',
'params' => array(300, 300, 0, 0),
),
),
),
)
)
->useAttributeAsKey('variation_name')
->normalizeKeys(false)
->prototype('array')
->children()
->scalarNode('reference')
->info('Tells the system which original variation to use as reference image. Defaults to original')
->example(array('reference' => 'large'))
->end()
->arrayNode('filters')
->info('A list of filters to run, each filter must be supported by the active image converters')
->useAttributeAsKey('name')
->normalizeKeys(false)
->prototype('array')
->info('Array/Hash of parameters to pass to the filter')
->useAttributeAsKey('options')
->beforeNormalization()
->ifTrue(
function ($v) {
// Check if passed array only contains a "params" key (BC with <=5.3).
return is_array($v) && count($v) === 1 && isset($v['params']);
}
)
->then(
function ($v) {
// If we have the "params" key, just use the value.
return $v['params'];
}
)
->end()
->prototype('variable')->end()
->end()
->end()
->arrayNode('post_processors')
->info('Post processors as defined in LiipImagineBundle. See https://github.com/liip/LiipImagineBundle/blob/master/Resources/doc/filters.md#post-processors')
->useAttributeAsKey('name')
->prototype('array')
->useAttributeAsKey('name')
->prototype('variable')->end()
->end()
->end()
->end()
->end()
->end()
->scalarNode('image_host')
->info('Images host. All system images URLs are prefixed with given host if configured.')
->example('https://ezplatform.com')
->end();
}
public function preMap(array $config, ContextualizerInterface $contextualizer)
{
$contextualizer->mapConfigArray('image_variations', $config);
$contextualizer->mapSetting('image_host', $config);
}
public function mapConfig(array &$scopeSettings, $currentScope, ContextualizerInterface $contextualizer)
{
if (isset($scopeSettings['imagemagick'])) {
$suggestion = new ConfigSuggestion(
'"imagemagick" settings are deprecated. Just remove them from your configuration file.'
);
$this->suggestionCollector->addSuggestion($suggestion);
}
}
}