/** * 设置全局变量 * * @param array|object|string $data * @param string $key * @return void */ public function setGlobal($data, $key = '') { if ($key) { $_G[$key] = $data; } else { if (is_object($data)) { $data = get_object_vars($data); } $_G = $data; } $this->response->setData($_G, 'G', true); }
/** * Tests WindFrontController->registeComponent() * */ public function testRegisteComponent() { $httprequest = new WindHttpRequest(); $httprequest->setAttribute(123, 'long'); $httpresponse = new WindHttpResponse(); $httpresponse->setData(123, 'long'); $aaa = new stdClass(); $aaa->long = 123; $this->WindFrontController->registeComponent($aaa, 'aaa'); $this->WindFrontController->registeComponent($httpresponse, 'response'); $this->WindFrontController->registeComponent($httprequest, 'request'); $this->WindFrontController->createApplication(); $this->assertEquals(123, Wind::getApp()->getRequest()->getAttribute('long')); $this->assertEquals(123, Wind::getApp()->getResponse()->getData('long')); $this->assertEquals(123, Wind::getApp()->getComponent('aaa')->long); }