本文整理汇总了PHP中Nette\Utils\Validators::is方法的典型用法代码示例。如果您正苦于以下问题:PHP Validators::is方法的具体用法?PHP Validators::is怎么用?PHP Validators::is使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Utils\Validators
的用法示例。
在下文中一共展示了Validators::is方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isAllowed
/**
* @param string $role
* @param IResource|string $resource
* @param $privilege
* @return bool
*/
public function isAllowed($role, $resource, $privilege)
{
$roles = [];
if ($role instanceof User) {
$roles = $role->getRoles();
} elseif ($role instanceof \Nette\Security\User) {
$userIdentity = $role->getIdentity();
if ($userIdentity !== null) {
$roles = $role->getIdentity()->getRoles();
}
} elseif ($role instanceof Role) {
$roles[] = $role->getName();
} elseif (Validators::is($role, 'unicode:1..')) {
$roles[] = $role;
} else {
return false;
}
try {
foreach ($roles as $role) {
if ($this->acl->isAllowed($role, $resource, $privilege) === true) {
return true;
}
}
return false;
} catch (InvalidStateException $e) {
return false;
// role does not exists
}
}
示例2: addEventsToSkip
/**
* @param array $eventsToSkip * or [logType => *] or [logType1 => [event1, event2, ...], logType2 => ...]
*/
public function addEventsToSkip($eventsToSkip)
{
if ($eventsToSkip === '*') {
$this->eventsToSkip = $eventsToSkip;
} elseif (is_array($eventsToSkip)) {
foreach ($eventsToSkip as $type => $events) {
if (!Validators::is($type, 'unicode:1..')) {
$this->logger->addWarning(sprintf('The keys of array $eventsToSkip must be non-empty strings. "%s" given', gettype($type)));
continue;
}
if ($events === '*') {
$this->eventsToSkip[$type] = $events;
} elseif (is_array($events)) {
foreach ($events as $event) {
if (Validators::is($event, 'unicode:1..')) {
$this->eventsToSkip[$type][$event] = $event;
} else {
$this->logger->addWarning(sprintf('The values of array $eventsToSkip[%s] must be non-empty string. "%s" given', $type, gettype($event)));
}
}
} else {
$this->logger->addWarning(sprintf('The values of array $eventsToSkip must be an ARRAY or * (a star). "%s" given', gettype($events)));
}
}
} else {
$this->logger->addWarning(sprintf('Argument $eventsToSkip must be an ARRAY or * (a star). "%s" given', gettype($eventsToSkip)));
}
}
示例3: loadState
public function loadState(array $params)
{
if (isset($params['page']) and !Validators::is($params['page'], 'numericint')) {
$params['page'] = 1;
}
parent::loadState($params);
$this->getPaginator()->setPage($this->page);
$this->page = $this->getPaginator()->getPage();
}
示例4: setUser
/**
* @param $user
*/
public function setUser($user)
{
if ($user instanceof User and !$user->isDetached()) {
$this->assignEntityToProperty($user, 'user');
} else {
if (Validators::is($user, 'numericint')) {
$this->row->userID = $user;
$this->row->cleanReferencedRowsCache('user', 'userID');
} else {
throw new InvalidArgumentException('Argument $user can by only attached instance
of App\\Entities\\User or integer number.');
}
}
}
示例5: actionRegistration
public function actionRegistration($email, $token)
{
if (!Validators::is($email, 'email')) {
$this->flashMessage('E-mailová adresa nemá platný formát.', 'warning');
$this->redirect('Login:default');
}
try {
$this->invitation = $this->invitationsFacade->checkInvitation($email, $token);
} catch (\Exceptions\Runtime\InvitationValidityException $t) {
$this->flashMessage('Registrovat se může pouze uživatel s platnou pozvánkou.', 'warning');
$this->redirect('Login:default');
}
$this['registrationForm']['email']->setDefaultValue($this->invitation->email);
}
示例6: setRecipient
/**
* @param User|int $recipient
*/
private function setRecipient($recipient)
{
if ($recipient instanceof User and !$recipient->isDetached()) {
$this->assignEntityToProperty($recipient, 'recipient');
} else {
if (Validators::is($recipient, 'numericint')) {
$this->row->recipient = $recipient;
$this->row->cleanReferencedRowsCache('user', 'recipient');
} else {
throw new InvalidArgumentException('Argument $recipient can by only instance of App\\Entities\\User or
integer number.');
}
}
}
示例7: setAuthor
/**
* @param string $author
*/
private function setAuthor($author)
{
if ($author instanceof User and !$author->isDetached()) {
$this->assignEntityToProperty($author, 'author');
} else {
if (Validators::is($author, 'numericint')) {
$this->row->author = $author;
$this->row->cleanReferencedRowsCache('user', 'author');
} else {
throw new InvalidArgumentException('Argument $author can by only instance of App\\Entities\\User or
integer number.');
}
}
}
示例8: getUserID
/**
* @param \App\Model\Entities\User|int $user
* @return int
*/
protected function getUserID($user)
{
$id = null;
if ($user instanceof User and !$user->isDetached()) {
$id = $user->userID;
} else {
if (Validators::is($user, 'numericint')) {
$id = $user;
} else {
throw new InvalidArgumentException('Argument $user must be instance of ' . User::class . '
or integer number.');
}
}
return $id;
}
示例9: validate
/**
* Validate value for this rule
* @param mixed $value
* @param Rule $rule
* @return bool
*
* @throws ValidationException
* @throws InvalidStateException
*/
public function validate($value, Rule $rule)
{
if (isset($this->handle[$rule->expression])) {
$callback = $this->handle[$rule->expression];
if (!is_callable($callback)) {
throw new InvalidStateException('Handle for expression ' . $rule->expression . ' not found or is not callable');
}
$params = array($value, $rule);
call_user_func_array($callback, $params);
return TRUE;
}
$expression = $this->parseExpression($rule);
if (!Validators::is($value, $expression)) {
throw ValidationException::createFromRule($rule, $value);
}
return TRUE;
}
示例10: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
if ($input->hasOption('password') && $input->getOption('password') === NULL) {
$output->writeln('<error>Please enable interactive mode to set password.</error>');
return 1;
}
if ($input->hasOption('password') && $input->getOption('generate-password')) {
$output->writeln('<error>Cannot set and generate password at once.</error>');
return 1;
}
if (!$input->hasOption('password') && !$input->getOption('generate-password')) {
$output->writeln('<error>Cannot create user without password.</error>');
return 1;
}
$name = $input->getArgument('name');
if ($this->model->getByNameOrEmail($name)) {
$output->writeln('<error>User with same name already exists.</error>');
return 1;
}
$email = $input->getArgument('email');
if (!Validators::is($email, 'email')) {
$output->writeln('<error>Invalid email</error>');
return 1;
}
if ($this->model->getByNameOrEmail($email)) {
$output->writeln('<error>User with same email already exists.</error>');
return 1;
}
$printPassword = FALSE;
if ($input->getOption('password') !== NULL) {
$password = $input->getOption('password');
} elseif ($this->getOption('generate-password')) {
$password = Strings::random();
$printPassword = TRUE;
}
$roles = $input->getOption('role');
$this->factory->create($name, $email, $password, $roles);
if ($printPassword) {
$verbosity = $output->getVerbosity();
$output->setVerbosity(OutputInterface::VERBOSITY_NORMAL);
$output->write('<info>');
$output->write($password, OutputInterface::OUTPUT_RAW);
$output->writeln('</info>');
$output->setVerbosity($verbosity);
}
}
示例11: addError
/**
* @param string $message
* @param string $type
* @param string|null $index
* @param string|null $errorImportance
*/
public function addError($message, $type, $index = null, $errorImportance = null)
{
$error = new ValidationError($message, $type);
if (Validators::is($errorImportance, 'unicode:1..')) {
if (Validators::is($this->loggerChannel, 'unicode:1..')) {
$error->setAsLoggable($errorImportance, $this->loggerChannel);
}
}
if (Validators::is($index, 'unicode:1..')) {
$error->setIndex($index);
if (isset($this->errors[$index])) {
throw new ValidationErrorIndexAlreadyExistsException(sprintf('Validation Object already contains an Error with index "%s"', $index));
}
$this->errors[$index] = $error;
} else {
$this->errors[] = $error;
}
}
示例12: createComponentOptionsForm
protected function createComponentOptionsForm()
{
$form = new Form();
$form->setTranslator($this->translator->domain('options.form'));
$form->addText('blog_title', 'blogTitle.label', null, 255)->setRequired('blogTitle.messages.required');
$form->addText('blog_subtitle', 'blogSubtitle.label', null, 255);
$form->addText('copyright', 'copyright.label', null, 255)->setRequired('copyright.messages.required');
$form->addText('articles_per_page', 'articlesPerPage.label', null, 2)->setRequired('articlesPerPage.messages.required')->addRule(function ($input) {
if (Validators::is($input->value, 'numericint:1..')) {
return true;
}
return false;
}, 'articlesPerPage.messages.wrongInput');
$form->addText('google_analytics_measure_code', 'gaMeasureCode.label');
$form->addSubmit('save', 'save.caption');
$form->onSuccess[] = [$this, 'processForm'];
$form->addProtection();
if (!$this->authorizator->isAllowed($this->user, 'options', 'edit')) {
$form['save']->setDisabled();
}
$form->setDefaults($this->optionFacade->loadOptions());
return $form;
}
示例13: askInternalID
private function askInternalID(QuestionHelper $helper, InputInterface $input, OutputInterface $output)
{
$question = new Question('Internal ID: ');
$question->setValidator(function ($answer) {
if (!Validators::is(trim($answer), 'numericint:1..')) {
throw new \RuntimeException('The Internal ID must be positive integer number.');
}
return $answer;
});
$question->setMaxAttempts(null);
// unlimited number of attempts
return $helper->ask($input, $output, $question);
}
示例14: constructUrl
/**
* Constructs absolute URL from Request object.
* @param \Nette\Application\Request $appRequest
* @param \Nette\Http\Url $refUrl
* @throws \Nette\InvalidStateException
* @return string|NULL
*/
public function constructUrl(Request $appRequest, Url $refUrl)
{
// Module prefix not match.
if ($this->module && !Strings::startsWith($appRequest->getPresenterName(), $this->module)) {
return NULL;
}
$parameters = $appRequest->getParameters();
$url = $refUrl->getBaseUrl();
$urlStack = [];
// Module prefix.
$moduleFrags = explode(":", $appRequest->getPresenterName());
$moduleFrags = array_map('\\AdamStipak\\Support\\Inflector::spinalCase', $moduleFrags);
$resourceName = array_pop($moduleFrags);
$urlStack += $moduleFrags;
// Associations.
if (isset($parameters['associations']) && Validators::is($parameters['associations'], 'array')) {
$associations = $parameters['associations'];
unset($parameters['associations']);
foreach ($associations as $key => $value) {
$urlStack[] = $key;
$urlStack[] = $value;
}
}
// Resource.
$urlStack[] = $resourceName;
// Id.
if (isset($parameters['id']) && Validators::is($parameters['id'], 'scalar')) {
$urlStack[] = $parameters['id'];
unset($parameters['id']);
}
$url = $url . implode('/', $urlStack);
$sep = ini_get('arg_separator.input');
if (isset($parameters['query'])) {
$query = http_build_query($parameters['query'], '', $sep ? $sep[0] : '&');
if ($query != '') {
$url .= '?' . $query;
}
}
return $url;
}
示例15: checkQuality
/**
* Check value of quality
*
* @param int|string $quality
* @param string $type
*/
private function checkQuality($quality)
{
// quality must be number or percent
if (Validators::is($quality, 'string') && !Validators::isNumeric($quality)) {
$msg = sprintf('Quality has unexpected format, "%s" given.', $quality);
throw new InvalidArgumentException($msg);
}
// quality cannot be negative number
if ((int) $quality < 0) {
$msg = sprintf('Quality must be greater than 0, "%s" given.', $quality);
throw new InvalidArgumentException($msg);
}
}