本文整理汇总了PHP中Respect\Validation\Validator::notEmpty方法的典型用法代码示例。如果您正苦于以下问题:PHP Validator::notEmpty方法的具体用法?PHP Validator::notEmpty怎么用?PHP Validator::notEmpty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Respect\Validation\Validator
的用法示例。
在下文中一共展示了Validator::notEmpty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initRules
/**
* Set items constraints
*
* @return void
*/
public function initRules()
{
$this->rules['no_certificado'] = V::numeric()->noWhitespace()->setName('Numero de certificado');
$this->rules['clave'] = V::notEmpty()->noWhitespace()->setName('Contraseña de la llave privada');
}
示例2: index
public function index($params)
{
Validator::notEmpty()->setName('name')->check($params['name']);
Validator::notEmpty()->setName('password')->check($params['password']);
$levels = Config::loadData('level');
$this->render('index.php', ['name' => $params['name']]);
}
示例3: __construct
public function __construct(Client $client, $key)
{
$this->client = $client;
$this->key = $key;
$baseUrl = $this->client->getConfig('base_uri');
Validator::notEmpty()->url()->endsWith('/')->setName("URL for NewRelic's Insights API must be valid and have a trailing slash")->assert($baseUrl);
}
示例4: password
/**
* @param $param
* @return string
* @throws EntityValidationException
*/
public function password($param)
{
if (!v::notEmpty()->length(2, 100)->validate($param)) {
throw new EntityValidationException('User', 'password', $param, 'length must be between 2 and 100');
}
return $param;
}
示例5: fuelTypeName
/**
* @param $param
* @return string
* @throws EntityValidationException
*/
public function fuelTypeName($param)
{
if (!v::notEmpty()->length(1, 100)->validate($param)) {
throw new EntityValidationException('VehicleCSV', 'fuelTypeName', $param, 'length must be between 1 and 100');
}
return $param;
}
示例6: setValidationRules
protected function setValidationRules($validator)
{
$required = new Validator();
$required->notEmpty();
$validator->attribute('name', $required);
$validator->attribute('content', $required);
}
示例7: postalCode
/**
* @param $param
* @return string
* @throws EntityValidationException
*/
public function postalCode($param)
{
if (!v::notEmpty()->length(2, 100)->validate($param)) {
throw new EntityValidationException('Address', 'postalCode', $param, 'length must be between 2 and 50');
}
return $param;
}
示例8: validateField
private function validateField($parameters, $fieldName)
{
if (v::key($fieldName)->validate($parameters)) {
if (v::notEmpty()->validate($parameters[$fieldName])) {
return true;
}
}
return false;
}
示例9: uniqueReference
/**
* @param $param
* @return string
* @throws EntityValidationException
*/
public function uniqueReference($param)
{
if (empty($param) || is_null($param)) {
return $param;
}
if (!v::notEmpty()->length(1, 100)->validate((string) $param)) {
throw new EntityValidationException('Vendor', 'uniqueReference', $param, 'length must be between 1 and 100');
}
return $param;
}
示例10: postChild
protected function postChild($categoryId)
{
try {
v::arr()->key('name', v::string()->notEmpty()->length(1, 300))->key('parent_category', v::notEmpty()->int()->equals($categoryId))->assert($_POST);
$newCategory = (object) (['id' => null] + $_POST);
$this->collection->persist($newCategory);
$this->collection->flush();
header('HTTP/1.1 303 See Other');
header('Location: ' . $_SERVER['REQUEST_URI']);
} catch (NestedValidationExceptionInterface $e) {
return ['category/editCategory' => $editProduct, 'messages' => $e->findMessages(['name' => 'Name must have between 1 and 300 chars'])];
}
}
示例11: validateAddress
public function validateAddress($address)
{
//@TODO: properly check all types.. strings need to be double checked for alnum, cause of typecasting.
$rules = v::key('firstname', v::notEmpty()->setName('First name'))->key('lastname', v::notEmpty()->setName('Last name'))->key('address', v::alnum(".,-'")->notEmpty()->setName('Address'))->key('secondary_address', v::when(v::notEmpty(), v::alnum(".,-'"), v::alwaysValid())->setName('Address 2'))->key('city', v::alnum()->notEmpty()->setName('City'))->key('state', v::alnum()->notEmpty()->setName('State'))->key('zip', v::when(v::notEmpty(), v::postalCode('US'), v::alwaysValid())->notEmpty()->setName('Zipcode'));
if ($rules->validate($address)) {
return true;
}
try {
$rules->check($address);
} catch (ValidationExceptionInterface $exception) {
// $this->error = $exception->getMainMessage();
}
return false;
}
示例12: test_findMessages_should_apply_templates_to_flattened_messages
public function test_findMessages_should_apply_templates_to_flattened_messages()
{
$stringMax256 = v::string()->length(5, 256);
$alnumDot = v::alnum('.');
$stringMin8 = v::string()->length(8, null);
$v = v::allOf(v::attribute('first_name', $stringMax256)->setName('First Name'), v::attribute('last_name', $stringMax256)->setName('Last Name'), v::attribute('desired_login', $alnumDot)->setName('Desired Login'), v::attribute('password', $stringMin8)->setName('Password'), v::attribute('password_confirmation', $stringMin8)->setName('Password Confirmation'), v::attribute('stay_signedin', v::notEmpty())->setName('Stay signed in'), v::attribute('enable_webhistory', v::notEmpty())->setName('Enabled Web History'), v::attribute('security_question', $stringMax256)->setName('Security Question'))->setName('Validation Form');
try {
$v->assert((object) array('first_name' => 'fiif', 'last_name' => null, 'desired_login' => null, 'password' => null, 'password_confirmation' => null, 'stay_signedin' => null, 'enable_webhistory' => null, 'security_question' => null));
} catch (ValidationException $e) {
$messages = $e->findMessages(array('allOf' => 'Invalid {{name}}', 'first_name.length' => 'Invalid length for {{name}} {{input}}'));
$this->assertEquals($messages['allOf'], 'Invalid Validation Form');
$this->assertEquals($messages['first_name_length'], 'Invalid length for "fiif" fiif');
}
}
示例13: __construct
public function __construct($data)
{
parent::__construct();
$this->data = $data;
$this->fields = array('firstname' => array('value' => $this->data['firstname'], 'validators' => array('notEmpty'), 'errors' => array('Firstname is empty')), 'email' => array('value' => $this->data['email'], 'validators' => array('email', 'notEmpty'), 'errors' => array('Email is not valid', 'Email is empty')), 'url' => array('value' => $this->data['url'], 'validators' => array('notEmpty', 'url'), 'errors' => array('Url is empty', 'Url is not valid')), 'cv' => array('value' => $_FILES['cv'], 'validators' => function () {
return v::exists()->validate($_FILES['cv']["tmp_name"]);
}, 'errors' => array('File is empty')), 'content' => array('value' => $this->data['content'], 'validators' => function ($value) {
return v::when(v::int(), v::positive(), v::notEmpty())->validate($value);
}, 'errors' => array('content is not valid')), 'int' => array('value' => $this->data['int'], 'validators' => function ($value) {
return v::allOf(v::int(), v::positive(), v::notEmpty())->validate($value);
}, 'errors' => array('int is not valid')), 'uppercase' => array('value' => '', 'validators' => function ($value) {
return v::string()->uppercase()->validate($value);
}, 'errors' => array('uppercase is not valid')));
}
示例14: validate
public function validate($addr)
{
$this->clearErrors();
// Do our special validations first
// State should only be set for the US
if ($addr->getField('Country') != 'US' && v::notEmpty()->validate($addr->getField('State'))) {
$this->addError('State', $this->STATE_ONLY_FOR_US);
}
// Country must be an ISO3166-1 Country Code
if (!array_key_exists($addr->getField('Country'), Iso3166::get())) {
$this->addError('Country', $this->COUNTRY_VALID_CODE);
}
// Perform some general validations and return ourself
return parent::validate($addr);
}
示例15: login
/**
* @RPC\Route("/api/auth/login")
* @RPC\Method("POST")
*/
public function login()
{
$credentials = json_decode($this->request->getContent(), true);
try {
v::create()->key('email', v::notEmpty())->key('password', v::notEmpty())->assert($credentials);
} catch (ValidationException $e) {
$errors = $e->findMessages(['email', 'password']);
throw new \pmill\Doctrine\Rest\Exception\ValidationException($errors);
}
$password = $credentials['password'];
unset($credentials['password']);
/** @var User $user */
$user = $this->authenticationService->authenticateWithCredentials(User::class, $credentials, $password);
$token = $this->authenticationService->generateTokenFromObject($user);
return ['token' => $token];
}