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


PHP Validator::int方法代码示例

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


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

示例1: preprocessValue

 protected function preprocessValue(&$uid)
 {
     if (!Validator::int($uid)) {
         throw new InvalidArgumentException('uid', 'type_invalid');
     }
     $uid = (int) $uid;
 }
开发者ID:Tanklong,项目名称:openvj,代码行数:7,代码来源:UserUidResolver.php

示例2: getProductById

 /**
  * Display a selected resource.
  *
  * @return Response
  */
 public function getProductById($categoryId, $productId)
 {
     if (Validator::int()->min(0)->validate($categoryId) && Validator::int()->min(0)->validate($productId)) {
         $category = null;
         for ($i = 0; $i < count($this->json_content->collections) && $category == null; $i++) {
             if ($this->json_content->collections[$i]->id == $categoryId) {
                 $category = $this->json_content->collections[$i];
             }
         }
         if ($category != null) {
             $product = null;
             for ($i = 0; $i < count($category->skus) && $product == null; $i++) {
                 if ($category->skus[$i]->id == $productId) {
                     $product = $category->skus[$i];
                 }
             }
             if ($product != null) {
                 return response()->json(new SuccessResponse(array('category' => $category, 'product' => $product), 'Category and Product found'), 200);
             } else {
                 return response()->json(new DangerResponse(array('category' => $category, 'product' => $product), 'Product not found'), 200);
             }
         } else {
             return response()->json(new DangerResponse(array('category' => $category, 'product' => $product), 'Category and Product not found'), 200);
         }
     } else {
         return response()->json(new DangerResponse(array('category' => array()), 'Failed to get category and product'), 200);
     }
 }
开发者ID:sirCamp,项目名称:padawanTest,代码行数:33,代码来源:IndexController.php

示例3: createHolidayAction

 public function createHolidayAction()
 {
     $title = $this->app->request->post('title');
     $date = $this->app->request->post('date');
     $days = $this->app->request->post('days');
     $is_enabled = !empty($this->app->request->post('is_enabled')) ? true : false;
     $is_recurring = !empty($this->app->request->post('is_recurring')) ? true : false;
     $date = c::parse($date)->toDateString();
     $rules = array('title' => v::string()->notEmpty()->setName('title'), 'date' => v::date()->notEmpty()->setName('date'), 'days' => v::int()->notEmpty()->setName('days'), 'is_enabled' => v::bool()->setName('is_enabled'), 'is_recurring' => v::bool()->setName('is_recurring'));
     $data = $this->app->request->post();
     $data['date'] = $date;
     $data['is_enabled'] = $is_enabled;
     $data['is_recurring'] = $is_recurring;
     $message = array('type' => 'success', 'text' => 'Successfully added event');
     foreach ($data as $key => $value) {
         try {
             $rules[$key]->check($value);
         } catch (\InvalidArgumentException $e) {
             $message = array('type' => 'error', 'text' => $e->getMainMessage());
             break;
         }
     }
     $event = R::dispense('events');
     $event->title = $title;
     $event->date = $date;
     $event->days = $days;
     $event->is_enabled = $is_enabled;
     $event->is_recurring = $is_recurring;
     R::store($event);
     $this->app->flash('message', $message);
     $this->app->redirect('/');
 }
开发者ID:anchetaWern,项目名称:naughtyfire,代码行数:32,代码来源:Home.php

示例4: createRole

 /**
  * 创建一个角色
  *
  * @param string $name
  * @param bool $internal
  * @param \MongoId $domain
  * @param int $owner
  * @return bool
  * @throws InvalidArgumentException
  * @throws MissingArgumentException
  */
 public static function createRole($name, $internal = false, \MongoId $domain = null, $owner = null)
 {
     if (!is_string($name)) {
         throw new InvalidArgumentException('name', 'type_invalid');
     }
     if (!mb_check_encoding($name, 'UTF-8')) {
         throw new InvalidArgumentException('name', 'encoding_invalid');
     }
     if (!preg_match('/^\\$[0-9a-zA-Z_]{1,20}$/', $name)) {
         throw new InvalidArgumentException('name', 'format_invalid');
     }
     if (!$internal) {
         if ($domain === null) {
             throw new MissingArgumentException('domain');
         }
         if ($owner === null) {
             throw new MissingArgumentException('owner');
         }
         if (!Validator::int()->validate($owner)) {
             throw new InvalidArgumentException('owner', 'type_invalid');
         }
     }
     $name = strtoupper($name);
     if (!$internal) {
         $result = Application::coll('Role')->update(['domain' => $domain, 'name' => $name], ['$setOnInsert' => ['owner' => (int) $owner, 'at' => new \MongoDate()]], ['upsert' => true]);
     } else {
         $result = Application::coll('Role')->update(['internal' => true, 'name' => $name], [], ['upsert' => true]);
     }
     return $result['n'] === 1;
 }
