当前位置: 首页>>代码示例>>PHP>>正文


PHP Validator::string方法代码示例

本文整理汇总了PHP中Respect\Validation\Validator::string方法的典型用法代码示例。如果您正苦于以下问题:PHP Validator::string方法的具体用法?PHP Validator::string怎么用?PHP Validator::string使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Respect\Validation\Validator的用法示例。


在下文中一共展示了Validator::string方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setState

 public function setState($value)
 {
     if (!v::string()->notEmpty()->validate($value) || strlen($value) != 2) {
         throw new FieldRequiredException("Estado é uma informação obrigatória");
     }
     $this->_state = strtoupper($value);
 }
开发者ID:dindigital,项目名称:nfe-focus,代码行数:7,代码来源:Address.php

示例2: __construct

 public function __construct($webapiKey = null, $userLogin = null, $hashedPassword = null)
 {
     $this->properties['webapiKey'] = new Property(['validator' => function ($value) {
         try {
             Validator::string()->noWhitespace()->notEmpty()->length(4)->assert($value);
         } catch (NestedValidationExceptionInterface $e) {
             throw new ValidationException($e);
         }
     }]);
     if (!is_null($webapiKey)) {
         $this->properties['webapiKey']->set($webapiKey)->lock();
     }
     // --------------------
     $this->properties['userLogin'] = new Property(['validator' => function ($value) {
         try {
             Validator::string()->noWhitespace()->notEmpty()->length(4)->assert($value);
         } catch (NestedValidationExceptionInterface $e) {
             throw new ValidationException($e);
         }
     }]);
     if (!is_null($userLogin)) {
         $this->properties['userLogin']->set($userLogin)->lock();
     }
     // ----------------------
     $this->properties['hashedPassword'] = new Property(['validator' => function ($value) {
         try {
             Validator::string()->noWhitespace()->notEmpty()->regex('/^([A-Za-z0-9+\\/]{4})*([A-Za-z0-9+\\/]{4}|[A-Za-z0-9+\\/]{3}=|[A-Za-z0-9+\\/]{2}==)$/')->assert($value);
         } catch (NestedValidationExceptionInterface $e) {
             throw new ValidationException($e);
         }
     }]);
     if (!is_null($hashedPassword)) {
         $this->properties['hashedPassword']->set($hashedPassword)->lock();
     }
 }
开发者ID:rindeal,项目名称:allegro-client,代码行数:35,代码来源:ApiCredentials.php

示例3: setJustification

 public function setJustification($justification)
 {
     if (!v::string()->length(15, 1000)->validate($justification)) {
         throw new FieldRequiredException("A justicativa deve ter entre 15 e 100 caracteres");
     }
     $this->_justification = $justification;
 }
开发者ID:dindigital,项目名称:nfe-focus,代码行数:7,代码来源:CancelTransaction.php

示例4: set

 /**
  * Saves a setting as a key/value pair
  *
  * Settings specific to fast-forward start with a `ff.` prefix.
  *
  * You can use the constants of this class to avoid looking up the key names.
  *
  * @param string $key   Unique key name.<br>
  *                      Must contain only letters (a-z, A-Z), digits (0-9) and "."
  * @param string $value
  *
  * @throws \Exception
  */
 public function set($key, $value)
 {
     $out = $this->client->getOutput();
     try {
         v::string()->alnum('.')->noWhitespace()->notEmpty()->assert($key);
     } catch (NestedValidationExceptionInterface $e) {
         $out->error($e->getFullMessage());
         return;
     }
     $setting = $this->get($key, true);
     if ($setting === null) {
         $setting = new Setting();
         $setting->key = $key;
     }
     $oldValue = $setting->value;
     $setting->value = $value;
     if (!$this->validate($setting)) {
         return;
     }
     if ($oldValue === null) {
         $out->writeln("Inserting new setting:\n{$key} = <options=bold>{$value}</>");
     } elseif ($oldValue !== $value) {
         $out->writeln("Changing setting:\n{$key} = {$oldValue} --> <options=bold>{$value}</>");
     } else {
         $out->writeln("Setting already up-to-date:\n{$key} = {$value}");
     }
     $setting->save();
 }
