/** * Return a new instance of Response with the headers and response code retuned by * Skeetr\Runtime\Manager::value() method * * @return Response */ public static function fromRuntime() { $response = new static(); $values = Manager::values(); $response->setResponseCode($values['header']['code']); $response->setHeaders($values['header']['list'], true); return $response; }
public function testHeaderRegisterCallback() { if (!function_exists('header_register_callback')) { return true; } $callback = function () use(&$called) { $called = 1; }; header_register_callback($callback); $values = Manager::values(); $this->assertSame($callback, $values['header']['callback']); }
public function testRegisterResetAndValues() { $this->assertFalse(Manager::overridden('natcasesort')); Manager::register('\\Skeetr\\Tests\\Runtime\\Example'); $function = new \ReflectionFunction('natcasesort'); $this->assertFalse($function->isInternal()); $this->assertSame('foo', natcasesort('foo')); $this->assertTrue(Manager::overridden('natcasesort')); $this->assertSame(1, Example::$test); Example::$test = 0; Manager::reset(); $this->assertSame(1, Example::$test); Example::$test = 0; Manager::reset('\\Skeetr\\Tests\\Runtime\\Example'); $this->assertSame(1, Example::$test); $this->assertTrue(false === Manager::reset('NotExists')); $expected = array('example' => array('test' => 1)); $this->assertSame($expected, Manager::values('\\Skeetr\\Tests\\Runtime\\Example')); $values = Manager::values('\\Skeetr\\Tests\\Runtime\\Example'); $this->assertSame(1, $values['example']['test']); }
/** * Set the headers and the response code to a given $response, class is reset after. * * @param HTTP\Response $response * @return boolean */ private function prepareResponse(HTTP\Response $response) { if (!Manager::loaded()) { return false; } session_write_close(); $values = Manager::values(); if (isset($values['header'])) { if (isset($values['header']['code']) && $values['header']['code']) { $response->setResponseCode($values['header']['code']); } if (isset($values['header']['list'])) { foreach ($values['header']['list'] as $headers) { foreach ($headers as $header) { $response->addHeader($header, false); } } } } Manager::reset(); }