Beispiel #1
0
 /**
  * @param string $filter_name
  * @param mixed $value
  *
  * @return mixed
  */
 function apply_filters($filter_name, $value)
 {
     if (defined('WP_CONTENT_DIR')) {
         $args = func_get_args();
         $args[0] = $this->_hash_hook_name($filter_name);
         $value = call_user_func_array('apply_filters', $args);
     } else {
         $filters = RESTian::get_filters($filter_name);
         if (count($filters)) {
             $args = func_get_args();
             array_shift($args);
             foreach ($filters as $function) {
                 /**
                  * Sort by priorty
                  */
                 ksort($function);
                 foreach ($function as $priority) {
                     foreach ($priority as $callable) {
                         $value = call_user_func_array($callable, $args);
                     }
                 }
             }
         }
     }
     return $value;
 }
Beispiel #2
0
 /**
  * @param string $var_name
  * @param array $args
  * @throws Exception
  */
 function __construct($var_name, $args = array())
 {
     /**
      * If a string, could be 'foo' or 'var=foo' maybe
      */
     if (is_string($args)) {
         /**
          * If just 'foo' set $var = 'foo'
          */
         if (true === strpos($args, '=')) {
             $args = array('var' => $args);
         } else {
             /**
              * If 'var=foo' turn into array( 'var'=>'foo' )
              */
             parse_str($args, $args);
         }
     }
     if (!is_object($args) && !is_array($args)) {
         throw new Exception('Must pass a string, array or object for $args when creating a new ' . __CLASS__ . '.');
     }
     $this->name = $var_name;
     /**
      * Copy properties in from $args, if they exist.
      */
     foreach ($args as $property => $value) {
         if (property_exists($this, $property)) {
             $this->{$property} = $value;
         }
     }
     /*
      * Convert strings to arrays.
      */
     if (is_string($this->options)) {
         $this->options = RESTian::parse_string($this->options);
     }
     if (is_string($this->not_vars)) {
         $this->not_vars = RESTian::parse_string($this->not_vars);
     }
     if (is_string($this->transforms)) {
         $this->transforms = RESTian::parse_transforms($this->transforms);
     }
 }
Beispiel #3
0
 function __construct($settings_name, $args = array())
 {
     $this->modifier_name = $settings_name;
     if (!is_object($args) && !is_array($args)) {
         throw new Exception('Must pass a string, array or object for $args when creating a new ' . __CLASS__ . '.');
     }
     $args = RESTian::expand_shortnames($args, array('method' => 'http_method', 'type' => 'content_type'));
     if (isset($args['content_type'])) {
         $args['content_type'] = RESTian::expand_content_type($args['content_type']);
     }
     /**
      * Copy properties in from $args, if they exist.
      */
     foreach ($args as $property => $value) {
         if (property_exists($this, $property)) {
             $this->{$property} = $value;
         }
     }
 }
Beispiel #4
0
 /**
  * Call the API.
  *
  * On success (HTTP status == 200) $this->error_code and $this->error_msg will be false.
  * On failure (HTTP status != 200) $this->error_code and $this->error_msg will contain error information.
  *
  * On success or failure,  $this->response will contain the response captured by HTTP agent
  * except when username and password are not passed as part of auth.
  *
  * @return object|RESTian_Response
  */
 function make_request()
 {
     $response = new RESTian_Response(array('request' => $this));
     $api = $this->client;
     /**
      * Assign request & response to API so they are accessible inside the auth_provider
      */
     $api->request = $this;
     $api->response = $response;
     $auth_provider = $api->get_auth_provider();
     if ($this->needs_authentication() && !$this->has_authentication()) {
         $response->set_error('NO_AUTH', $this->service);
     } else {
         $http_agent = RESTian::get_new_http_agent($this->client->http_agent);
         $this->assign_settings();
         $response = $http_agent->make_request($this, $response);
         if ($response->is_http_error()) {
             /**
              * See if we can provide more than one error type here.
              */
             $msg = 'There was a problem reaching %s when calling the %s. Please try again later or contact the site\'s administrator.';
             $response->set_error('API_FAIL', sprintf($msg, $this->client->api_name, $this->service->service_name));
         } else {
             if ('authenticate' == $response->request->service->service_name) {
                 $handled = $auth_provider->authenticated($response);
             } else {
                 $handled = $auth_provider->handle_response($response);
             }
             if (!$handled) {
                 // @todo Add more HTTP status code responses as we better understand the use-cases.
                 switch ($response->status_code) {
                     case '200':
                         /**
                          * @var RESTian_Parser_Base $parser
                          */
                         $parser = RESTian::get_new_parser($this->service->content_type, $this, $response);
                         if ($parser instanceof RESTian_Parser_Base) {
                             $response->data = $parser->parse($response->body);
                         }
                         break;
                     case '401':
                         $response->set_error('BAD_AUTH', $this->service);
                         break;
                     default:
                         /**
                          * See if we can provide more than one error type here.
                          */
                         $response->set_error('UNKNOWN', 'Unexpected API response code: ' . $response->status_code);
                         break;
                 }
             }
             if ($this->omit_body) {
                 $response->body = null;
             }
             if ($this->omit_result) {
                 $response->result = null;
             }
         }
     }
     return $response;
 }