开发者ID:natedrake,项目名称:fast-forward,代码行数:41,代码来源:Settings.php

示例5: validate

 public function validate($data)
 {
     $validator = V::key('name', V::string()->length(0, 100), true)->key('email', V::email()->length(0, 200), true)->key('password', V::string()->length(0, 100), true);
     try {
         $validator->assert($data);
         switch ($data['userable_type']) {
             case 'Designer':
                 $this->designerCreationValidator->validate($data);
                 $data['userable_type'] = DesignerModel::class;
                 break;
             case 'Administrator':
                 $this->adminCreationValidator->validate($data);
                 $data['userable_type'] = AdministratorModel::class;
                 break;
             case 'Buyer':
                 $this->buyerCreationValidator->validate($data);
                 $data['userable_type'] = BuyerModel::class;
                 break;
             default:
                 break;
         }
     } catch (AbstractNestedException $e) {
         $errors = $e->findMessages(['email', 'length', 'in']);
         throw new ValidationException('Could not create user.', $errors);
     }
     return true;
 }
开发者ID:HOFB,项目名称:HOFB,代码行数:27,代码来源:UserCreationValidator.php

示例6: validate

 public function validate($prop, $label)
 {
     $value = $this->getValue($prop);
     if (!v::string()->cnpj()->validate($value)) {
         $this->addException("O preenchimento do campo {$label} está inválido");
     }
 }
开发者ID:dindigital,项目名称:din,代码行数:7,代码来源:StringCNPJ.php

示例7: post

 public function post()
 {
     try {
         $newManufacturer = (object) (['id' => null] + $_POST);
         v::arr()->key('name', v::string()->notEmpty()->length(1, 300))->assert($_POST);
         if ($_FILES['files']['error'] == 4) {
             throw new Exception('O campo imagem é obrigatório');
         }
         if (empty($newManufacturer->manufacturer_featured)) {
             $newManufacturer->manufacturer_featured = null;
         }
         $this->collection->persist($newManufacturer);
         $this->collection->flush();
         foreach ($_FILES as $file) {
             $this->uploaderService->setFile($_POST['name'], 'files');
             $image = (object) ['name' => $this->uploaderService->getFile()->getNameWithExtension(), 'title' => $_POST['name'], 'type' => $this->uploaderService->getFile()->getMimetype(), 'manufacturer_id' => $newManufacturer->id];
             $this->imageCollection->persist($image);
             $this->imageCollection->flush();
             $this->uploaderService->upload();
         }
         header('HTTP/1.1 303 See Other');
         header('Location: /catalog/manufacturers');
     } catch (NestedValidationExceptionInterface $e) {
         return $this->get() + ['manufacturer/addManufacturer' => $newManufacturer, 'messages' => $e->findMessages(['name' => 'O nome deve ser entre 1 e 300 caracteres'])];
     }
 }
开发者ID:supercluster,项目名称:catalog,代码行数:26,代码来源:Add.php

示例8: validate

 public function validate($prop, $label)
 {
     $value = $this->getValue($prop);
     if (!v::string()->notEmpty()->validate($value)) {
         $this->addException("O campo {$label} é de preenchimento obrigatório");
     }
 }
开发者ID:dindigital,项目名称:din,代码行数:7,代码来源:String.php

示例9: setName

 public function setName($value)
 {
     if (!v::string()->notEmpty()->validate($value)) {
         throw new FieldRequiredException("Nome/Razão Social é uma informação obrigatória");
     }
     $this->_name = $value;
 }
开发者ID:dindigital,项目名称:nfe-focus,代码行数:7,代码来源:Receiver.php