开发者ID:Tanklong,项目名称:openvj,代码行数:41,代码来源:RoleManager.php

示例5: generate

 /**
  * 创建并返回一个 token
  *
  * @param string $purpose
  * @param string|null $identifier 唯一标识,为空则不需要
  * @param int $expireAt
  * @param mixed $data
  * @param int $length
  * @return array
  * @throws InvalidArgumentException
  * @throws \Exception
  * @throws \MongoException
  */
 public function generate($purpose, $identifier, $expireAt, $data = null, $length = 30)
 {
     if (!is_string($purpose)) {
         throw new InvalidArgumentException('purpose', 'type_invalid');
     }
     if (!mb_check_encoding($purpose, 'UTF-8')) {
         throw new InvalidArgumentException('purpose', 'encoding_invalid');
     }
     if (!Validator::int()->validate($expireAt)) {
         throw new InvalidArgumentException('expireAt', 'type_invalid');
     }
     $token = Application::get('random')->generateString($length, VJ::RANDOM_CHARS);
     try {
         if ($identifier !== null) {
             if (!is_string($identifier)) {
                 throw new InvalidArgumentException('identifier', 'type_invalid');
             }
             if (!mb_check_encoding($identifier, 'UTF-8')) {
                 throw new InvalidArgumentException('identifier', 'encoding_invalid');
             }
             $result = Application::coll('Token')->update(['purpose' => $purpose, 'identifier' => $identifier], ['$set' => ['token' => $token, 'expireat' => new \MongoDate($expireAt), 'data' => $data]], ['upsert' => true]);
             return ['token' => $token, 'update' => $result['updatedExisting']];
         } else {
             $result = Application::coll('Token')->insert(['purpose' => $purpose, 'identifier' => null, 'token' => $token, 'expireat' => new \MongoDate($expireAt), 'data' => $data]);
             return ['token' => $token];
         }
     } catch (\MongoException $ex) {
         if ($ex->getCode() === 12) {
             throw new InvalidArgumentException('data', 'encoding_invalid');
         } else {
             throw $ex;
         }
     }
 }
开发者ID:Tanklong,项目名称:openvj,代码行数:47,代码来源:TokenManager.php

示例6: createDiscussion

 /**
  * 创建主题
  *
  * @param \MongoId $topicId
  * @param int $owner
  * @param string title
  * @param string $markdown
  * @return array|null
  * @throws InvalidArgumentException
  * @throws UserException
  */
 public static function createDiscussion(\MongoId $topicId, $owner, $title, $markdown)
 {
     if (!Validator::int()->validate($owner)) {
         throw new InvalidArgumentException('owner', 'type_invalid');
     }
     if (!is_string($title)) {
         throw new InvalidArgumentException('markdown', 'type_invalid');
     }
     if (!mb_check_encoding($title, 'UTF-8')) {
         throw new InvalidArgumentException('markdown', 'encoding_invalid');
     }
     if (!is_string($markdown)) {
         throw new InvalidArgumentException('markdown', 'type_invalid');
     }
     if (!mb_check_encoding($markdown, 'UTF-8')) {
         throw new InvalidArgumentException('markdown', 'encoding_invalid');
     }
     if (!Validator::length(VJ::COMMENT_MIN, VJ::COMMENT_MAX)) {
         throw new UserException('DiscussionUtil.content_invalid_length');
     }
     self::initParser();
     $discussionId = new \MongoId();
     $html = self::$parser->parse($markdown);
     $keyword = KeywordFilter::isContainGeneric(strip_tags($html));
     if ($keyword !== false) {
         throw new UserException('DiscussionUtil.content_forbid', ['keyword' => $keyword]);
     }
     $doc = ['_id' => $discussionId, 'owner' => (int) $owner, 'topicId' => $topicId, 'at' => new \MongoDate(), 'title' => $title, 'raw' => $markdown, 'html' => $html];
     Application::coll('Discussion')->insert($doc);
     Application::emit('discussion.create.succeeded', [$topicId, $discussionId]);
     return ['_id' => $discussionId, 'html' => $html];
 }
