當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Validators::is方法代碼示例

本文整理匯總了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
     }
 }
開發者ID:blitzik,項目名稱:CMS,代碼行數:35,代碼來源:Authorizator.php

示例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)));
     }
 }
開發者ID:blitzik,項目名稱:CMS,代碼行數:31,代碼來源:AppEventLogger.php

示例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();
 }
開發者ID:blitzik,項目名稱:CMS,代碼行數:9,代碼來源:VisualPaginator.php

示例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.');
         }
     }
 }
開發者ID:blitzik,項目名稱:vycetky,代碼行數:17,代碼來源:Listing.php

示例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);
 }
開發者ID:blitzik,項目名稱:vycetky-doctrine,代碼行數:14,代碼來源:AccountPresenter.php

示例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.');
         }
     }
 }
開發者ID:blitzik,項目名稱:vycetky,代碼行數:17,代碼來源:UserMessage.php

示例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.');
         }
     }
 }
開發者ID:blitzik,項目名稱:vycetky,代碼行數:17,代碼來源:Message.php

示例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;
 }
開發者ID:blitzik,項目名稱:vycetky,代碼行數:19,代碼來源:BaseFacade.php

示例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;
 }
開發者ID:lucien144,項目名稱:Restful,代碼行數:26,代碼來源:Validator.php

示例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);
     }
 }
開發者ID:rixxi,項目名稱:user,代碼行數:46,代碼來源:CreateCommand.php

示例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;
     }
 }
開發者ID:blitzik,項目名稱:CMS,代碼行數:24,代碼來源:ValidationObject.php

示例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;
 }
開發者ID:blitzik,項目名稱:CMS,代碼行數:23,代碼來源:OptionsFormControl.php

示例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);
 }
開發者ID:blitzik,項目名稱:CMS,代碼行數:13,代碼來源:NewUrlCommand.php

示例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;
 }
開發者ID:newPOPE,項目名稱:Nette-RestRoute,代碼行數:47,代碼來源:RestRoute.php

示例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);
     }
 }
開發者ID:lawondyss,項目名稱:imager,代碼行數:19,代碼來源:Image.php


注:本文中的Nette\Utils\Validators::is方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。