public function make_request($options) { $injector = Injector::getInstance(); $url = $options['url']; $method = $options['method']; $headers = $options['headers']; $body = isset($options['body']) ? $options['body'] : ''; $response = null; if (isset($options['qs'])) { $qs = http_build_query($options['qs']); $url .= '?' . $qs; } $url = str_replace('%2C', ',', $url); if (isset($headers['Content-Type']) && $headers['Content-Type'] == 'application/json' && is_array($body)) { $body = json_encode($body); } Request::verifyPeer($injector->ssl_verification); $response = Request::send($options['method'], $url, $body, $headers); return $response; }
public function make_request($options) { $injector = Injector::getInstance(); $url = $options['url']; $method = $options['method']; $headers = $options['headers']; $body = isset($options['body']) ? $options['body'] : ''; $response = null; if (isset($options['qs'])) { $qs = http_build_query($options['qs']); $url.= '?' . $qs; } $url = str_replace('%2C', ',', $url); \Unirest::verifyPeer($injector->ssl_verification); if ($options['method'] == 'GET') { $response = \Unirest::get($url, $headers); } if ($options['method'] == 'POST') { $response = \Unirest::post($url, $headers, $body); } if ($options['method'] == 'PUT') { $response = \Unirest::put($url, $headers, $body); } if ($options['method'] == 'DELETE') { $response = \Unirest::delete($url, $headers); } if ($options['method'] == 'PATCH') { $response = \Unirest::patch($url, $headers, $body); } return $response; }
private function processController() { $input = InputData::getInstance(); $input->setGet($this->_params); $input->setPost($this->_router->GetPost()); $file = ucfirst($this->_namespace) . '\\' . ucfirst($this->_controller); $this->_controller = $file; $realPath = str_replace('\\', DIRECTORY_SEPARATOR, '../' . $file . '.php'); $realPath = realpath($realPath); if (file_exists($realPath) && is_readable($realPath)) { $calledController = new $file(); if (method_exists($calledController, $this->_method)) { if ($this->isValidRequestMethod($calledController, $this->_method)) { // Create binding model $refMethod = new \ReflectionMethod($calledController, $this->_method); $doc = $refMethod->getDocComment(); // Validate accessibility $this->ValidateAuthorization($doc); if (preg_match('/@param\\s+\\\\?([\\s\\S]+BindingModel)\\s+\\$/', $doc, $match)) { $bindingModelName = $match[1]; $bindingModelsNamespace = App::getInstance()->getConfig()->app['namespaces']['Models'] . 'BindingModels/'; $bindingModelsNamespace = str_replace('../', '', $bindingModelsNamespace); $bindingModelPath = str_replace('/', '\\', $bindingModelsNamespace . $bindingModelName); $bindingReflection = new \ReflectionClass($bindingModelPath); $properties = $bindingReflection->getProperties(); $params = array(); foreach ($properties as $property) { $name = $property->getName(); $value = $input->postForDb($name); if ($value === null) { throw new \Exception("Invalid binding model! Property '{$name}' not found", 400); } else { $params[$name] = $value; } } $bindingModel = new $bindingModelPath($params); Injector::getInstance()->loadDependencies($calledController); $calledController->{strtolower($this->_method)}($bindingModel); } else { Injector::getInstance()->loadDependencies($calledController); $calledController->{strtolower($this->_method)}(); } exit; } else { throw new \Exception("Method does not allow '" . ucfirst($this->_requestMethod) . "' requests!", 500); } } else { throw new \Exception("'" . $this->_method . "' not found in '" . $file . '.php', 404); } } else { throw new \Exception("File '" . $file . '.php' . "' not found!", 404); } }
public function __construct($credentials = array()) { $this->injector = Injector::getInstance(); $this->credentials = $credentials; }
/** * * */ public function __construct() { $this->injector = Injector::getInstance(); }