Skip to content

Commit

Permalink
Merge pull request #35 from hutushen222/master
Browse files Browse the repository at this point in the history
Refactoring CaptchaServiceProvider
  • Loading branch information
mewebstudio committed Apr 26, 2015
2 parents cc8972f + 7cbdc9e commit 2e5d8cf
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 78 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/bootstrap/compiled.php
.env.*.php
.env.php
/vendor
composer.lock
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -31,7 +31,7 @@
"Mews\\Captcha\\": "src/"
},
"files": [
"src/helpers.php"
"src/helpers.php"
]
},
"autoload-dev": {
Expand Down
9 changes: 0 additions & 9 deletions src/Captcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
}

/**
Expand Down
72 changes: 18 additions & 54 deletions src/CaptchaServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
<?php namespace Mews\Captcha;

use Illuminate\Support\ServiceProvider;
use Illuminate\Validation\Factory;

class CaptchaServiceProvider extends ServiceProvider {

/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = false;

/**
*
* Boot the service provider.
*
* @return null
*/
public function boot()
{
// Publish configuration files
$this->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);
});
}

/**
Expand All @@ -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(
Expand All @@ -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'];
}

}
11 changes: 0 additions & 11 deletions src/CaptchaValidator.php

This file was deleted.

0 comments on commit 2e5d8cf

Please sign in to comment.