当前位置: 首页>>代码示例>>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;未经允许,请勿转载。