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


PHP Utility\Validator類代碼示例

本文整理匯總了PHP中Core\Helper\Utility\Validator的典型用法代碼示例。如果您正苦於以下問題:PHP Validator類的具體用法?PHP Validator怎麽用?PHP Validator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Validator類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: get

 public function get($f3)
 {
     global $smarty;
     // 首先做參數合法性驗證
     $validator = new Validator($f3->get('GET'));
     $goods_id = $validator->required('商品id不能為空')->digits('商品id非法')->min(1, true, '商品id非法')->validate('goods_id');
     $pageNo = $validator->digits()->min(0)->validate('pageNo');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     // 生成 smarty 的緩存 id
     $smartyCacheId = 'Goods|' . $goods_id . '|AjaxGoodsComment_' . $pageNo;
     // 開啟並設置 smarty 緩存時間
     enableSmartyCache(true, bzf_get_option_value('smarty_cache_time_goods_view'));
     if ($smarty->isCached('ajax_goodscomment.tpl', $smartyCacheId)) {
         goto out_display;
     }
     $this->preparePage($goods_id, $pageNo);
     out_display:
     $f3->expire(600);
     // 讓客戶端緩存 10 分鍾
     $smarty->display('ajax_goodscomment.tpl', $smartyCacheId);
     return;
     out_fail:
     // output nothing
     return;
 }
開發者ID:jackycgq,項目名稱:bzfshop,代碼行數:27,代碼來源:GoodsComment.php

示例2: ListAttrItem

 public function ListAttrItem($f3)
 {
     // 參數驗證
     $validator = new Validator($f3->get('GET'));
     $meta_id = $validator->required()->digits()->min(1)->validate('typeId');
     $errorMessage = '';
     if (!$this->validate($validator)) {
         $errorMessage = implode('|', $this->flashMessageArray);
         goto out_fail;
     }
     // 檢查緩存
     $cacheKey = md5(__FILE__ . '\\' . __METHOD__ . '\\' . $meta_id);
     $attrItemArray = $f3->get($cacheKey);
     if (!empty($attrItemArray)) {
         goto out;
     }
     $goodsTypeService = new GoodsTypeService();
     $attrItemArray = $goodsTypeService->fetchGoodsTypeAttrItemArray($meta_id);
     $f3->set($cacheKey, $attrItemArray, 300);
     //緩存 5 分鍾
     out:
     $f3->expire(60);
     // 客戶端緩存 1 分鍾
     Ajax::header();
     echo Ajax::buildResult(null, null, $attrItemArray);
     return;
     out_fail:
     Ajax::header();
     echo Ajax::buildResult(-1, $errorMessage, null);
 }
開發者ID:jackycgq,項目名稱:bzfshop,代碼行數:30,代碼來源:GoodsType.php

示例3: getRequestUrl

 public function getRequestUrl($orderId, $returnUrl, $notifyUrl)
 {
     // 參數驗證
     $validator = new Validator(array('orderId' => $orderId, 'returnUrl' => $returnUrl, 'notifyUrl' => $notifyUrl));
     $orderId = $validator->required()->digits()->min(1)->validate('orderId');
     $returnUrl = $validator->required()->validate('returnUrl');
     $notifyUrl = $validator->required()->validate('notifyUrl');
     $this->validate($validator);
     //設置訂單 ID
     $this->orderId = $orderId;
     // 取得訂單
     $orderBasicService = new OrderBasicService();
     $orderInfo = $orderBasicService->loadOrderInfoById($orderId);
     if (empty($orderInfo) || $orderInfo->isEmpty()) {
         throw new \InvalidArgumentException('invalid order_id [' . $orderId . ']');
     }
     $desc = $orderInfo['order_id'] . '|' . Money::toSmartyDisplay($orderInfo['order_amount']) . '|' . $orderInfo['system_id'] . '|WAP';
     // 構造要請求的參數數組,無需改動
     $parameterCreate = array("req_data" => '<direct_trade_create_req><subject>' . $desc . '</subject><out_trade_no>' . $orderInfo['order_sn'] . '_' . $orderInfo['order_id'] . '</out_trade_no><total_fee>' . Money::toDisplay($orderInfo['order_amount'], 2) . "</total_fee><seller_account_name>" . $this->account . "</seller_account_name><notify_url>" . $notifyUrl . "</notify_url><out_user>" . $orderInfo['user_id'] . "</out_user><merchant_url></merchant_url>" . "<call_back_url>" . $returnUrl . "</call_back_url></direct_trade_create_req>", "service" => $this->configServiceCreate, "sec_id" => $this->configSecId, "partner" => $this->partnerId, "req_id" => date("Ymdhms"), "format" => $this->configFormat, "v" => $this->configVersion);
     // 首先申請 Token
     $result = $this->callAlipayWapGateway($this->buildRequestLinkData($parameterCreate));
     // 調用GetToken方法,並返回token
     $token = $this->getToken($result);
     if (!$token) {
         printLog($this->getGatewayType() . ' 獲取 token 失敗');
         return null;
     }
     // 構造要請求的參數數組,無需改動
     $parameterExecute = array("req_data" => "<auth_and_execute_req><request_token>" . $token . "</request_token></auth_and_execute_req>", "service" => $this->configServiceExecute, "sec_id" => $this->configSecId, "partner" => $this->partnerId, "call_back_url" => $returnUrl, "format" => $this->configFormat, "v" => $this->configVersion);
     return $this->configGateway . $this->buildRequestLinkData($parameterExecute);
 }
