/** * 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); }
/** * Utility static to avoid repetition. * * @param Controller $controller * @param string $identifier e.g. 'ParentID' or 'ID' * @retun number */ public static function get_numeric_identifier($controller, $identifier = 'ID') { // Deal-to all types of incoming data if (!$controller->hasMethod('currentPageID')) { return 0; } // Use native SS logic to deal with an identifier of 'ID' if ($identifier == 'ID') { $useId = $controller->currentPageID(); // Otherwise it's custom } else { $params = $controller->getRequest()->requestVars(); $idFromFunc = function () use($controller, $params, $identifier) { if (!isset($params[$identifier])) { if (!isset($controller->urlParams[$identifier])) { return 0; } return $controller->urlParams[$identifier]; } return $params[$identifier]; }; $useId = $idFromFunc(); } // We may have a padded string e.g. "1217 ". Without first truncating, we'd return 0 and pass tests... $id = (int) trim($useId); return !empty($id) && is_numeric($id) ? $id : 0; }
public function __construct(Controller $controller, $name) { // Set default fields $fields = new FieldList(HiddenField::create("AuthenticationMethod", null, $this->authenticator_class, $this), HiddenField::create('tempid', null, $controller->getRequest()->requestVar('tempid')), PasswordField::create("Password", _t('Member.PASSWORD', 'Password')), LiteralField::create('forgotPassword', sprintf('<p id="ForgotPassword"><a href="%s" target="_top">%s</a></p>', $this->getExternalLink('lostpassword'), _t('CMSMemberLoginForm.BUTTONFORGOTPASSWORD', "Forgot password?")))); if (Security::config()->autologin_enabled) { $fields->push(new CheckboxField("Remember", _t('Member.REMEMBERME', "Remember me next time?"))); } // Determine returnurl to redirect to parent page $logoutLink = $this->getExternalLink('logout'); if ($returnURL = $controller->getRequest()->requestVar('BackURL')) { $logoutLink = Controller::join_links($logoutLink, '?BackURL=' . urlencode($returnURL)); } // Make actions $actions = new FieldList(FormAction::create('dologin', _t('CMSMemberLoginForm.BUTTONLOGIN', "Log back in")), LiteralField::create('doLogout', sprintf('<p id="doLogout"><a href="%s" target="_top">%s</a></p>', $logoutLink, _t('CMSMemberLoginForm.BUTTONLOGOUT', "Log out")))); parent::__construct($controller, $name, $fields, $actions); }
public function __construct(Response $response, Controller $controller) { $this->response = $response; $this->controller = $controller; $this->request = $controller->getRequest(); $this->application = $controller->getApplication(); $this->config = $this->application->getConfig(); $this->controllerName = $this->request->getControllerName(); $this->actionName = $this->request->getActionName(); }
/** * 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; }
/** * Renders the search results into a template. Either * the search results template or the Atom feed */ public function renderResults() { if (!$this->results) { $this->performSearch(); } if (!$this->outputController) { return user_error('Call renderResults() on a DocumentationViewer instance.', E_USER_ERROR); } $request = $this->outputController->getRequest(); $data = $this->getSearchResults($request); $templates = array('DocumentationViewer_results', 'DocumentationViewer'); if ($request->requestVar('format') && $request->requestVar('format') == "atom") { // alter the fields for the opensearch xml. $title = ($title = $this->getTitle()) ? ' - ' . $title : ""; $link = Controller::join_links($this->outputController->Link(), 'DocumentationOpenSearch_Controller/description/'); $data->setField('Title', $data->Title . $title); $data->setField('DescriptionURL', $link); array_unshift($templates, 'OpenSearchResults'); } return $this->outputController->customise($data)->renderWith($templates); }
function getRequest() { return parent::getRequest(); }
/** * * @param Controller $controller * @param string $method */ private function normalizeMethodArguments($controller, $method) { $reflection = new ReflectionMethod($controller, $method); $numRequired = $reflection->getNumberOfRequiredParameters(); $numCurrent = count($this->methodArguments); if ($numRequired > $numCurrent) { // If request don't have enought arguments for method set it as invalid $controller->getRequest()->setValid(false); for ($i = $numRequired - $numCurrent; $i--; $i > 0) { $this->methodArguments[] = NULL; } } }
function confirm($request) { //TODO: pretend the user confirmed, and skip straight to results. (check that this is allowed) //TODO: get updated shipping details from paypal?? if ($payment = $this->payment()) { if ($pid = Controller::getRequest()->getVar('PayerID')) { $payment->PayerID = $pid; $payment->write(); $payment->confirmPayment(); } } else { //something went wrong? ..perhaps trying to pay for a payment that has already been processed } $this->doRedirect(); return; }
/** * Builds the cache key of this form * * @return void * * @author Sebastian Diel <*****@*****.**> * @since 26.11.2014 */ public function buildCacheKey() { $customParameters = $this->getCustomParameters(); $request = $this->controller->getRequest(); $requestString = ''; $formFieldString = ''; $formFields = $this->getFormFields(); $this->cacheKey = $this->name; if (count($customParameters) > 0) { $customParameterString = ''; foreach ($customParameters as $parameterName => $parameterValue) { $customParameterString .= $parameterName . ':' . $parameterValue . ';'; } $this->cacheKey .= sha1($customParameterString); } if (!is_null($request)) { foreach ($formFields as $fieldName => $fieldDefinition) { $this->addRequiredFieldParams($fieldDefinition, $fieldDefinition); $requestString .= $fieldName . ':' . $request[$fieldName] . ';'; $fieldDefinitionValue = $fieldDefinition['value']; if (is_string($fieldDefinitionValue)) { $formFieldString .= $fieldName . ':' . $fieldDefinitionValue . ';'; } elseif (is_array($fieldDefinitionValue)) { $formFieldString .= $fieldName . ':' . implode('-', $fieldDefinitionValue) . ';'; } } } if (class_exists('Translatable')) { $requestString .= '_' . Translatable::get_current_locale(); } $this->cacheKey .= sha1($requestString); $this->cacheKey .= sha1($formFieldString); $this->cacheKey .= md5($formFieldString); if (SecurityToken::is_enabled()) { $this->cacheKey .= $this->getSecurityID(); } if ($this->hasCacheKeyExtension()) { $this->cacheKey .= $this->getCacheKeyExtension(); } }
/** * * Detect if a flush operation is happening. * * @param Controller $controller * @return boolean * @todo add tests */ public static function is_flush(Controller $controller) { $getVars = $controller->getRequest()->getVars(); return stristr(implode(',', array_keys($getVars)), 'flush') !== false; }
public function testGetRequest() { $this->container->expects($this->once())->method('getInstanceOf')->with($this->equalTo('request_service'))->will($this->returnValue($this->getMock('IRequest'))); $this->assertThat($this->object->getRequest(), $this->isInstanceOf('IRequest')); }
/** * @return array */ public function getKeyInformation() { $request = $this->controller->getRequest(); return array('url' => sprintf("/%s/", trim($request->getURL(true), '/'))); }