@@ -15,199 +15,199 @@ |
||
| 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 if (method_exists($request, 'setLaravelSession')) { |
|
| 106 | - $request->setLaravelSession($app['session']); |
|
| 107 | - } else { |
|
| 108 | - $request->setSession($app['session']); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - return $request; |
|
| 112 | - }, true); |
|
| 113 | - |
|
| 114 | - // Config |
|
| 115 | - ////////////////////////////////////////////////////////////////// |
|
| 116 | - |
|
| 117 | - $app->bindIf('path.config', function ($app) { |
|
| 118 | - return __DIR__ . '/../config/'; |
|
| 119 | - }, true); |
|
| 120 | - |
|
| 121 | - $app->bindIf('config', function ($app) { |
|
| 122 | - $config = new Repository; |
|
| 123 | - $this->loadConfigurationFiles($app, $config); |
|
| 124 | - return $config; |
|
| 125 | - }, true); |
|
| 126 | - |
|
| 127 | - // Localization |
|
| 128 | - ////////////////////////////////////////////////////////////////// |
|
| 129 | - |
|
| 130 | - $app->bindIf('translation.loader', function ($app) { |
|
| 131 | - return new FileLoader($app['files'], 'src/config'); |
|
| 132 | - }); |
|
| 133 | - |
|
| 134 | - $app->bindIf('translator', function ($app) { |
|
| 135 | - $loader = new FileLoader($app['files'], 'lang'); |
|
| 136 | - |
|
| 137 | - return new Translator($loader, 'fr'); |
|
| 138 | - }); |
|
| 139 | - |
|
| 140 | - return $app; |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * Load the configuration items from all of the files. |
|
| 145 | - * |
|
| 146 | - * @param Container $app |
|
| 147 | - * @param Repository $config |
|
| 148 | - * @return void |
|
| 149 | - */ |
|
| 150 | - protected function loadConfigurationFiles($app, Repository $config) |
|
| 151 | - { |
|
| 152 | - foreach ($this->getConfigurationFiles($app) as $key => $path) |
|
| 153 | - { |
|
| 154 | - $config->set($key, require $path); |
|
| 155 | - } |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * Get all of the configuration files for the application. |
|
| 160 | - * |
|
| 161 | - * @param $app |
|
| 162 | - * @return array |
|
| 163 | - */ |
|
| 164 | - protected function getConfigurationFiles($app) |
|
| 165 | - { |
|
| 166 | - $files = array(); |
|
| 167 | - |
|
| 168 | - foreach (Finder::create()->files()->name('*.php')->in($app['path.config']) as $file) |
|
| 169 | - { |
|
| 170 | - $files[basename($file->getRealPath(), '.php')] = $file->getRealPath(); |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - return $files; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * Bind Former classes to the container |
|
| 178 | - * |
|
| 179 | - * @param Container $app |
|
| 180 | - * |
|
| 181 | - * @return Container |
|
| 182 | - */ |
|
| 183 | - public function bindFormer(Container $app) |
|
| 184 | - { |
|
| 185 | - // Add config namespace |
|
| 186 | - $configPath = __DIR__ . '/../config/former.php'; |
|
| 187 | - $this->mergeConfigFrom($configPath, 'former'); |
|
| 188 | - $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 if (method_exists($request, 'setLaravelSession')) { |
|
| 106 | + $request->setLaravelSession($app['session']); |
|
| 107 | + } else { |
|
| 108 | + $request->setSession($app['session']); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + return $request; |
|
| 112 | + }, true); |
|
| 113 | + |
|
| 114 | + // Config |
|
| 115 | + ////////////////////////////////////////////////////////////////// |
|
| 116 | + |
|
| 117 | + $app->bindIf('path.config', function ($app) { |
|
| 118 | + return __DIR__ . '/../config/'; |
|
| 119 | + }, true); |
|
| 120 | + |
|
| 121 | + $app->bindIf('config', function ($app) { |
|
| 122 | + $config = new Repository; |
|
| 123 | + $this->loadConfigurationFiles($app, $config); |
|
| 124 | + return $config; |
|
| 125 | + }, true); |
|
| 126 | + |
|
| 127 | + // Localization |
|
| 128 | + ////////////////////////////////////////////////////////////////// |
|
| 129 | + |
|
| 130 | + $app->bindIf('translation.loader', function ($app) { |
|
| 131 | + return new FileLoader($app['files'], 'src/config'); |
|
| 132 | + }); |
|
| 133 | + |
|
| 134 | + $app->bindIf('translator', function ($app) { |
|
| 135 | + $loader = new FileLoader($app['files'], 'lang'); |
|
| 136 | + |
|
| 137 | + return new Translator($loader, 'fr'); |
|
| 138 | + }); |
|
| 139 | + |
|
| 140 | + return $app; |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * Load the configuration items from all of the files. |
|
| 145 | + * |
|
| 146 | + * @param Container $app |
|
| 147 | + * @param Repository $config |
|
| 148 | + * @return void |
|
| 149 | + */ |
|
| 150 | + protected function loadConfigurationFiles($app, Repository $config) |
|
| 151 | + { |
|
| 152 | + foreach ($this->getConfigurationFiles($app) as $key => $path) |
|
| 153 | + { |
|
| 154 | + $config->set($key, require $path); |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * Get all of the configuration files for the application. |
|
| 160 | + * |
|
| 161 | + * @param $app |
|
| 162 | + * @return array |
|
| 163 | + */ |
|
| 164 | + protected function getConfigurationFiles($app) |
|
| 165 | + { |
|
| 166 | + $files = array(); |
|
| 167 | + |
|
| 168 | + foreach (Finder::create()->files()->name('*.php')->in($app['path.config']) as $file) |
|
| 169 | + { |
|
| 170 | + $files[basename($file->getRealPath(), '.php')] = $file->getRealPath(); |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + return $files; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * Bind Former classes to the container |
|
| 178 | + * |
|
| 179 | + * @param Container $app |
|
| 180 | + * |
|
| 181 | + * @return Container |
|
| 182 | + */ |
|
| 183 | + public function bindFormer(Container $app) |
|
| 184 | + { |
|
| 185 | + // Add config namespace |
|
| 186 | + $configPath = __DIR__ . '/../config/former.php'; |
|
| 187 | + $this->mergeConfigFrom($configPath, 'former'); |
|
| 188 | + $this->publishes([$configPath => $app['path.config'] . '/former.php']); |
|
| 189 | 189 | |
| 190 | - $framework = $app['config']->get('former.framework'); |
|
| 190 | + $framework = $app['config']->get('former.framework'); |
|
| 191 | 191 | |
| 192 | - $app->bind('former.framework', function ($app) { |
|
| 193 | - return $app['former']->getFrameworkInstance($app['config']->get('former.framework')); |
|
| 194 | - }); |
|
| 192 | + $app->bind('former.framework', function ($app) { |
|
| 193 | + return $app['former']->getFrameworkInstance($app['config']->get('former.framework')); |
|
| 194 | + }); |
|
| 195 | 195 | |
| 196 | - $app->singleton('former.populator', function ($app) { |
|
| 197 | - return new Populator(); |
|
| 198 | - }); |
|
| 196 | + $app->singleton('former.populator', function ($app) { |
|
| 197 | + return new Populator(); |
|
| 198 | + }); |
|
| 199 | 199 | |
| 200 | - $app->singleton('former.dispatcher', function ($app) { |
|
| 201 | - return new MethodDispatcher($app, Former::FIELDSPACE); |
|
| 202 | - }); |
|
| 200 | + $app->singleton('former.dispatcher', function ($app) { |
|
| 201 | + return new MethodDispatcher($app, Former::FIELDSPACE); |
|
| 202 | + }); |
|
| 203 | 203 | |
| 204 | - $app->singleton('former', function ($app) { |
|
| 205 | - return new Former($app, $app->make('former.dispatcher')); |
|
| 206 | - }); |
|
| 207 | - $app->alias('former', 'Former\Former'); |
|
| 204 | + $app->singleton('former', function ($app) { |
|
| 205 | + return new Former($app, $app->make('former.dispatcher')); |
|
| 206 | + }); |
|
| 207 | + $app->alias('former', 'Former\Former'); |
|
| 208 | 208 | |
| 209 | - Helpers::setApp($app); |
|
| 209 | + Helpers::setApp($app); |
|
| 210 | 210 | |
| 211 | - return $app; |
|
| 212 | - } |
|
| 211 | + return $app; |
|
| 212 | + } |
|
| 213 | 213 | } |