開發者ID:swcug,項目名稱:bzfshop,代碼行數:31,代碼來源:Gateway.php

示例4: GalleryThumb

 /**
  * 根據 goods_id 得到一個商品的圖片集
  *
  * @param $f3
  */
 public function GalleryThumb($f3)
 {
     // 參數驗證
     $validator = new Validator($f3->get('GET'));
     $errorMessage = '';
     $goods_id = $validator->required()->digits()->min(1)->filter('ValidatorIntValue')->validate('goods_id');
     if (!$this->validate($validator)) {
         $errorMessage = implode('|', $this->flashMessageArray);
         goto out_fail;
     }
     $goodsGalleryService = new GoodsGalleryService();
     $galleryArray = $goodsGalleryService->fetchGoodsGalleryArrayByGoodsId($goods_id);
     $thumImageList = array();
     foreach ($galleryArray as $galleryItem) {
         $thumImageList[] = array('img_id' => $galleryItem['img_id'], 'thumb_url' => RouteHelper::makeImageUrl($galleryItem['thumb_url']));
     }
     out:
     Ajax::header();
     echo Ajax::buildResult(null, null, $thumImageList);
     return;
     out_fail:
     // 失敗,返回出錯信息
     Ajax::header();
     echo Ajax::buildResult(-1, $errorMessage, null);
 }
開發者ID:jackycgq,項目名稱:bzfshop,代碼行數:30,代碼來源:Goods.php

示例5: countGoodsLogArray

 public function countGoodsLogArray($goods_id, $ttl = 0)
 {
     // 參數驗證
     $validator = new Validator(array('goods_id' => $goods_id));
     $goods_id = $validator->required()->digits()->min(1)->validate('goods_id');
     $this->validate($validator);
     return $this->_countArray('goods_log', array(array('goods_id = ?', $goods_id)), null, $ttl);
 }
開發者ID:swcug,項目名稱:bzfshop,代碼行數:8,代碼來源:Log.php

示例6: loadGoodsAttrGroupByName

 /**
  * 根據組名取得商品屬性組
  *
  * @param string $groupName
  *
  * @return \Core\Modal\SqlMapper
  */
 public function loadGoodsAttrGroupByName($groupName)
 {
     // 參數驗證
     $validator = new Validator(array('groupName' => $groupName));
     $groupName = $validator->required()->validate('groupName');
     $this->validate($validator);
     return $this->loadMetaByTypeAndName(GoodsAttrGroup::META_TYPE, $groupName);
 }
開發者ID:jackycgq,項目名稱:bzfshop,代碼行數:15,代碼來源:GoodsAttrGroup.php

示例7: countOrderSettleArray

 /**
  *
  * 取得一組記錄的數目,用於分頁
  *
  * @return int 查詢條數
  *
  * @param array $condArray 查詢條件數組,例如:
  *                         array(
  *                         array('supplier_id = ?', $supplier_id)
  *                         array('is_on_sale = ?', 1)
  *                         array('create_time > ? or create_time < ?', $timeMin, $timeMax)
  * )
  *
  * @param int   $ttl       緩存多少時間
  *
  */
 public function countOrderSettleArray(array $condArray, $ttl = 0)
 {
     // 參數驗證
     $validator = new Validator(array('condArray' => $condArray), '');
     $condArray = $validator->requireArray(true)->validate('condArray');
     $this->validate($validator);
     return $this->_countArray('order_settle', $condArray, null, $ttl);
 }
