1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CSSPrites; |
4
|
|
|
|
5
|
|
|
use CSSPrites\ImageProcessor\ImageProcessorInterface; |
6
|
|
|
use League\Container\ServiceProvider as BaseServiceProvider; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* ServiceProvider to register all the needed dependencies. |
10
|
|
|
* |
11
|
|
|
* @codeCoverageIgnore |
12
|
|
|
*/ |
13
|
|
|
class ServiceProvider extends BaseServiceProvider |
14
|
|
|
{ |
15
|
|
|
protected $provides = [ |
16
|
|
|
'configuration', |
17
|
|
|
'image.processor', |
18
|
|
|
'sprite.processor.horizontal', |
19
|
|
|
'sprite.processor.vertical', |
20
|
|
|
'sprite.processor.simplebinpacking', |
21
|
|
|
'commands.generate', |
22
|
|
|
]; |
23
|
|
|
|
24
|
|
|
public function register() |
25
|
|
|
{ |
26
|
|
|
$container = $this->getContainer(); |
27
|
|
|
|
28
|
|
|
// AutoConfigure ContainerAwareInterface |
29
|
|
|
$container->inflector('League\Container\ContainerAwareInterface') |
30
|
|
|
->invokeMethod('setContainer', [$container]); |
31
|
|
|
|
32
|
|
|
// Registering Configuration as singleton |
33
|
|
|
$container->singleton('configuration', 'CSSPrites\Configuration'); |
34
|
|
|
|
35
|
|
|
// Registering Slugifier as singleton |
36
|
|
|
$container->singleton('slugifier', 'CSSPrites\Slugifier\SlugifySlugifier'); |
37
|
|
|
|
38
|
|
|
// Registering Image Processor |
39
|
|
|
$container->add('image.processor', 'CSSPrites\ImageProcessor\ImagineImageProcessor'); |
40
|
|
|
|
41
|
|
|
// AutoConfigure Image Processor |
42
|
|
|
$container->inflector('CSSPrites\ImageProcessor\ImageProcessorInterface', function (ImageProcessorInterface $instance) use ($container) { |
43
|
|
|
$instance->setConfig($container->get('configuration')->get('image.processor')); |
44
|
|
|
}); |
45
|
|
|
|
46
|
|
|
// Registering Sprites Processors |
47
|
|
|
$container->add('sprite.processor.horizontal', 'CSSPrites\SpriteProcessor\HorizontalSpriteProcessor') |
|
|
|
|
48
|
|
|
->withArgument('image.processor'); |
49
|
|
|
$container->add('sprite.processor.vertical', 'CSSPrites\SpriteProcessor\VerticalSpriteProcessor') |
50
|
|
|
->withArgument('image.processor'); |
51
|
|
|
$container->add('sprite.processor.simplebinpacking', 'CSSPrites\SpriteProcessor\SimpleBinPackingSpriteProcessor') |
52
|
|
|
->withArgument('image.processor'); |
53
|
|
|
|
54
|
|
|
// Registering ConsoleCommands |
55
|
|
|
$container->add('commands.generate', 'CSSPrites\Commands\GenerateCommand'); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: