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


PHP Terminus::get_cache方法代码示例

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


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

示例1: request

 /**
  * Make a request to the Pantheon API
  *
  * @param [string] $realm   Permissions realm for data request (e.g. user,
  *   site organization, etc. Can also be "public" to simply pull read-only
  *   data that is not privileged.
  * @param [string] $uuid    The UUID of the item in the realm to access
  * @param [string] $path    API path (URL)
  * @param [string] $method  HTTP method to use
  * @param [mixed]  $options A native PHP data structure (e.g. int, string,
  *   array, or stdClass) to be sent along with the request
  * @return [array] $data
  */
 public static function request($realm, $uuid, $path = false, $method = 'GET', $options = null)
 {
     if (!in_array($realm, array('login', 'user', 'public'))) {
         Auth::loggedIn();
     }
     try {
         $cache = Terminus::get_cache();
         if (!in_array($realm, array('login', 'user'))) {
             $options['cookies'] = array('X-Pantheon-Session' => Session::getValue('session'));
             $options['verify'] = false;
         }
         $url = Endpoint::get(array('realm' => $realm, 'uuid' => $uuid, 'path' => $path));
         if (Terminus::get_config('debug')) {
             Logger::debug('Request URL: ' . $url);
         }
         $resp = Request::send($url, $method, $options);
         $json = $resp->getBody(true);
         $data = array('info' => $resp->getInfo(), 'headers' => $resp->getRawHeaders(), 'json' => $json, 'data' => json_decode($json), 'status_code' => $resp->getStatusCode());
         return $data;
     } catch (Guzzle\Http\Exception\BadResponseException $e) {
         $response = $e->getResponse();
         \Terminus::error("%s", $response->getBody(true));
     } catch (Guzzle\Http\Exception\HttpException $e) {
         $request = $e->getRequest();
         $sanitized_request = TerminusCommand::stripSensitiveData((string) $request, TerminusCommand::$blacklist);
         \Terminus::error('Request %s had failed: %s', array($sanitized_request, $e->getMessage()));
     } catch (Exception $e) {
         \Terminus::error('Unrecognised request failure: %s', $e->getMessage());
     }
 }
开发者ID:newtoid,项目名称:cli,代码行数:43,代码来源:class-terminus-command.php

示例2: request

 /**
  * Make a request to the Dashbord's internal API.
  *
  * @param $realm
  *    Permissions realm for data request: currently "user" or "site" but in the
  *    future this could also be "organization" or another high-level business
  *    object (e.g. "product" for managing your app). Can also be "public" to
  *    simply pull read-only data that is not privileged.
  *
  * @param $uuid
  *    The UUID of the item in the realm you want to access.
  *
  * @param $method
  *    HTTP method (verb) to use.
  *
  * @param $data
  *    A native PHP data structure (int, string, arary or simple object) to be
  *    sent along with the request. Will be encoded as JSON for you.
  */
 public static function request($realm, $uuid, $path = FALSE, $method = 'GET', $options = NULL)
 {
     if (!in_array($realm, array('login', 'user', 'public')) and !Terminus::is_test()) {
         Auth::loggedIn();
     }
     try {
         $cache = Terminus::get_cache();
         // combine session realm uuid and path to get a unique key
         // @todo need cache "groups"
         $cachekey = md5(Session::getValue('user_uuid') . $uuid . $realm . $path);
         $data = $cache->get_data($cachekey);
         // check the request cache
         if ("GET" == $method and !Terminus::get_config('nocache') and !getenv('CLI_TEST_MODE') and !empty($data)) {
             if (Terminus::get_config('debug')) {
                 Logger::debug('CacheKey: ' . $cachekey);
             }
             return (array) $data;
         }
         // for some methods we'll assume the cache should be invalidated
         if (in_array($method, array("POST", "PUT", "DELETE"))) {
             $cache->flush(null, 'session');
         }
         if (!in_array($realm, array('login', 'user'))) {
             $options['cookies'] = array('X-Pantheon-Session' => Session::getValue('session'));
             $options['verify'] = false;
         }
         $url = Endpoint::get(array('realm' => $realm, 'uuid' => $uuid, 'path' => $path));
         if (Terminus::get_config('debug')) {
             Logger::debug('Request URL: ' . $url);
         }
         $resp = Request::send($url, $method, $options);
         $json = $resp->getBody(TRUE);
         $data = array('info' => $resp->getInfo(), 'headers' => $resp->getRawHeaders(), 'json' => $json, 'data' => json_decode($json), 'status_code' => $resp->getStatusCode());
         $cache->put_data($cachekey, $data);
         return $data;
     } catch (Guzzle\Http\Exception\BadResponseException $e) {
         $response = $e->getResponse();
         \Terminus::error("%s", $response->getBody(TRUE));
     } catch (Guzzle\Http\Exception\HttpException $e) {
         $request = $e->getRequest();
         //die(Terminus_Command::stripSensitiveData());
         $sanitized_request = Terminus_Command::stripSensitiveData((string) $request, Terminus_Command::$_blacklist);
         \Terminus::error("Request %s had failed: %s", array($sanitized_request, $e->getMessage()));
     } catch (Exception $e) {
         \Terminus::error("Unrecognised request failure: %s", $e->getMessage());
     }
 }
开发者ID:xwp,项目名称:pantheon-cli,代码行数:66,代码来源:class-terminus-command.php

示例3: environments

 /**
  * Return all environments for a site
  */
 public function environments()
 {
     $cache = \Terminus::get_cache();
     if (empty($this->environments)) {
         if (!($environments = $cache->get_data("environments:{$this->id}"))) {
             $results = \Terminus_Command::request("sites", $this->getId(), "environments", "GET");
             $environments = $results['data'];
             $cache->put_data("environments:{$this->id}", $environments);
         }
         $this->environments = $environments;
     }
     // instantiate local objects
     foreach ($this->environments as $name => $env) {
         $this->environments->{$name} = EnvironmentFactory::load($this, $name, array('hydrate_with' => $env));
     }
     return $this->environments;
 }
开发者ID:xwp,项目名称:pantheon-cli,代码行数:20,代码来源:Site.php


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