本文整理汇总了PHP中Illuminate\Validation\Factory::setPresenceVerifier方法的典型用法代码示例。如果您正苦于以下问题:PHP Factory::setPresenceVerifier方法的具体用法?PHP Factory::setPresenceVerifier怎么用?PHP Factory::setPresenceVerifier使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Validation\Factory
的用法示例。
在下文中一共展示了Factory::setPresenceVerifier方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setValidator
protected function setValidator()
{
$filesystem = new FileLoader(new Filesystem(), CONFIG_DIR . DIRECTORY_SEPARATOR . 'langs');
$translator = new Translator($filesystem, Main::$app->web->get('locale', false) ?: 'en');
$this->validator = new ValidatorFactory($translator);
$verifier = new DatabasePresenceVerifier($this->capsule->getDatabaseManager());
$this->validator->setPresenceVerifier($verifier);
}
示例2: register
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->mergeConfigFrom(__DIR__ . '/../config/captcha.php', 'mews.captcha');
/**
* @param $app
* @return Captcha
*/
$this->app->bind('captcha', function ($app) {
return new Captcha($app['Illuminate\\Filesystem\\Filesystem'], $app['Illuminate\\Config\\Repository'], $app['Intervention\\Image\\ImageManager'], $app['Illuminate\\Session\\Store'], $app['Illuminate\\Hashing\\BcryptHasher'], $app['Illuminate\\Support\\Str']);
});
/**
* @param Captcha $captcha
* @param $config
* @return \Intervention\Image\ImageManager
*/
$this->app['router']->get('captcha/{config?}', 'Chekun\\Captcha\\CaptchaController@draw');
$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;
});
}
示例3: register
public function register(Application $app)
{
$core = $app;
$app['illuminate'] = new Container();
$app['illuminate']['config'] = array('cache.driver' => 'memcached', 'cache.memcached' => array(array('host' => 'localhost', 'port' => '11211')));
$app['illuminate']->bindShared('validator', function ($app) use($core) {
$validator = new Factory($core['translator'], $app);
// 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'])) {
$validator->setPresenceVerifier($app['validation.presence']);
}
return $validator;
});
$app['illuminate']->bindShared('cache', function ($app) {
return new CacheManager($app);
});
$app['illuminate']->bindShared('cache.store', function ($app) {
return $app['cache']->driver();
});
$app['illuminate']->bindShared('memcached.connector', function () {
return new MemcachedConnector();
});
}
示例4: registerValidationFactory
/**
* @return void
*/
protected function registerValidationFactory()
{
$this->app->singleton('validator', function ($app) {
$validator = new Factory($app['translator'], $app);
if (isset($app['validation.presence'])) {
$validator->setPresenceVerifier($app['validation.presence']);
}
return $validator;
});
}
示例5: registerValidationFactory
/**
* Register the validation factory.
*
* @return void
*/
protected function registerValidationFactory()
{
$validator = new Factory($this->container['translator'], $this->container);
// 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($this->container['validation.presence'])) {
$validator->setPresenceVerifier($this->container['validation.presence']);
}
return $validator;
}
示例6: register
/**
* Register any validation services.
*
* @param \Pimple\Container $container
*/
public function register(Container $container)
{
$this->registerPresenceVerifier($container);
$container['validator'] = function () use($container) {
$validator = new Factory($container['translator']);
if (isset($container['validation.presence'])) {
$validator->setPresenceVerifier($container['validation.presence']);
}
return $validator;
};
}
示例7: __construct
/**
* Create a new Validator factory instance.
*
* @param \Illuminate\Database\Capsule\Manager $db
* @return \Illuminate\Validation\Factory
*/
public function __construct($db)
{
if (!$this->factory) {
/**
* illuminate/translation (Translator) package need for correct work of Validator
*/
$translator = new Translator('en');
$this->factory = new Factory($translator);
/**
* To set database presence verifier we need database connection instance,
* which is implements ConnectionResolverInterface. For this purpose
* Illuminate\Database\Capsule\Manager class, which we get from $db arg,
* have getDatabaseManager() function.
* With defined DatabasePresenceVerifier we can use rules such as:
* unique:table,column,except,idColumn
* exists:table,column
*/
$dbManager = $db->getDatabaseManager();
$this->factory->setPresenceVerifier(new DatabasePresenceVerifier($dbManager));
}
return $this->factory;
}
示例8: register
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->registerPresenceVerifier();
$this->app['validator'] = $this->app->share(function ($app) {
$validator = new Factory($app['translator'], $app);
// 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'])) {
$validator->setPresenceVerifier($app['validation.presence']);
}
return $validator;
});
}
示例9: testMakeMethodCreatesValidValidator
public function testMakeMethodCreatesValidValidator()
{
$translator = m::mock('Symfony\\Component\\Translation\\TranslatorInterface');
$factory = new Factory($translator);
$validator = $factory->make(array('foo' => 'bar'), array('baz' => 'boom'));
$this->assertEquals($translator, $validator->getTranslator());
$this->assertEquals(array('foo' => 'bar'), $validator->getData());
$this->assertEquals(array('baz' => array('boom')), $validator->getRules());
$presence = m::mock('Illuminate\\Validation\\PresenceVerifierInterface');
$factory->extend('foo', function () {
});
$factory->setPresenceVerifier($presence);
$validator = $factory->make(array(), array());
$this->assertEquals(array('foo' => function () {
}), $validator->getExtensions());
$this->assertEquals($presence, $validator->getPresenceVerifier());
}
示例10: register
public function register()
{
$this->app->singleton('validation.presence', function ($app) {
return new DatabasePresenceVerifier($app['db']);
});
$this->app->singleton('validator', function ($app) {
$validator = new Factory($app['translator'], $app);
$validator->resolver(function ($translator, $data, $rules, $messages, $customAttributes) {
return new \App\Http\Services\Validator($translator, $data, $rules, $messages, $customAttributes);
});
// 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'])) {
$validator->setPresenceVerifier($app['validation.presence']);
}
return $validator;
});
}
示例11: register
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->registerPresenceVerifier();
$this->app->singleton('validator', function ($app) {
$validator = new Factory($app['translator'], $app);
// 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'])) {
$validator->setPresenceVerifier($app['validation.presence']);
}
// Add validation extensions
$extensions = config('esensi/core::validation.extensions', []);
foreach ($extensions as $extension => $class) {
$validator->extend($extension, $class . '@validate' . ucfirst(studly_case($extension)));
$validator->replacer($extension, $class . '@replace' . ucfirst(studly_case($extension)));
}
return $validator;
});
}
示例12: testBoot
public function testBoot()
{
$translator = Mockery::mock('Symfony\\Component\\Translation\\TranslatorInterface');
$translator->shouldReceive('get');
$presence = Mockery::mock('Illuminate\\Validation\\PresenceVerifierInterface');
$factory = new Factory($translator);
$factory->setPresenceVerifier($presence);
$container = Mockery::mock('Illuminate\\Container\\Container');
$container->shouldReceive('bind');
$container->shouldReceive('offsetGet')->with('translator')->andReturn($translator);
$container->shouldReceive('offsetGet')->with('validator')->andReturn($factory);
$sp = Mockery::mock('Cviebrock\\ImageValidator\\ImageValidatorServiceProvider[package]', array($container));
$sp->shouldReceive('package');
$sp->boot();
$validator = $factory->make(array(), array());
foreach ($validator->getExtensions() as $rule => $class_and_method) {
$this->assertTrue(in_array($rule, $sp->getRules()));
$this->assertEquals('Cviebrock\\ImageValidator\\ImageValidator@' . 'validate' . studly_case($rule), $class_and_method);
list($class, $method) = Str::parseCallback($class_and_method, null);
$this->assertTrue(method_exists($class, $method));
}
}
示例13: configureAsExternal
/**
* Configures Ardent to be used outside of Laravel - correctly setting Eloquent and Validation modules.
* @todo Should allow for additional language files. Would probably receive a Translator instance as an optional argument, or a list of translation files.
*
* @param array $connection Connection info used by {@link \Illuminate\Database\Capsule\Manager::addConnection}.
* Should contain driver, host, port, database, username, password, charset and collation.
*/
public static function configureAsExternal(array $connection)
{
$db = new DatabaseCapsule();
$db->addConnection($connection);
$db->setEventDispatcher(new Dispatcher(new Container()));
//TODO: configure a cache manager (as an option)
// Make this Capsule instance available globally via static methods
$db->setAsGlobal();
$db->bootEloquent();
$translator = new Translator('en');
$translator->addLoader('file_loader', new PhpFileLoader());
$translator->addResource('file_loader', dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'lang' . DIRECTORY_SEPARATOR . 'en' . DIRECTORY_SEPARATOR . 'validation.php', 'en');
self::$externalValidator = true;
self::$validationFactory = new ValidationFactory($translator);
self::$validationFactory->setPresenceVerifier(new DatabasePresenceVerifier($db->getDatabaseManager()));
}
示例14: function
$validator = $validation->make($data, $rules);
if ($validator->fails()) {
$errors = $validator->errors();
}
return $app->render('form.php', ['posted' => true, 'errors' => $errors, 'email' => $_POST['email']]);
});
// For a thorough example, we establish a database connection
// to drive the database presence verifier used by the validator.
// If you do not need to validate against values in the database,
// the database presence verifier and related code can be removed.
$app->get('/database', function () use($app) {
return $app->render('form.php', ['posted' => false, 'errors' => null, 'email' => '']);
});
$app->post('/database', function () use($app) {
$capsule = new Capsule();
$capsule->addConnection(['driver' => 'mysql', 'host' => 'localhost', 'database' => 'illuminate_non_laravel', 'username' => 'root', 'password' => '', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '']);
$loader = new FileLoader(new Filesystem(), 'lang');
$translator = new Translator($loader, 'en');
$presence = new DatabasePresenceVerifier($capsule->getDatabaseManager());
$validation = new Factory($translator, new Container());
$validation->setPresenceVerifier($presence);
$data = ['email' => $_POST['email']];
$rules = ['email' => 'required|email|unique:users'];
$errors = null;
$validator = $validation->make($data, $rules);
if ($validator->fails()) {
$errors = $validator->errors();
}
return $app->render('form.php', ['posted' => true, 'errors' => $errors, 'email' => $_POST['email']]);
});
$app->run();
示例15: createIlluminateDriver
/**
* Create an instance of the Illuminate validation driver.
*
* @return \Deefour\Aide\Validation\AbstractValidator
*/
protected function createIlluminateDriver()
{
$factory = new IlluminateFactory($this->app['translator'], $this->app);
$factory->setPresenceVerifier($this->app['validation.presence']);
return new IlluminateValidator($factory);
}