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


PHP Utils::isPositive方法代碼示例

本文整理匯總了PHP中Grav\Common\Utils::isPositive方法的典型用法代碼示例。如果您正苦於以下問題:PHP Utils::isPositive方法的具體用法?PHP Utils::isPositive怎麽用?PHP Utils::isPositive使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Grav\Common\Utils的用法示例。


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

示例1: onFormProcessed

 /**
  * Handle form processing instructions.
  *
  * @param Event $event
  */
 public function onFormProcessed(Event $event)
 {
     $form = $event['form'];
     $action = $event['action'];
     $params = $event['params'];
     $this->process($form);
     switch ($action) {
         case 'captcha':
             if (isset($params['recaptcha_secret'])) {
                 $recaptchaSecret = $params['recaptcha_secret'];
             } else {
                 if (isset($params['recatpcha_secret'])) {
                     // Included for backwards compatibility with typo (issue #51)
                     $recaptchaSecret = $params['recatpcha_secret'];
                 } else {
                     $recaptchaSecret = $this->config->get('plugins.form.recaptcha.secret_key');
                 }
             }
             // Validate the captcha
             $query = http_build_query(['secret' => $recaptchaSecret, 'response' => $form->value('g-recaptcha-response', true)]);
             $url = 'https://www.google.com/recaptcha/api/siteverify?' . $query;
             $response = json_decode(file_get_contents($url), true);
             if (!isset($response['success']) || $response['success'] !== true) {
                 $this->grav->fireEvent('onFormValidationError', new Event(['form' => $form, 'message' => $this->grav['language']->translate('PLUGIN_FORM.ERROR_VALIDATING_CAPTCHA')]));
                 $event->stopPropagation();
                 return;
             }
             break;
         case 'ip':
             $label = isset($params['label']) ? $params['label'] : 'User IP';
             $blueprint = $form->value()->blueprints();
             $blueprint->set('form/fields/ip', ['name' => 'ip', 'label' => $label]);
             $form->setFields($blueprint->fields());
             $form->setData('ip', Uri::ip());
             break;
         case 'message':
             $translated_string = $this->grav['language']->translate($params);
             $vars = array('form' => $form);
             /** @var Twig $twig */
             $twig = $this->grav['twig'];
             $processed_string = $twig->processString($translated_string, $vars);
             $form->message = $processed_string;
             break;
         case 'redirect':
             $this->grav['session']->setFlashObject('form', $form);
             $this->grav->redirect((string) $params);
             break;
         case 'reset':
             if (Utils::isPositive($params)) {
                 $form->reset();
             }
             break;
         case 'display':
             $route = (string) $params;
             if (!$route || $route[0] != '/') {
                 /** @var Uri $uri */
                 $uri = $this->grav['uri'];
                 $route = rtrim($uri->route(), '/') . '/' . ($route ?: '');
             }
             /** @var Twig $twig */
             $twig = $this->grav['twig'];
             $twig->twig_vars['form'] = $form;
             /** @var Pages $pages */
             $pages = $this->grav['pages'];
             $page = $pages->dispatch($route, true);
             if (!$page) {
                 throw new \RuntimeException('Display page not found. Please check the page exists.', 400);
             }
             unset($this->grav['page']);
             $this->grav['page'] = $page;
             break;
         case 'save':
             $prefix = !empty($params['fileprefix']) ? $params['fileprefix'] : '';
             $format = !empty($params['dateformat']) ? $params['dateformat'] : 'Ymd-His-u';
             $ext = !empty($params['extension']) ? '.' . trim($params['extension'], '.') : '.txt';
             $filename = !empty($params['filename']) ? $params['filename'] : '';
             $operation = !empty($params['operation']) ? $params['operation'] : 'create';
             if (!$filename) {
                 $filename = $prefix . $this->udate($format) . $ext;
             }
             /** @var Twig $twig */
             $twig = $this->grav['twig'];
             $vars = ['form' => $form];
             // Process with Twig
             $filename = $twig->processString($filename, $vars);
             $locator = $this->grav['locator'];
             $path = $locator->findResource('user://data', true);
             $dir = $path . DS . $form->name();
             $fullFileName = $dir . DS . $filename;
             $file = File::instance($fullFileName);
             if ($operation == 'create') {
                 $body = $twig->processString(!empty($params['body']) ? $params['body'] : '{% include "forms/data.txt.twig" %}', $vars);
                 $file->save($body);
             } elseif ($operation == 'add') {
                 if (!empty($params['body'])) {
//.........這裏部分代碼省略.........
開發者ID:getgrav,項目名稱:grav-plugin-form,代碼行數:101,代碼來源:form.php

示例2: authorize

 /**
  * Checks user authorization to the action.
  *
  * @param  string  $action
  * @return bool
  */
 public function authorize($action)
 {
     if (empty($this->items)) {
         return false;
     }
     return Utils::isPositive($this->get("access.{$action}"));
 }
開發者ID:realitygaps,項目名稱:grav_ynh,代碼行數:13,代碼來源:User.php

示例3: authorize

 /**
  * Checks user authorization to the action.
  *
  * @param  string  $action
  * @return bool
  */
 public function authorize($action)
 {
     if (empty($this->items)) {
         return false;
     }
     if (isset($this->state) && $this->state !== 'enabled') {
         return false;
     }
     return Utils::isPositive($this->get("access.{$action}"));
 }
開發者ID:krsreenatha,項目名稱:grav,代碼行數:16,代碼來源:User.php

示例4: authorize

 /**
  * Checks user authorization to the action.
  *
  * @param  string $action
  *
  * @return bool
  */
 public function authorize($action)
 {
     if (empty($this->items)) {
         return false;
     }
     if (isset($this->state) && $this->state !== 'enabled') {
         return false;
     }
     $return = false;
     //Check group access level
     $groups = $this->get('groups');
     if ($groups) {
         foreach ((array) $groups as $group) {
             $permission = self::getGrav()['config']->get("groups.{$group}.access.{$action}");
             $return = Utils::isPositive($permission);
             if ($return === true) {
                 break;
             }
         }
     }
     //Check user access level
     if ($this->get('access')) {
         if (Utils::resolve($this->get('access'), $action) !== null) {
             $permission = $this->get("access.{$action}");
             $return = Utils::isPositive($permission);
         }
     }
     return $return;
 }
開發者ID:jeremycherfas,項目名稱:grav-blog,代碼行數:36,代碼來源:User.php

示例5: testIsPositive

 public function testIsPositive()
 {
     $this->assertTrue(Utils::isPositive(true));
     $this->assertTrue(Utils::isPositive(1));
     $this->assertTrue(Utils::isPositive('1'));
     $this->assertTrue(Utils::isPositive('yes'));
     $this->assertTrue(Utils::isPositive('on'));
     $this->assertTrue(Utils::isPositive('true'));
     $this->assertFalse(Utils::isPositive(false));
     $this->assertFalse(Utils::isPositive(0));
     $this->assertFalse(Utils::isPositive('0'));
     $this->assertFalse(Utils::isPositive('no'));
     $this->assertFalse(Utils::isPositive('off'));
     $this->assertFalse(Utils::isPositive('false'));
     $this->assertFalse(Utils::isPositive('some'));
     $this->assertFalse(Utils::isPositive(2));
 }
開發者ID:getgrav,項目名稱:grav,代碼行數:17,代碼來源:UtilsTest.php


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