开发者ID:Tanklong,项目名称:openvj,代码行数:43,代码来源:DiscussionUtil.php

示例7: joinDomainById

 /**
  * 加入域
  *
  * @param int $uid
  * @param \MongoId $domainId
  * @return bool
  * @throws InvalidArgumentException
  * @throws UserException
  */
 public function joinDomainById($uid, \MongoId $domainId)
 {
     if (!Validator::int()->validate($uid)) {
         throw new InvalidArgumentException('uid', 'type_invalid');
     }
     $uid = (int) $uid;
     if (!DomainUtil::isGlobalDomainId($domainId)) {
         // 检查域是否存在
         $d = Application::coll('Domain')->findOne(['_id' => $domainId]);
         if (!DomainUtil::isDomainObjectValid($d)) {
             throw new UserException('DomainManager.joinDomain.invalid_domain');
         }
     }
     // 检查用户是否存在
     $user = UserUtil::getUserObjectByUid($uid);
     if (!UserUtil::isUserObjectValid($user)) {
         throw new UserException('DomainManager.joinDomain.invalid_user');
     }
     // 添加 MEMBER 角色
     Application::coll('UserRole')->update(['uid' => $uid], ['$addToSet' => ['d.' . (string) $domainId => 'DOMAIN_MEMBER']], ['upsert' => true]);
     // 创建空资料
     $document = ['pref' => new \stdClass(), 'rp' => 0.0, 'rp_s' => 0.0, 'rank' => -1, 'level' => 0];
     if (DomainUtil::isGlobalDomainId($domainId)) {
         $document += ['sig' => '', 'sigraw' => '', 'contacts' => []];
     }
     Application::coll('UserInfo')->update(['uid' => $uid, 'domain' => new \MongoId(VJ::DOMAIN_GLOBAL)], ['$setOnInsert' => $document], ['upsert' => true]);
     // 操作非全局域则插入操作记录
     if (!DomainUtil::isGlobalDomainId($domainId)) {
         $doc = ['uid' => $this->session->getCurrentToken(), 'at' => new \MongoDate(), 'type' => 'join', 'ua' => $this->request->getUserAgent(), 'ip' => $this->request->getClientIp(), 'target_uid' => $uid, 'target_domain' => $domainId];
         Application::coll('DomainLog')->insert($doc);
     }
     return true;
 }
开发者ID:Tanklong,项目名称:openvj,代码行数:42,代码来源:DomainManager.php

示例8: getUserObjectByUid

 /**
  * @param int $uid
  * @return array|null
  */
 public static function getUserObjectByUid($uid)
 {
     if (!Validator::int()->validate($uid)) {
         return null;
     }
     $user = Application::coll('User')->findOne(['uid' => (int) $uid]);
     return $user;
 }
开发者ID:Tanklong,项目名称:openvj,代码行数:12,代码来源:UserUtil.php

示例9: assertIntBetween

 protected function assertIntBetween($fieldName, $start, $end, $parameter)
 {
     if (!v::int()->between($start, $end, true)->validate($parameter)) {
         $this->setValidationResponse(s::VALIDATION_ERROR, $fieldName, "is invalid");
         return false;
     }
     return true;
 }
开发者ID:marcoescudeiro,项目名称:erede-acquiring-php,代码行数:8,代码来源:TransactionCreditValidator.php

