/** * Overriding parent * * @param string $name * @return mixed */ public function __get($name) { // View if ($name == 'view') { return $this->_controllerInstance->getView(); } // Request if ($name == 'request') { return $this->_controllerInstance->getRequest(); } // Response if ($name == 'response') { return $this->_controllerInstance->getResponse(); } // POST if ($name == 'post') { return $this->_controllerInstance->getRequest()->getPost(); } // GET if ($name == 'query') { return $this->_controllerInstance->getRequest()->getQuery(); } // URL parameters if ($name == 'params') { return $this->_controllerInstance->getRequest()->getParams(); } // application env if ($name == 'appEnv') { return $this->_controllerInstance->getAppEnv(); } parent::__get($name); }
/** * * Adapted and simplified from {@link Security::permissionFailure()}. * * @param Controller $controller * @param string $message * @return SS_HTTPResponse $response */ public static function show_access_message($controller, $message = '') { $response = $controller->getResponse(); $response->setBody($message); $response->setStatusDescription($message); $response->setStatusCode(403); return $response; }
/** * Executes the main functionality of the output processor * * @param \Controller $controller The relevant SilverStripe controller * @param mixed $result The result from the input processor * @return \SS_HTTPResponse */ public function process(\Controller $controller, $result = null) { $response = $controller->getResponse(); $response->setStatusCode(200); $response->addHeader('Content-Type', 'application/json'); $response->setBody(json_encode(['success' => (bool) $result])); return $response; }
/** * Executes the main functionality of the output processor * * @param \Controller $controller The relevant SilverStripe controller * @param mixed $result The result from the input processor * @return mixed|null */ public function process(\Controller $controller, $result = null) { if ($controller->getRequest()->isAjax()) { $response = $controller->getResponse(); $response->setStatusCode(200); $response->addHeader('Content-Type', 'application/json'); $response->setBody(json_encode($result)); return $response; } else { $controller->redirectBack(); } return null; }
public function getResponse() { // AJAX response with flash messages always returns JSON response. // But do not create a new JsonResponse if response already is one... if ($this->is_ajax) { header('X-path: ' . (isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/')); if (count($this->flash) > 0 && !$this->response instanceof Response\JsonResponse) { $old_response = parent::getResponse(); $this->response = new Response\JsonResponse(); $this->set('content', $old_response->renderToString()); } } $this->set('flash', $this->flash); return parent::getResponse(); }
/** * Outputs the content of a scaffold method passing it through the Controller::afterFilter() * * @return void */ protected function _output() { $this->controller->afterFilter(); $this->controller->getResponse()->send(); }
function getResponse() { return parent::getResponse(); }
/** * Register that we've had a permission failure trying to view the given page * * This will redirect to a login page. * If you don't provide a messageSet, a default will be used. * * @param Controller $controller The controller that you were on to cause the permission * failure. * @param string|array $messageSet The message to show to the user. This * can be a string, or a map of different * messages for different contexts. * If you pass an array, you can use the * following keys: * - default: The default message * - logInAgain: The message to show * if the user has just * logged out and the * - alreadyLoggedIn: The message to * show if the user * is already logged * in and lacks the * permission to * access the item. */ static function permissionFailure($controller = null, $messageSet = null) { if(Director::is_ajax()) { $response = ($controller) ? $controller->getResponse() : new HTTPResponse(); $response->setStatusCode(403); $response->setBody('NOTLOGGEDIN:'); return $response; } else { // Prepare the messageSet provided if(!$messageSet) { if(self::$default_message_set) { $messageSet = self::$default_message_set; } else { $messageSet = array( 'default' => _t( 'Security.NOTEPAGESECURED', "That page is secured. Enter your credentials below and we will send you right along." ), 'alreadyLoggedIn' => _t( 'Security.ALREADYLOGGEDIN', "You don't have access to this page. If you have another account that can access that page, you can log in below." ), 'logInAgain' => _t( 'Security.LOGGEDOUT', "You have been logged out. If you would like to log in again, enter your credentials below." ) ); } } if(!is_array($messageSet)) { $messageSet = array('default' => $messageSet); } // Work out the right message to show if(Member::currentUserID()) { $message = isset($messageSet['alreadyLoggedIn']) ? $messageSet['alreadyLoggedIn'] : $messageSet['default']; if($member = Member::currentUser()) { $member->logOut(); } } else if(substr(Director::history(),0,15) == 'Security/logout') { $message = $messageSet['logInAgain'] ? $messageSet['logInAgain'] : $messageSet['default']; } else { $message = $messageSet['default']; } Session::set("Security.Message.message", $message); Session::set("Security.Message.type", 'warning'); Session::set("BackURL", $_SERVER['REQUEST_URI']); // TODO AccessLogEntry needs an extension to handle permission denied errors // Audit logging hook if($controller) $controller->extend('permissionDenied', $member); Director::redirect("Security/login"); } return; }
public function testGetResponse() { $this->container->expects($this->once())->method('getInstanceOf')->with($this->equalTo('response_service'))->will($this->returnValue($this->getMock('IResponse'))); $this->assertThat($this->object->getResponse(), $this->isInstanceOf('IResponse')); }
/** * Initializes the components and models a controller will be using. * Triggers the controller action, and invokes the rendering if Controller::$autoRender is true and echo's the output. * Otherwise the return value of the controller action are returned. * * @param Controller $controller Controller to invoke * @param CakeRequest $request The request object to invoke the controller for. * @return string Output as sent by controller * @throws MissingActionException when the action being called is missing. */ protected function _invoke(Controller $controller, CakeRequest $request) { $controller->constructClasses(); $controller->startupProcess(); $methods = array_flip($controller->methods); if (!isset($methods[$request->params['action']])) { if ($controller->scaffold !== false) { App::import('Controller', 'Scaffold', false); return new Scaffold($controller, $request); } throw new MissingActionException(array('controller' => Inflector::camelize($request->params['controller']) . "Controller", 'action' => $request->params['action'])); } $result = call_user_func_array(array(&$controller, $request->params['action']), $request->params['pass']); $response = $controller->getResponse(); if ($controller->autoRender) { $controller->render(); } elseif ($response->body() === null) { $response->body($result); } $controller->shutdownProcess(); if (isset($request->params['return'])) { return $response->body(); } $response->send(); }
/** * test getResponse() method * * @test */ public function getResponse() { $this->generateComponent(); $this->Api->setResponse(['very' => ['deep' => ['array' => ['test']]]]); $this->assertSame('test', $this->Api->getResponse('very.deep.array.0')); }