您的位置:首页 > 编程语言 > PHP开发

[李景山php]每天laravel-20161001|ValidationServiceProvider.php

2016-07-28 09:02 567 查看
<?php

namespace Illuminate\Validation;

use Illuminate\Support\ServiceProvider;
// just namespace
class ValidationServiceProvider extends ServiceProvider
{// a class extends a standard class
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = true;// Indicates if loading of the provider is deferred.

/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->registerPresenceVerifier();// register Presence Verifier

$this->registerValidationFactory();// register validation Factory
}// Register the service provider.

/**
* Register the validation factory.
*
* @return void
*/
protected function registerValidationFactory()
{
$this->app->singleton('validator', function ($app) {
$validator = new Factory($app['translator'], $app);// get instance of the

// The validation presence verifier is responsible for determining the existence
// of values in a given data collection, typically a relational database or
// other persistent data stores. And it is used to check for uniqueness.
if (isset($app['validation.presence'])) {// has it
$validator->setPresenceVerifier($app['validation.presence']);//and set it
}// if has a other way to get it

return $validator;// return it
});// set the singleton
}// Register the validation factory.

/**
* Register the database presence verifier.
*
* @return void
*/
protected function registerPresenceVerifier()
{
$this->app->singleton('validation.presence', function ($app) {
return new DatabasePresenceVerifier($app['db']);
});// like set a singleton
}//Register the database presence verifier.

/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return [
'validator', 'validation.presence',
];
}// get return
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: