Call a method and cache the response.

@param string $property
@param string $path
@param string $method

@return mixed
193037
protected function callWithFallback($property, $path, $method)
    {
        $result = $this->cache->{$method}($path);

        if ($result !== false && ($property === null || array_key_exists($property, $result))) {
            return $result;
        }

        $result = $this->adapter->{$method}($path);

        if ($result) {
            $object = $result + compact('path');
            $this->cache->updateObject($path, $object, true);
        }

        return $result;
    }
858976
private function getMethodValue($object, $property)
    {
        $methods = [$property];

        if (method_exists($object, $property)) {
            return $this->getReflectionMethod($object, $property)->invoke($object);
        }

        $methodSuffix = ucfirst($property);

        foreach (['get', 'has', 'is'] as $methodPrefix) {
            $methods[] = $method = $methodPrefix.$methodSuffix;

            if (method_exists($object, $method)) {
                return $this->getReflectionMethod($object, $method)->invoke($object);
            }
        }

        throw new \InvalidArgumentException(sprintf(
            'The property "%s" or methods %s don\'t exist on class "%s".',
            $property,
            '"'.implode('", "', $methods).'"',
            get_class($object)
        ));
    }
416683
public static function set($method, $path, $action)
    {
        if (is_array($method)) {
            foreach ($method as $value) {
                self::set($value, $path, $action);
            }
        } else {
            if (is_string($action)) {
                $action = parent::$prefixNS . $action;
            } elseif ($action !== null && !$action instanceof \Closure) {
                return null;
            }

            $method = strtoupper(trim($method));

            $path = parent::$prefixPath . $path;

            if (!isset(parent::$httpRoutes[$path])) {
                parent::$httpRoutes[$path] = array();
            }

            parent::$httpRoutes[$path][$method] = $action;
        }
    }
581040
protected function getMethod($target, $property, $pre = 'get')
    {
        if(isset($this->$property)){
            $method = $pre . ucfirst($this->$property);
            if(method_exists($target, $method)){
                return $method;
            }
            throw new MethodNotFoundException($method, get_class($target));
        }
        throw new PropertyNotFoundException($property, get_class($target));
    }
1218239
function purge_cache( $path, $method = 'GET', $params = array() ) {
			$this->_logger->entrance( "{$method}:{$path}" );

			$cache_key = $this->get_cache_key( $path, $method, $params );

			self::$_cache->purge( $cache_key );
		}
708656
private function getResponse($method, $path, $body = null, $headers = [])
    {
        $allHeaders = array_merge($this->getAuthorizationHeader(), $headers);
        $uri = $path;

        $request = new Request($method, $uri, $allHeaders, $body);

        return $this->guzzle->send($request);
    }
793988
private function register($method, $path, $controller, $action) {

        $this->klein->respond($method, $path, function($request, $response, $service) use($controller, $action) {
            require_once app_path("controllers/$controller.php");
            $class = new $controller($request, $response, $service);

            $class->_preRender();
            echo $class->_render($class->$action(), array());
            $class->_postRender();
        });

    }
872634
protected function createRequest($method, $path, $value = null)
    {
        list($path, $value) = $this->evaluatePathValueArguments(array($path, $value));
        return $this->client->createRequest($method, $this->buildUrl($path), $this->buildOptions($value));
    }
318079
private function getResponse($method, $path, $parameters)
    {
        try {
            $response = $this->adapter->request($method, $path, $parameters);
            return $this->getResult($response);
        }
        catch (\Exception $e) {
            return $e->getMessage();
        }
    }
730250
protected function dispatchRouter($method, $path)
    {
        $router = $this->container['router'];
        $logger = $this->container['logger'];

        $logger->debug('Router dispatch.', ['method' => $method, 'path' => $path]);

        $router->init();
        $route_info = $router->dispatch($method, $path);

        $handler = null;
        $vars = [];

        switch ($route_info[0]) {
        case RouteDispatcher::NOT_FOUND:
            $logger->debug('Routing failed. Not Found.');
            throw new HttpNotFoundException('404 Not Found');
            break;
        case RouteDispatcher::METHOD_NOT_ALLOWED:
            $logger->debug('Routing failed. Method Not Allowd.');
            throw new HttpMethodNotAllowedException('405 Method Not Allowed');
            break;
        case RouteDispatcher::FOUND:
            $handler = $route_info[1];
            $vars = $route_info[2];
            $logger->debug('Route found.', ['handler' => $handler]);
            break;
        }

        return [$handler, $vars];
    }
1054476
function is_cached( $path, $method = 'GET', $params = array() ) {
			$cache_key = $this->get_cache_key( $path, $method, $params );

			return self::$_cache->has_valid( $cache_key );
		}
228909
protected function _noData($path, $method = 'GET')
    {
        try {
            $ch = $this->_getCurlHandler($path, $method);
            $return = $this->_parseCurlResponse(curl_exec($ch));
            curl_close($ch);
        } catch (\Exception $e) {
            $return = null;
        }
        return $return;
    }
885015
public function prepareRequest($path, $method = 'GET', $data = '')
    {
        $this->responseCode = null;
        $curl = curl_init();

        // General cURL options
        $this->setCurlOption(CURLOPT_VERBOSE, 0);
        $this->setCurlOption(CURLOPT_HEADER, 0);
        $this->setCurlOption(CURLOPT_RETURNTRANSFER, 1);

        // HTTP Basic Authentication
        if ($this->apikeyOrUsername && $this->useHttpAuth) {
            if (null === $this->pass) {
                $this->setCurlOption(CURLOPT_USERPWD, $this->apikeyOrUsername.':'.rand(100000, 199999));
            } else {
                $this->setCurlOption(CURLOPT_USERPWD, $this->apikeyOrUsername.':'.$this->pass);
            }
            $this->setCurlOption(CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
        }

        // Host and request options
        $this->setCurlOption(CURLOPT_URL, $this->url.$path);
        $this->setCurlOption(CURLOPT_PORT, $this->getPort());
        if (80 !== $this->getPort()) {
            $this->setCurlOption(CURLOPT_SSL_VERIFYPEER, (int) $this->checkSslCertificate);
            $this->setCurlOption(CURLOPT_SSL_VERIFYHOST, (int) $this->checkSslHost);
            $this->setCurlOption(CURLOPT_SSLVERSION, $this->sslVersion);
        }

        // Set the HTTP request headers
        $httpHeader = $this->setHttpHeader($path);
        $this->setCurlOption(CURLOPT_HTTPHEADER, $httpHeader);

        $this->unsetCurlOption(CURLOPT_CUSTOMREQUEST);
        $this->unsetCurlOption(CURLOPT_POST);
        $this->unsetCurlOption(CURLOPT_POSTFIELDS);
        switch ($method) {
            case 'POST':
                $this->setCurlOption(CURLOPT_POST, 1);
                if ($this->isUploadCall($path, $data)) {
                    $this->prepareUploadRequest($data);
                } elseif (isset($data)) {
                    $this->setCurlOption(CURLOPT_POSTFIELDS, $data);
                }
                break;
            case 'PUT':
                $this->setCurlOption(CURLOPT_CUSTOMREQUEST, 'PUT');
                if (isset($data)) {
                    $this->setCurlOption(CURLOPT_POSTFIELDS, $data);
                }
                break;
            case 'DELETE':
                $this->setCurlOption(CURLOPT_CUSTOMREQUEST, 'DELETE');
                break;
            default: // GET
                break;
        }
        // Set all cURL options to the current cURL resource
        curl_setopt_array($curl, $this->getCurlOptions());

        return $curl;
    }
498625
private function get_cache_key( $path, $method = 'GET', $params = array() ) {
			$canonized = $this->_api->CanonizePath( $path );
//			$exploded = explode('/', $canonized);
//			return $method . '_' . array_pop($exploded) . '_' . md5($canonized . json_encode($params));
			return strtolower( $method . ':' . $canonized ) . ( ! empty( $params ) ? '#' . md5( json_encode( $params ) ) : '' );
		}
760768
protected function invokeGetter(ReflectionProperty $property)
    {
        $methodName = $this->generateGetterName($property->getName());
        if ($this->hasInternalMethod($methodName)) {
            return $this->$methodName();
        }

        throw new UndefinedPropertyException(sprintf(
            'No "%s"() method available for property "%s"', $methodName,
            $property->getName()
        ));
    }
594023
public function update(PropertyRequest $request, Property $property)
    {
        $property->update($request->all());
        return new PropertyResource($property);
    }
905715
private function request($path = 'post/index.json', $method = 'GET', array $data = null, array $options = null, $class = null)
    {
        if (empty($path)) {
            throw new \InvalidArgumentException('Argument "path" cannot be empty');
        }

        if (strtoupper($method) === 'GET') {
            $request_options = ['query' => $data];
        } elseif (strtoupper($method) === 'POST') {
            $request_options = $this->prepareRequestParams($data);
        } else {
            throw new \InvalidArgumentException('Unsupported request method');
        }

        ($this->progress_handler !== null && is_callable($this->progress_handler)) && $request_options['progress'] = $this->progress_handler;
        ($this->debug_log_handler !== null && is_callable($this->debug_log_handler)) && $request_options['debug'] = $this->createDebugStream();

        if (is_array($options)) {
            $request_options = array_replace_recursive($request_options, $options);
        }

        try {
            $response = $this->client->request($method, $path, $request_options);
            $raw_result = (string)$response->getBody();
            $result = json_decode($raw_result, true);

            if (!is_array($result)) {
                if ($this->throw_exceptions === true) {
                    throw new E621Exception(E621Exception::MESSAGE_DATA_INVALID, 0, null, $response);
                } else {
                    $result = [
                        'reason' => E621Exception::MESSAGE_DATA_INVALID,
                        'error'  => 'Response couldn\'t be decoded into array',
                    ];
                }
            }
        } catch (GuzzleConnectException $e) {
            if ($this->throw_exceptions === true) {
                throw new ConnectException($e);
            } else {
                $result = [
                    'reason' => ConnectException::MESSAGE,
                    'error'  => $e->getMessage(),
                ];
            }
        } catch (RequestException $e) {
            $response = $e->getResponse();
            $this->debugLog($e);

            if ($response !== null && $response->getBody() !== null) {
                $raw_result = (string)$response->getBody();
                $result = json_decode($raw_result, true);

                if (!is_array($result)) {
                    $result = 'Request resulted in a `' . $e->getResponse()->getStatusCode() . ' ' . $e->getResponse()->getReasonPhrase() . '` response';

                    if ($this->throw_exceptions === true) {
                        throw new E621Exception($result, 0, $e, $response);
                    }

                    $result = [
                        'reason' => ConnectException::MESSAGE,
                        'error'  => $result,
                    ];
                }
            } else {
                if ($this->throw_exceptions === true) {
                    throw new E621Exception(E621Exception::MESSAGE_REQUEST_ERROR, 0, $e, $response);
                } else {
                    $result = [
                        'reason' => ConnectException::MESSAGE,
                        'error'  => $e->getMessage(),
                    ];
                }
            }
        } catch (GuzzleException $e) {
            if ($this->throw_exceptions === true) {
                throw new E621Exception(E621Exception::MESSAGE_CLIENT_ERROR, 0, $e);
            } else {
                $result = [
                    'reason' => E621Exception::MESSAGE_CLIENT_ERROR,
                    'error'  => $e->getMessage(),
                ];
            }
        } finally {
            $this->endDebugStream();
        }

        // Search for result class if we don't have one, this shouldn't happen but fail safe should be left anyway
        if (empty($class)) {
            $class = Generic::class;
            $method_config = Methods::lookupByPath($path);

            if ($method_config !== null) {
                $class = $method_config['class'];
            }
        }

        /** @noinspection PhpUndefinedVariableInspection */
        return new Response($class, $result, isset($raw_result) ? $raw_result : null);
    }