開發者ID:jackycgq,項目名稱:bzfshop,代碼行數:24,代碼來源:Settle.php

示例8: ListChildTreeNodeAllStr

 public function ListChildTreeNodeAllStr($f3)
 {
     // 參數驗證
     $validator = new Validator($f3->get('GET'));
     $errorMessage = '';
     $treeKey = $validator->required()->validate('treeKey');
     $parentId = $validator->digits()->min(0)->validate('parentId');
     $parentId = $parentId ?: 0;
     // 用戶也可以通過 treeNodeName 來做查詢
     $treeNodeName = $validator->validate('treeNodeName');
     if (!$this->validate($validator)) {
         $errorMessage = implode('|', $this->flashMessageArray);
         goto out_fail;
     }
     // 檢查緩存
     $cacheKey = md5(__NAMESPACE__ . '\\' . __CLASS__ . '\\' . __METHOD__ . '\\' . $treeKey . '\\' . $parentId . '\\' . $treeNodeName);
     $outputArray = $f3->get($cacheKey);
     if (!empty($outputArray)) {
         goto out;
     }
     $metaTreeService = new MetaTreeService();
     if (!empty($treeNodeName)) {
         $treeNode = $metaTreeService->loadTreeNodeWithTreeKeyAndName($treeKey, $treeNodeName);
         if (!$treeNode->isEmpty()) {
             $parentId = $treeNode['meta_id'];
         }
     }
     // 取得樹形的層級結構
     $treeNodeArray = $metaTreeService->fetchChildTreeNodeArrayAll($treeKey, $parentId);
     // 構建顯示輸出
     $outputArray = array();
     function buildHierarchyArray(&$outputArray, $treeNodeArray, $separator = '')
     {
         $hierarchySeparator = '---------->';
         foreach ($treeNodeArray as $treeNodeItem) {
             $outputItem = array();
             $outputItem['meta_id'] = $treeNodeItem['meta_id'];
             $outputItem['meta_name'] = $treeNodeItem['meta_name'];
             $outputItem['display_text'] = $separator . $treeNodeItem['meta_name'];
             $outputArray[] = $outputItem;
             // 有子節點,遞歸建立子節點
             if (isset($treeNodeItem['child_list'])) {
                 buildHierarchyArray($outputArray, $treeNodeItem['child_list'], $separator . $hierarchySeparator);
             }
         }
     }
     buildHierarchyArray($outputArray, $treeNodeArray, '');
     $f3->set($cacheKey, $outputArray, 600);
     //緩存 10 分鍾
     out:
     Ajax::header();
     echo Ajax::buildResult(null, null, $outputArray);
     return;
     out_fail:
     // 失敗,返回出錯信息
     Ajax::header();
     echo Ajax::buildResult(-1, $errorMessage, null);
 }
開發者ID:jackycgq,項目名稱:bzfshop,代碼行數:58,代碼來源:Tree.php

