Completed
Push — master ( 008aa0...babc0b )
by Aimeos
02:37
created

ShopServiceProvider::provides()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
/**
4
 * @license MIT, http://opensource.org/licenses/MIT
5
 * @copyright Aimeos (aimeos.org), 2015-2016
6
 * @package laravel
7
 */
8
9
10
namespace Aimeos\Shop;
11
12
use Illuminate\Support\ServiceProvider;
13
use Illuminate\Support\Facades\Blade;
14
use Illuminate\Support\Facades\Input;
15
use Illuminate\Support\Facades\Route;
16
17
18
/**
19
 * Aimeos shop service provider for Laravel
20
 * @package laravel
21
 */
22
class ShopServiceProvider extends ServiceProvider {
23
24
	/**
25
	 * Indicates if loading of the provider is deferred.
26
	 *
27
	 * @var bool
28
	 */
29
	protected $defer = false;
30
31
32
	/**
33
	 * Bootstrap the application events.
34
	 *
35
	 * @return void
36
	 */
37
	public function boot()
38
	{
39
		$basedir = dirname(dirname(__DIR__)).DIRECTORY_SEPARATOR;
40
		$confpath = config_path('shop.php');
41
42
		$config = array_replace_recursive(
43
			$this->app['config']->get('shop', []),
44
			require $basedir.'default.php',
45
			(file_exists($confpath) ? require $confpath : array())
46
		);
47
		$this->app['config']->set('shop', $config);
48
49
		$this->loadViewsFrom($basedir.'views', 'shop');
50
51
52
		$this->publishes(array(
53
			$basedir.'config/shop.php' => config_path('shop.php'),
54
		), 'config');
55
56
		$this->publishes(array(
57
			$basedir.'views' => base_path('resources/views/vendor/shop'),
58
		), 'views');
59
60
		$this->publishes(array(
61
			dirname($basedir).DIRECTORY_SEPARATOR.'public' => public_path('packages/aimeos/shop'),
62
		), 'public');
63
64
65
		require $basedir.'routes.php';
66
67
68
		$i18n = $this->app->make( '\Aimeos\Shop\Base\I18n' );
69
		$config = $this->app->make( '\Aimeos\Shop\Base\Config' );
70
71
		Blade::directive('ai:config', function( $key, $default = null ) use ( $config )
72
		{
73
			return $config->get( $key, $default );
74
		});
75
76
		Blade::directive('ai:translate', function( $domain, $singular, $plural, $number ) use ( $i18n )
77
		{
78
			if( $plural !== '' ) {
79
				return $this->translator->dn( $domain, $singular, $plural, $number );
0 ignored issues
show
Bug introduced by
The property translator does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
80
			}
81
			return $this->translator->dt( $domain, $singular );
82
		});
83
	}
84
85
86
	/**
87
	 * Register the service provider.
88
	 *
89
	 * @return void
90
	 */
91
	public function register()
92
	{
93
		$this->app->singleton('\Aimeos\Shop\Base\Aimeos', function($app) {
94
			return new \Aimeos\Shop\Base\Aimeos($app['config']);
95
		});
96
97
		$this->app->singleton('\Aimeos\Shop\Base\Config', function($app) {
98
			return new \Aimeos\Shop\Base\Config($app['config'], $app['\Aimeos\Shop\Base\Aimeos']);
99
		});
100
101
		$this->app->singleton('\Aimeos\Shop\Base\I18n', function($app) {
102
			return new \Aimeos\Shop\Base\I18n($this->app['config'], $app['\Aimeos\Shop\Base\Aimeos']);
103
		});
104
105
		$this->app->singleton('\Aimeos\Shop\Base\Locale', function($app) {
106
			return new \Aimeos\Shop\Base\Locale($app['config']);
107
		});
108
109
		$this->app->singleton('\Aimeos\Shop\Base\Context', function($app) {
110
			return new \Aimeos\Shop\Base\Context($app['session.store'], $app['\Aimeos\Shop\Base\Config'], $app['\Aimeos\Shop\Base\Locale'], $app['\Aimeos\Shop\Base\I18n']);
111
		});
112
113
		$this->app->singleton('\Aimeos\Shop\Base\Page', function($app) {
114
			return new \Aimeos\Shop\Base\Page($app['config'], $app['\Aimeos\Shop\Base\Aimeos'], $app['\Aimeos\Shop\Base\Context'], $app['\Aimeos\Shop\Base\Locale'], $app['\Aimeos\Shop\Base\View']);
115
		});
116
117
		$this->app->singleton('\Aimeos\Shop\Base\Support', function($app) {
118
			return new \Aimeos\Shop\Base\Support($app['\Aimeos\Shop\Base\Context'], $app['\Aimeos\Shop\Base\Locale']);
119
		});
120
121
		$this->app->singleton('\Aimeos\Shop\Base\View', function($app) {
122
			return new \Aimeos\Shop\Base\View($app['\Aimeos\Shop\Base\I18n'], $app['\Aimeos\Shop\Base\Support']);
123
		});
124
125
126
		$this->app['command.aimeos.account'] = $this->app->share(function() {
0 ignored issues
show
Bug introduced by
The method share() does not seem to exist on object<Illuminate\Contra...Foundation\Application>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
127
			return new Command\AccountCommand();
128
		});
129
130
		$this->app['command.aimeos.cache'] = $this->app->share(function() {
0 ignored issues
show
Bug introduced by
The method share() does not seem to exist on object<Illuminate\Contra...Foundation\Application>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
131
			return new Command\CacheCommand();
132
		});
133
134
		$this->app['command.aimeos.jobs'] = $this->app->share(function() {
0 ignored issues
show
Bug introduced by
The method share() does not seem to exist on object<Illuminate\Contra...Foundation\Application>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
135
			return new Command\JobsCommand();
136
		});
137
138
		$this->app['command.aimeos.setup'] = $this->app->share(function() {
0 ignored issues
show
Bug introduced by
The method share() does not seem to exist on object<Illuminate\Contra...Foundation\Application>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
139
			return new Command\SetupCommand();
140
		});
141
142
		$this->commands('command.aimeos.account');
143
		$this->commands('command.aimeos.cache');
144
		$this->commands('command.aimeos.setup');
145
		$this->commands('command.aimeos.jobs');
146
	}
147
148
149
	/**
150
	 * Get the services provided by the provider.
151
	 *
152
	 * @return array
153
	 */
154
	public function provides()
155
	{
156
		return array(
157
			'command.aimeos.account', 'command.aimeos.cache', 'command.aimeos.jobs', 'command.aimeos.setup',
158
			'\Aimeos\Shop\Base\Aimeos', '\Aimeos\Shop\Base\I18n', '\Aimeos\Shop\Base\Context',
159
			'\Aimeos\Shop\Base\Config', '\Aimeos\Shop\Base\Locale', '\Aimeos\Shop\Base\View',
160
			'\Aimeos\Shop\Base\Page', '\Aimeos\Shop\Base\Support'
161
		);
162
	}
163
164
}