Beispiel #5
0
<?php

/**
 * Used by PhpStorm to map factory methods to classes for code completion, source code analysis, etc.
 *
 * The code is not ever actually executed and it only needed during development when coding with PhpStorm.
 *
 * @see http://confluence.jetbrains.com/display/PhpStorm/PhpStorm+Advanced+Metadata
 * @see http://blog.jetbrains.com/webide/2013/04/phpstorm-6-0-1-eap-build-129-177/
 */
namespace PHPSTORM_META;

/** @noinspection PhpUnusedLocalVariableInspection */
/** @noinspection PhpIllegalArrayKeyTypeInspection */
$STATIC_METHOD_TYPES = array(\RESTian::get_new_parser('', null, null) => array('application/xml' instanceof \RESTian_Application_Xml_Parser, 'application/json' instanceof \RESTian_Application_Json_Parser, 'text/plain' instanceof \RESTian_Text_Plain_Parser, 'text/html' instanceof \RESTian_Text_Html_Parser, 'text/csv' instanceof \RESTian_Text_Csv_Parser, 'application/vnd.php.serialized' instanceof \RESTian_Application_Serialized_Php_Parser), \RESTian::get_new_auth_provider('') => array('n/a' instanceof \RESTian_Not_Applicable_Provider, 'basic_http' instanceof \RESTian_Basic_Http_Auth_Provider), \RESTian::get_new_http_agent('') => array('wordpress' instanceof \RESTian_WordPress_Http_Agent, 'php_curl' instanceof \RESTian_Php_Curl_Http_Agent));
Beispiel #6
0
 /**
  * @param string $service_name
  * @param RESTian_Client $client
  * @param array $args
  * @throws Exception
  */
 function __construct($service_name, $client, $args = array())
 {
     $this->service_name = strtolower($service_name);
     $this->client = $client;
     /**
      * Set any defaults not set
      */
     foreach ($this->client->get_service_defaults() as $name => $value) {
         if (!isset($args[$name])) {
             $args[$name] = $value;
         }
     }
     /**
      * Allow shorthand of 'auth' for 'needs_authentication'
      */
     $args = RESTian::expand_shortnames($args, array('auth' => 'needs_authentication', 'settings' => 'settings_name'));
     /**
      * Copy properties in from $args, if they exist.
      */
     foreach ($args as $property => $value) {
         if (property_exists($this, $property)) {
             $this->{$property} = $value;
         }
     }
     /*
      * Transform from shortcut names like json and xml to valid mime type names application/json and application/xml.
      * @see: http://www.iana.org/assignments/media-types/index.html
      */
     $this->content_type = RESTian::expand_content_type($this->content_type);
     /*
      * Convert strings to arrays.
      */
     if (is_string($this->requires)) {
         $this->requires = RESTian::parse_string($this->requires);
     }
     /*
      * TODO: Note=> 'not_vars' is not yet tested.
      */
     if (is_string($this->not_vars)) {
         $this->not_vars = RESTian::parse_string($this->not_vars);
     }
     if (is_string($this->vars)) {
         $this->vars = RESTian::parse_string($this->vars);
     }
     if (isset($args['var_set'])) {
         $var_set_vars = $client->get_var_set($args['var_set']);
         $this->vars = $this->vars ? array_merge($var_set_vars, $this->vars) : $var_set_vars;
     }
 }
Beispiel #7
0
 /**
  * Register a settings
  *
  * @param string $settings_name
  * @param array|string $args
  */
 function register_settings($settings_name, $args)
 {
     $this->_settings[$settings_name] = new RESTian_Settings($settings_name, RESTian::parse_args($args));
 }