示例10: load

 function load()
 {
     if ($this->_view == 'node') {
         $this->_from = $this->get('s');
         $this->_node = $this->get('n');
         if (!$this->validateServerNode($this->_from, $this->_node)) {
             return;
         }
         $pd = new \Modl\ItemDAO();
         $this->_item = $pd->getItem($this->_from, $this->_node);
         $this->_mode = 'group';
         $this->url = Route::urlize('node', array($this->_from, $this->_node));
     } else {
         $this->_from = $this->get('f');
         $cd = new \modl\ContactDAO();
         $this->_contact = $cd->get($this->_from, true);
         if (filter_var($this->_from, FILTER_VALIDATE_EMAIL)) {
             $this->_node = 'urn:xmpp:microblog:0';
         } else {
             return;
         }
         $this->_mode = 'blog';
         $this->url = Route::urlize('blog', $this->_from);
     }
     $pd = new \modl\PostnDAO();
     if ($this->_id = $this->get('i')) {
         if (Validator::int()->between(0, 100)->validate($this->_id)) {
             $this->_messages = $pd->getNodeUnfiltered($this->_from, $this->_node, $this->_id * $this->_paging, $this->_paging + 1);
             $this->_page = $this->_id + 1;
         } elseif (Validator::string()->length(5, 100)->validate($this->_id)) {
             $this->_messages = $pd->getPublicItem($this->_from, $this->_node, $this->_id);
             if (is_object($this->_messages[0])) {
                 $this->title = $this->_messages[0]->title;
                 $description = stripTags($this->_messages[0]->contentcleaned);
                 if (!empty($description)) {
                     $this->description = $description;
                 }
                 $attachements = $this->_messages[0]->getAttachements();
                 if ($attachements && array_key_exists('pictures', $attachements)) {
                     $this->image = urldecode($attachements['pictures'][0]['href']);
                 }
             }
             if ($this->_view == 'node') {
                 $this->url = Route::urlize('node', array($this->_from, $this->_node, $this->_id));
             } else {
                 $this->url = Route::urlize('blog', array($this->_from, $this->_id));
             }
         }
     } else {
         $this->_page = 1;
         $this->_messages = $pd->getNodeUnfiltered($this->_from, $this->_node, 0, $this->_paging + 1);
     }
     if (count($this->_messages) == $this->_paging + 1) {
         array_pop($this->_messages);
     }
 }
开发者ID:vijo,项目名称:movim,代码行数:56,代码来源:Blog.php

示例11: overWriteToken

 /**
  * 在函数调用期间使用指定的 uid 作为权限控制主体的标识符
  *
  * @param int $uid
  * @param callable $callback
  * @throws InvalidArgumentException
  */
 public function overWriteToken($uid, callable $callback)
 {
     if (!Validator::int()->validate($uid)) {
         throw new InvalidArgumentException('uid', 'type_invalid');
     }
     $lastOverWrite = $this->{$overWriteUid};
     $this->{$overWriteUid} = $uid;
     $callback();
     $this->{$overWriteUid} = $lastOverWrite;
 }
开发者ID:Tanklong,项目名称:openvj,代码行数:17,代码来源:UserSession.php

示例12: validate

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

示例13: __construct

 /**
  * @param int|null $uid
  */
 public function __construct($uid = null)
 {
     if ($uid === null || !Validator::int()->validate($uid)) {
         $this->roles = [];
         return;
     }
     $data = Application::coll('UserRole')->findOne(['uid' => (int) $uid]);
     if ($data === null) {
         $this->roles = [];
         return;
     }
     $this->roles = $data['d'];
 }
开发者ID:Tanklong,项目名称:openvj,代码行数:16,代码来源:Role.php

示例14: validateId

 public function validateId($id, $name = 'ID')
 {
     $rules = v::int()->notEmpty()->setName($name);
     if ($rules->validate($id)) {
         return true;
     }
     try {
         $rules->check($id);
     } catch (ValidationExceptionInterface $exception) {
         $this->error = $exception->getMainMessage();
     }
     return false;
 }
开发者ID:alldigitalrewards,项目名称:marketplace,代码行数:13,代码来源:GenericTrait.php

示例15: __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')));
 }
开发者ID:ddelor,项目名称:gallery-wp-theme,代码行数:14,代码来源:FormTest.php


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