diff --git a/.gitignore b/.gitignore index ac3492e..9d0b93e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ /bootstrap/compiled.php .env.*.php .env.php +/vendor +composer.lock diff --git a/composer.json b/composer.json index 1bcf04b..872ecc1 100644 --- a/composer.json +++ b/composer.json @@ -18,9 +18,9 @@ "ext-gd": "*", "illuminate/config": "~5.0", "illuminate/filesystem": "~5.0", - "illuminate/support": "~5.0", - "illuminate/hashing": "~5.0", - "intervention/image": "~2.1" + "illuminate/support": "~5.0", + "illuminate/hashing": "~5.0", + "intervention/image": "~2.1" }, "require-dev": { "phpunit/phpunit": "~4.0", @@ -31,7 +31,7 @@ "Mews\\Captcha\\": "src/" }, "files": [ - "src/helpers.php" + "src/helpers.php" ] }, "autoload-dev": { diff --git a/src/Captcha.php b/src/Captcha.php index 60eb7af..d2d3132 100644 --- a/src/Captcha.php +++ b/src/Captcha.php @@ -174,15 +174,6 @@ public function __construct(Filesystem $files, Repository $config, ImageManager $this->session = $session; $this->hasher = $hasher; $this->str = $str; - - if ( ! $this->config->has('captcha')) - { - if ( ! $this->config->has('mews.captcha')) - { - throw new Exception('Configuration parameters not loaded!'); - } - $this->config->set('captcha', $this->config->get('mews.captcha')); - } } /** diff --git a/src/CaptchaServiceProvider.php b/src/CaptchaServiceProvider.php index fe26e49..7938c1f 100644 --- a/src/CaptchaServiceProvider.php +++ b/src/CaptchaServiceProvider.php @@ -1,28 +1,32 @@ publishes([ - __DIR__.'/../config/captcha.php' => config_path('captcha.php') - ]); + __DIR__.'/../config/captcha.php' => config_path('captcha.php') + ], 'config'); + + // HTTP routing + $this->app['router']->get('captcha/{config?}', function(Captcha $captcha, $config = 'default') + { + return $captcha->create($config); + }); + + // Validator extensions + $this->app['validator']->extend('captcha', function($attribute, $value, $parameters) + { + return captcha_check($value); + }); } /** @@ -32,14 +36,12 @@ public function boot() */ public function register() { + // Merge configs $this->mergeConfigFrom( - __DIR__.'/../config/captcha.php', 'mews.captcha' + __DIR__.'/../config/captcha.php', 'captcha' ); - /** - * @param $app - * @return Captcha - */ + // Bind captcha $this->app->bind('captcha', function($app) { return new Captcha( @@ -51,44 +53,6 @@ public function register() $app['Illuminate\Support\Str'] ); }); - - /** - * @param Captcha $captcha - * @return \Intervention\Image\ImageManager - */ - $this->app['router']->get('captcha', function(Captcha $captcha) - { - return $captcha->create(); - }); - - /** - * @param Captcha $captcha - * @param $config - * @return \Intervention\Image\ImageManager - */ - $this->app['router']->get('captcha/{config}', function(Captcha $captcha, $config) - { - return $captcha->create($config); - }); - - $this->app['validator'] = $this->app->share(function($app) { - $validator = new Factory($app['translator']); - $validator->setPresenceVerifier($this->app['validation.presence']); - $validator->resolver(function($translator, $data, $rules, $messages) { - return new CaptchaValidator($translator, $data, $rules, $messages); - }); - return $validator; - }); - } - - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides() - { - return ['captcha']; } } diff --git a/src/CaptchaValidator.php b/src/CaptchaValidator.php deleted file mode 100644 index e1feeab..0000000 --- a/src/CaptchaValidator.php +++ /dev/null @@ -1,11 +0,0 @@ -