Completed
Push — master ( c615d9...f5a26f )
by Ben
01:42
created
src/Former/FormerServiceProvider.php 1 patch
Indentation   +186 added lines, -186 removed lines patch added patch discarded remove patch
@@ -15,197 +15,197 @@
 block discarded – undo
15 15
  */
16 16
 class FormerServiceProvider extends ServiceProvider
17 17
 {
18
-	/**
19
-	 * Indicates if loading of the provider is deferred.
20
-	 *
21
-	 * @var bool
22
-	 */
23
-	protected $defer = true;
24
-
25
-	/**
26
-	 * Register Former's package with Laravel
27
-	 *
28
-	 * @return void
29
-	 */
30
-	public function register()
31
-	{
32
-		$this->app = static::make($this->app);
33
-	}
34
-
35
-	/**
36
-	 * Get the services provided by the provider.
37
-	 *
38
-	 * @return string[]
39
-	 */
40
-	public function provides()
41
-	{
42
-		return array('former', 'Former\Former');
43
-	}
44
-
45
-	////////////////////////////////////////////////////////////////////
46
-	/////////////////////////// CLASS BINDINGS /////////////////////////
47
-	////////////////////////////////////////////////////////////////////
48
-
49
-	/**
50
-	 * Create a Former container
51
-	 *
52
-	 * @param  Container $app
53
-	 *
54
-	 * @return Container
55
-	 */
56
-	public static function make($app = null)
57
-	{
58
-		if (!$app) {
59
-			$app = new Container();
60
-		}
61
-
62
-		// Bind classes to container
63
-		$provider = new static($app);
64
-		$app      = $provider->bindCoreClasses($app);
65
-		$app      = $provider->bindFormer($app);
66
-
67
-		return $app;
68
-	}
69
-
70
-	/**
71
-	 * Bind the core classes to the Container
72
-	 *
73
-	 * @param  Container $app
74
-	 *
75
-	 * @return Container
76
-	 */
77
-	public function bindCoreClasses(Container $app)
78
-	{
79
-		// Cancel if in the scope of a Laravel application
80
-		if ($app->bound('events')) {
81
-			return $app;
82
-		}
83
-
84
-		// Core classes
85
-		//////////////////////////////////////////////////////////////////
86
-
87
-		$app->bindIf('files', 'Illuminate\Filesystem\Filesystem');
88
-		$app->bindIf('url', 'Illuminate\Routing\UrlGenerator');
89
-
90
-		// Session and request
91
-		//////////////////////////////////////////////////////////////////
92
-
93
-		$app->bindIf('session.manager', function ($app) {
94
-			return new SessionManager($app);
95
-		});
96
-
97
-		$app->bindIf('session', function ($app) {
98
-			return $app['session.manager']->driver('array');
99
-		}, true);
100
-
101
-		$app->bindIf('request', function ($app) {
102
-			$request = Request::createFromGlobals();
103
-			if (method_exists($request, 'setSessionStore')) {
104
-				$request->setSessionStore($app['session']);
105
-			} else {
106
-				$request->setLaravelSession($app['session']);
107
-			}
108
-
109
-			return $request;
110
-		}, true);
111
-
112
-		// Config
113
-		//////////////////////////////////////////////////////////////////
114
-
115
-		$app->bindIf('path.config', function ($app) {
116
-			return __DIR__ . '/../config/';
117
-		}, true);
118
-
119
-		$app->bindIf('config', function ($app) {
120
-			$config = new Repository;
121
-			$this->loadConfigurationFiles($app, $config);
122
-			return $config;
123
-		}, true);
124
-
125
-		// Localization
126
-		//////////////////////////////////////////////////////////////////
127
-
128
-		$app->bindIf('translation.loader', function ($app) {
129
-			return new FileLoader($app['files'], 'src/config');
130
-		});
131
-
132
-		$app->bindIf('translator', function ($app) {
133
-			$loader = new FileLoader($app['files'], 'lang');
134
-
135
-			return new Translator($loader, 'fr');
136
-		});
137
-
138
-		return $app;
139
-	}
140
-
141
-	/**
142
-	 * Load the configuration items from all of the files.
143
-	 *
144
-	 * @param  Container $app
145
-	 * @param  Repository  $config
146
-	 * @return void
147
-	 */
148
-	protected function loadConfigurationFiles($app, Repository $config)
149
-	{
150
-		foreach ($this->getConfigurationFiles($app) as $key => $path)
151
-		{
152
-			$config->set($key, require $path);
153
-		}
154
-	}
155
-
156
-	/**
157
-	 * Get all of the configuration files for the application.
158
-	 *
159
-	 * @param  $app
160
-	 * @return array
161
-	 */
162
-	protected function getConfigurationFiles($app)
163
-	{
164
-		$files = array();
165
-
166
-		foreach (Finder::create()->files()->name('*.php')->in($app['path.config']) as $file)
167
-		{
168
-			$files[basename($file->getRealPath(), '.php')] = $file->getRealPath();
169
-		}
170
-
171
-		return $files;
172
-	}
173
-
174
-	/**
175
-	 * Bind Former classes to the container
176
-	 *
177
-	 * @param  Container $app
178
-	 *
179
-	 * @return Container
180
-	 */
181
-	public function bindFormer(Container $app)
182
-	{
183
-		// Add config namespace
184
-		$configPath = __DIR__ . '/../config/former.php';
185
-		$this->mergeConfigFrom($configPath, 'former');
186
-		$this->publishes([$configPath => $app['path.config'] . '/former.php']);
18
+    /**
19
+     * Indicates if loading of the provider is deferred.
20
+     *
21
+     * @var bool
22
+     */
23
+    protected $defer = true;
24
+
25
+    /**
26
+     * Register Former's package with Laravel
27
+     *
28
+     * @return void
29
+     */
30
+    public function register()
31
+    {
32
+        $this->app = static::make($this->app);
33
+    }
34
+
35
+    /**
36
+     * Get the services provided by the provider.
37
+     *
38
+     * @return string[]
39
+     */
40
+    public function provides()
41
+    {
42
+        return array('former', 'Former\Former');
43
+    }
44
+
45
+    ////////////////////////////////////////////////////////////////////
46
+    /////////////////////////// CLASS BINDINGS /////////////////////////
47
+    ////////////////////////////////////////////////////////////////////
48
+
49
+    /**
50
+     * Create a Former container
51
+     *
52
+     * @param  Container $app
53
+     *
54
+     * @return Container
55
+     */
56
+    public static function make($app = null)
57
+    {
58
+        if (!$app) {
59
+            $app = new Container();
60
+        }
61
+
62
+        // Bind classes to container
63
+        $provider = new static($app);
64
+        $app      = $provider->bindCoreClasses($app);
65
+        $app      = $provider->bindFormer($app);
66
+
67
+        return $app;
68
+    }
69
+
70
+    /**
71
+     * Bind the core classes to the Container
72
+     *
73
+     * @param  Container $app
74
+     *
75
+     * @return Container
76
+     */
77
+    public function bindCoreClasses(Container $app)
78
+    {
79
+        // Cancel if in the scope of a Laravel application
80
+        if ($app->bound('events')) {
81
+            return $app;
82
+        }
83
+
84
+        // Core classes
85
+        //////////////////////////////////////////////////////////////////
86
+
87
+        $app->bindIf('files', 'Illuminate\Filesystem\Filesystem');
88
+        $app->bindIf('url', 'Illuminate\Routing\UrlGenerator');
89
+
90
+        // Session and request
91
+        //////////////////////////////////////////////////////////////////
92
+
93
+        $app->bindIf('session.manager', function ($app) {
94
+            return new SessionManager($app);
95
+        });
96
+
97
+        $app->bindIf('session', function ($app) {
98
+            return $app['session.manager']->driver('array');
99
+        }, true);
100
+
101
+        $app->bindIf('request', function ($app) {
102
+            $request = Request::createFromGlobals();
103
+            if (method_exists($request, 'setSessionStore')) {
104
+                $request->setSessionStore($app['session']);
105
+            } else {
106
+                $request->setLaravelSession($app['session']);
107
+            }
108
+
109
+            return $request;
110
+        }, true);
111
+
112
+        // Config
113
+        //////////////////////////////////////////////////////////////////
114
+
115
+        $app->bindIf('path.config', function ($app) {
116
+            return __DIR__ . '/../config/';
117
+        }, true);
118
+
119
+        $app->bindIf('config', function ($app) {
120
+            $config = new Repository;
121
+            $this->loadConfigurationFiles($app, $config);
122
+            return $config;
123
+        }, true);
124
+
125
+        // Localization
126
+        //////////////////////////////////////////////////////////////////
127
+
128
+        $app->bindIf('translation.loader', function ($app) {
129
+            return new FileLoader($app['files'], 'src/config');
130
+        });
131
+
132
+        $app->bindIf('translator', function ($app) {
133
+            $loader = new FileLoader($app['files'], 'lang');
134
+
135
+            return new Translator($loader, 'fr');
136
+        });
137
+
138
+        return $app;
139
+    }
140
+
141
+    /**
142
+     * Load the configuration items from all of the files.
143
+     *
144
+     * @param  Container $app
145
+     * @param  Repository  $config
146
+     * @return void
147
+     */
148
+    protected function loadConfigurationFiles($app, Repository $config)
149
+    {
150
+        foreach ($this->getConfigurationFiles($app) as $key => $path)
151
+        {
152
+            $config->set($key, require $path);
153
+        }
154
+    }
155
+
156
+    /**
157
+     * Get all of the configuration files for the application.
158
+     *
159
+     * @param  $app
160
+     * @return array
161
+     */
162
+    protected function getConfigurationFiles($app)
163
+    {
164
+        $files = array();
165
+
166
+        foreach (Finder::create()->files()->name('*.php')->in($app['path.config']) as $file)
167
+        {
168
+            $files[basename($file->getRealPath(), '.php')] = $file->getRealPath();
169
+        }
170
+
171
+        return $files;
172
+    }
173
+
174
+    /**
175
+     * Bind Former classes to the container
176
+     *
177
+     * @param  Container $app
178
+     *
179
+     * @return Container
180
+     */
181
+    public function bindFormer(Container $app)
182
+    {
183
+        // Add config namespace
184
+        $configPath = __DIR__ . '/../config/former.php';
185
+        $this->mergeConfigFrom($configPath, 'former');
186
+        $this->publishes([$configPath => $app['path.config'] . '/former.php']);
187 187
 		
188
-		$framework = $app['config']->get('former.framework');
188
+        $framework = $app['config']->get('former.framework');
189 189
 		
190
-		$app->bind('former.framework', function ($app) {
191
-			return $app['former']->getFrameworkInstance($app['config']->get('former.framework'));
192
-		});
190
+        $app->bind('former.framework', function ($app) {
191
+            return $app['former']->getFrameworkInstance($app['config']->get('former.framework'));
192
+        });
193 193
 
194
-		$app->singleton('former.populator', function ($app) {
195
-			return new Populator();
196
-		});
194
+        $app->singleton('former.populator', function ($app) {
195
+            return new Populator();
196
+        });
197 197
 
198
-		$app->singleton('former.dispatcher', function ($app) {
199
-			return new MethodDispatcher($app, Former::FIELDSPACE);
200
-		});
198
+        $app->singleton('former.dispatcher', function ($app) {
199
+            return new MethodDispatcher($app, Former::FIELDSPACE);
200
+        });
201 201
 
202
-		$app->singleton('former', function ($app) {
203
-			return new Former($app, $app->make('former.dispatcher'));
204
-		});
205
-		$app->alias('former', 'Former\Former');
202
+        $app->singleton('former', function ($app) {
203
+            return new Former($app, $app->make('former.dispatcher'));
204
+        });
205
+        $app->alias('former', 'Former\Former');
206 206
 
207
-		Helpers::setApp($app);
207
+        Helpers::setApp($app);
208 208
 
209
-		return $app;
210
-	}
209
+        return $app;
210
+    }
211 211
 }
Please login to merge, or discard this patch.