示例9: get

 public function get($f3)
 {
     global $smarty;
     // 首先做參數合法性驗證
     $validator = new Validator($f3->get('GET'));
     $goods_id = $validator->required('商品id不能為空')->digits('商品id非法')->min(1, true, '商品id非法')->validate('goods_id');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     // 生成 smarty 的緩存 id
     $smartyCacheId = 'Goods|' . $goods_id . '|View';
     // 開啟並設置 smarty 緩存時間
     enableSmartyCache(true, MobileThemePlugin::getOptionValue('smarty_cache_time_goods_view'));
     // 緩存頁麵
     if ($smarty->isCached('goods_view.tpl', $smartyCacheId)) {
         goto out_display;
     }
     // 查詢商品信息
     $goodsBasicService = new GoodsBasicService();
     $goodsInfo = $goodsBasicService->loadGoodsById($goods_id);
     // 商品不存在,退出
     if ($goodsInfo->isEmpty() || !Utils::isTagExist(PluginHelper::SYSTEM_MOBILE, $goodsInfo['system_tag_list'])) {
         $this->addFlashMessage('商品 [' . $goods_id . '] 不存在');
         goto out_fail;
     }
     // 取商品推廣信息設置
     $goodsPromote = $goodsBasicService->loadGoodsPromoteByGoodsId($goods_id);
     // 取商品圖片集
     $goodsGalleryArray = GoodsGalleryCache::getGoodsGallery($goods_id);
     foreach ($goodsGalleryArray as &$galleryItem) {
         $galleryItem['img_url'] = RouteHelper::makeImageUrl($galleryItem['img_url']);
         $galleryItem['thumb_url'] = RouteHelper::makeImageUrl($galleryItem['thumb_url']);
     }
     unset($galleryItem);
     // 設置商品頁麵的 SEO 信息
     $smarty->assign('seo_title', $goodsInfo['seo_title'] . ',' . $f3->get('sysConfig[site_name]'));
     $smarty->assign('seo_description', $goodsInfo['seo_description']);
     $smarty->assign('seo_keywords', $goodsInfo['seo_keyword']);
     // 給模板賦值
     $smarty->assign('goodsInfo', $goodsInfo);
     $smarty->assign('goodsPromote', $goodsPromote);
     if (!Utils::isEmpty($goodsGalleryArray)) {
         $smarty->assign('goodsGalleryArray', $goodsGalleryArray);
     }
     // 設置商品規格
     if (!empty($goodsInfo['goods_spec'])) {
         $goodsSpecService = new GoodsSpecService();
         $goodsSpecService->initWithJson($goodsInfo['goods_spec']);
         $smarty->assign('goodsSpec', $goodsSpecService->getGoodsSpecDataArray());
     }
     out_display:
     $smarty->display('goods_view.tpl', $smartyCacheId);
     return;
     out_fail:
     // 失敗從這裏返回
     RouteHelper::reRoute($this, '/');
     // 返回首頁
 }
開發者ID:jackycgq,項目名稱:bzfshop,代碼行數:58,代碼來源:View.php

示例10: countSupplierGoodsArray

 /**
  * 取得供貨商下麵商品的總數,用於分頁顯示
  *
  * @return int 商品總數
  *
  * @param int $suppliers_id 供貨商的ID
  * @param int $ttl          緩存時間
  */
 public function countSupplierGoodsArray($suppliers_id, $ttl = 0)
 {
     // 參數驗證
     $validator = new Validator(array('suppliers_id' => $suppliers_id, 'ttl' => $ttl));
     $suppliers_id = $validator->required()->digits()->min(1)->validate('suppliers_id');
     $ttl = $validator->digits()->min(0)->validate('ttl');
     $this->validate($validator);
     return $this->_countArray('goods', array(array('suppliers_id = ? AND is_delete = 0 AND is_on_sale = 1 AND is_alone_sale = 1', $suppliers_id)), null, $ttl);
 }
開發者ID:jackycgq,項目名稱:bzfshop,代碼行數:17,代碼來源:Supplier.php

示例11: post

 public function post($f3)
 {
     global $smarty;
     // 首先做參數合法性驗證
     $validator = new Validator($f3->get('POST'));
     $input = array();
     $input['user_name'] = $validator->required('用戶名不能為空')->validate('user_name');
     $input['password'] = $validator->required('密碼不能為空')->validate('password');
     $p_captcha = $validator->required('驗證碼不能為空')->validate('captcha');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     // 檢查驗證碼是否有效
     $captchaController = new \Controller\Image\Captcha();
     if (!$captchaController->validateCaptcha($p_captcha)) {
         $this->addFlashMessage("驗證碼錯誤");
         goto out_fail;
     }
     $adminService = new AdminUserService();
     // 驗證用戶登陸
     $admin = $adminService->doAuthAdmin($input['user_name'], $input['user_name'], $input['password']);
     if (!$admin) {
         $this->addFlashMessage("登陸失敗,用戶名、密碼錯誤");
         goto out_fail;
     }
     // 記錄用戶的登陸信息
     $adminUserInfo = $admin->toArray();
     unset($adminUserInfo['password']);
     // 不要記錄密碼
     // 取得用戶的角色權限
     $adminUserInfo['role_action_list'] = '';
     if ($adminUserInfo['role_id'] > 0) {
         $metaRoleService = new MetaRoleService();
         $role = $metaRoleService->loadRoleById($adminUserInfo['role_id']);
         if (!$role->isEmpty()) {
             // 賦值角色權限
             $adminUserInfo['role_action_list'] = $role['meta_data'];
         }
     }
     AuthHelper::saveAuthUser($adminUserInfo);
     try {
         // 記錄用戶登錄日誌
         AdminLog::logAdminOperate('user.login', '用戶登錄', 'IP:' . $f3->get('IP'));
     } catch (\Exception $e) {
         // do nothing
     }
     $this->addFlashMessage("登陸成功");
     // 跳轉到用戶之前看的頁麵,如果之前沒有看過的頁麵那就回到首頁
     RouteHelper::jumpBack($this, '/', true);
     return;
     // 這裏正常返回
     out_fail:
     // 失敗從這裏入口
     $smarty->display('user_login.tpl', 'User|Login|post');
 }
