function HttpServletContext(&$servletcontext) { parent::HttpContext(); if (ServletContext::validClass($servletcontext)) { $this->context =& $servletcontext; } }
public static function mapBindingModels($controller, $action) { $generatedBindingModels = []; $class = new \ReflectionClass($controller); $method = $class->getMethod($action); $properties = $method->getParameters(); foreach ($properties as $property) { $type = $property->getClass(); if ($type !== null) { $bindingModelClass = $property->getClass(); $bmClassName = $property->getClass()->name; $bindingModelInstance = new $bmClassName(); if (!HttpContext::getInstance()->isPost()) { $generatedBindingModels[] = $bindingModelInstance; continue; } $methods = $bindingModelClass->getMethods(); foreach ($methods as $bmMethod) { if (strpos($bmMethod->name, 'set') === 0) { $propertyName = lcfirst(substr($bmMethod->name, 3, strlen($bmMethod->name))); if (isset($_POST[$propertyName])) { $method = $bmMethod->name; $bindingModelInstance->{$method}($_POST[$propertyName]); } } } $bindingModelInstance->validate(); $generatedBindingModels[] = $bindingModelInstance; } } return $generatedBindingModels; }
private function getPath() { $path = HttpContext::getInstance()->getRequest()->getPathInfo(); if (!$path) { return ''; } $path = substr($path, 1); return $path; }
public function testGetSession() { $session = $this->object->getSession(); $this->assertTrue($session instanceof HttpSession); $this->assertTrue($session === $this->object->getSession(), "Check for Singleton"); }
/** * The HTTP response body from the API request * @return mixed */ public function getResponseBody() { return $this->context->getResponse()->getRawBody(); }
/** * Set the CORS headers * * @see http://www.w3.org/TR/cors/ * @see http://www.nczonline.net/blog/2010/05/25/cross-domain-ajax-with-cross-origin-resource-sharing/ * @see http://enable-cors.org/ * @see http://www.html5rocks.com/en/tutorials/cors/ */ public function setCORSHeaders() { $httpContext = HttpContext::get(); $request = $httpContext->getRequest(); $response = $httpContext->getResponse(); $response->addHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, HEAD, PATCH, OPTIONS'); // origin $origin = $request->getHeader('Origin'); if ($origin) { $response->addHeader('Access-Control-Allow-Origin', $origin); } // or use '*' to allow all // custom headers $xHeaders = $request->getHeader('Access-Control-Request-Headers'); if ($xHeaders) { $response->addHeader('Access-Control-Allow-Headers', $xHeaders); } $response->addHeader('Access-Control-Allow-Credentials', 'true'); // change preflight request $response->addHeader('Access-Control-Max-Age', 1800); }