示例10: post

 public function post($manufacturerId)
 {
     $editManufacturer = $this->collection[$manufacturerId]->fetch() ?: new stdClass();
     foreach ($_POST as $k => $v) {
         $editManufacturer->{$k} = $v;
     }
     try {
         v::object()->attribute('name', v::string()->notEmpty()->length(1, 300))->assert($editManufacturer);
         $this->collection->persist($editManufacturer);
         $this->collection->flush();
         if (empty($newManufacturer->manufacturer_featured)) {
             $newManufacturer->manufacturer_featured = null;
         }
         if ($_FILES['files']['error'] != 4) {
             foreach ($_FILES as $file) {
                 $this->uploaderService->setFile($editManufacturer->name, 'files');
                 $image = (object) ['name' => $this->uploaderService->getFile()->getNameWithExtension(), 'title' => $editManufacturer->name, 'type' => $this->uploaderService->getFile()->getMimetype(), 'manufacturer_id' => $editManufacturer->id];
                 $this->imageCollection->persist($image);
                 $this->imageCollection->flush();
                 $this->uploaderService->upload();
             }
         }
         header('HTTP/1.1 303 See Other');
         header('Location: ' . $_SERVER['REQUEST_URI']);
     } catch (NestedValidationExceptionInterface $e) {
         return ['editManufacturer' => $editManufacturer, 'messages' => $e->findMessages(['name' => 'Name must have between 1 and 300 chars', 'enabled' => 'Could not enable manufacturer'])];
     }
 }
开发者ID:supercluster,项目名称:catalog,代码行数:28,代码来源:Edit.php

示例11: setStateRegistration

 public function setStateRegistration($value)
 {
     if (!v::string()->notEmpty()->validate($value)) {
         throw new FieldRequiredException("Inscrição Estadual é uma informação obrigatória");
     }
     $value = preg_replace('/\\D/', '', $value);
     $this->_stateRegistration = $value;
 }
开发者ID:dindigital,项目名称:nfe-focus,代码行数:8,代码来源:Issuer.php

示例12: testGetFullMessageShouldIncludeAllValidationMessagesInAChain

 public function testGetFullMessageShouldIncludeAllValidationMessagesInAChain()
 {
     try {
         Validator::string()->length(1, 15)->assert('');
     } catch (NestedValidationExceptionInterface $e) {
         $this->assertEquals('\\-These rules must pass for ""
\-"" must have a length between 1 and 15', $e->getFullMessage());
     }
 }
开发者ID:00F100,项目名称:Validation,代码行数:9,代码来源:ValidatorTest.php

示例13: validateServer

 private function validateServer($server)
 {
     $validate_server = Validator::string()->noWhitespace()->length(6, 80);
     if (!$validate_server->validate($server)) {
         return false;
     } else {
         return true;
     }
 }
开发者ID:Nyco,项目名称:movim,代码行数:9,代码来源:Account.php

示例14: validateServerNode

 private function validateServerNode($server, $node)
 {
     $validate_server = Validator::string()->noWhitespace()->length(6, 40);
     $validate_node = Validator::string()->length(3, 100);
     if (!$validate_server->validate($server) || !$validate_node->validate($node)) {
         return false;
     } else {
         return true;
     }
 }
开发者ID:vijo,项目名称:movim,代码行数:10,代码来源:Blog.php

示例15: validate

 public function validate($data)
 {
     $validator = V::key('about', V::string()->length(0, 100), false)->key('website', V::string()->length(0, 100), false)->key('twitter_username', V::string()->length(0, 100), false)->key('facebook_url', V::string()->length(0, 100), false)->key('pinterest_url', V::string()->length(0, 100), false)->key('instagram_username', V::string()->length(0, 100), false);
     try {
         $validator->assert($data);
     } catch (AbstractNestedException $e) {
         $errors = $e->findMessages(['about', 'website', 'twitter_username', 'facebook_url', 'pinterest_url', 'instagram_username']);
         throw new ValidationException('Could not update user.', $errors);
     }
     return true;
 }
开发者ID:HOFB,项目名称:HOFB,代码行数:11,代码来源:DesignerUpdateValidator.php


注:本文中的Respect\Validation\Validator::string方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。