開發者ID:swcug,項目名稱:bzfshop,代碼行數:55,代碼來源:Login.php

示例12: fetchGoodsGalleryArrayByGoodsIdArray

 /**
  * 給出一組商品 ID,取得所有商品的圖片,
  * 這是一個大查詢,可能會很多數據,之所以加這個大查詢的目的是,
  * 我們寧可要一個幾百條記錄的大查詢,也不要幾百個一條記錄的小查詢
  *
  * @return array  圖像集合 array(array(圖片1), array(圖片2))
  *
  * @param array $goodsIdArray 商品的 ID 數組
  * @param int   $ttl          緩存時間
  */
 public function fetchGoodsGalleryArrayByGoodsIdArray(array $goodsIdArray, $ttl = 0)
 {
     if (!is_array($goodsIdArray) || empty($goodsIdArray)) {
         throw new \InvalidArgumentException('goodsIdArray must be an array not empty');
     }
     // 參數驗證
     $validator = new Validator(array('ttl' => $ttl));
     $ttl = $validator->digits()->min(0)->validate('ttl');
     $this->validate($validator);
     $dataMapper = new DataMapper('goods_gallery');
     $sqlInClause = QueryBuilder::buildInCondition('goods_id', $goodsIdArray, \PDO::PARAM_INT);
     return $dataMapper->find(array($sqlInClause), array('order' => 'goods_id asc , img_sort_order desc, img_id asc'), $ttl);
 }
開發者ID:swcug,項目名稱:bzfshop,代碼行數:23,代碼來源:Gallery.php

示例13: isOrderGoodsCommentExist

 /**
  * 檢查 order_goods 對應的評論記錄是否已經存在
  *
  * @param int $rec_id
  *
  * @return bool
  */
 public function isOrderGoodsCommentExist($rec_id)
 {
     if (!$rec_id) {
         return false;
     }
     // 參數驗證
     $validator = new Validator(array('rec_id' => $rec_id));
     $rec_id = $validator->required()->digits()->min(1)->validate('rec_id');
     $this->validate($validator);
     $dataMapper = new DataMapper('goods_comment');
     $dataMapper->loadOne(array('rec_id = ?', $rec_id), null, 0);
     return !$dataMapper->isEmpty();
 }
開發者ID:jackycgq,項目名稱:bzfshop,代碼行數:20,代碼來源:Comment.php

示例14: validate

 /**
  * 驗證是否有失敗的 validate,失敗的 validate 對應的消息會自動被添加到 flash message 中
  *
  * @return boolean
  *
  * @param object $validator  validator 對象
  * */
 protected function validate(Validator $validator)
 {
     $hasError = $validator->hasErrors();
     if (!$hasError) {
         // 沒有錯誤,成功返回
         return true;
     }
     // 有錯誤,把錯誤消息放入到 flash Message 中
     $errorArray = $validator->getAllErrors();
     foreach ($errorArray as $errorField => $errorMsg) {
         $this->addFlashMessage($errorMsg);
     }
     return false;
 }
開發者ID:jackycgq,項目名稱:bzfshop,代碼行數:21,代碼來源:BaseController.php

示例15: getRequestUrl

 public function getRequestUrl($orderId, $returnUrl, $notifyUrl)
 {
     // 參數驗證
     $validator = new Validator(array('orderId' => $orderId, 'returnUrl' => $returnUrl));
     $orderId = $validator->required()->digits()->min(1)->validate('orderId');
     $returnUrl = $validator->required()->validate('returnUrl');
     $this->validate($validator);
     $this->orderId = $orderId;
     //設置訂單 ID
     // 自己調用 notify 完成訂單支付
     $this->doNotifyUrl(null);
     return $returnUrl . '?order_id=' . $orderId;
     //返回 returnUrl
 }
開發者ID:jackycgq,項目名稱:bzfshop,代碼行數:14,代碼來源:CreditGateway.php


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