This makes PHP code quality analyzer tools very happy.
/** * Render an exception into an HTTP response. * * @param Request $request * @param Exception $exception * * @return Response */ public function render($request, Exception $exception) { if (!$request->is(config('jsonapi.url'))) { return parent::render($request, $exception); } return $this->handle($request, $exception); }
function onAction() { global $application; if (modApiFunc('Session', 'is_Set', 'SessionPost')) { _fatal(array("CODE" => "CORE_050"), __CLASS__, __FUNCTION__); } $SessionPost = $_POST; $SessionPost["ViewState"]["ErrorsArray"] = array(); $fsr_id = $SessionPost["FsRule_id"] = intval($SessionPost["FsRule_id"]); $SessionPost["FsRuleName"] = trim($SessionPost["FsRuleName"]); $SessionPost["FsRuleMinSubtotal"] = floatval($SessionPost["FsRuleMinSubtotal"]); $SessionPost["FsRuleStrictCart"] = intval($SessionPost["StrictCart"]); if ($SessionPost["FsRuleName"] == "") { $SessionPost["ViewState"]["ErrorsArray"][] = "ERROR_EMPTY_RULE_NAME"; } $is_unique = modApiFunc("Shipping_Cost_Calculator", "checkIfFsRuleIsUnique", $SessionPost["FsRuleName"], $fsr_id); if (!$is_unique) { $SessionPost["ViewState"]["ErrorsArray"][] = "ERROR_NOT_UNIQUE_RULE_NAME"; } if ($SessionPost["FormSubmitValue"] == "Save") { if (count($SessionPost["ViewState"]["ErrorsArray"]) == 0) { unset($SessionPost["ViewState"]["ErrorsArray"]); $this->saveSettings($SessionPost); $SessionPost["ViewState"]["hasCloseScript"] = "true"; } } modApiFunc('Session', 'set', 'SessionPost', $SessionPost); $request = new Request(); $request->setView(CURRENT_REQUEST_URL); $request->setKey('FsRule_id', $fsr_id); $application->redirect($request); }
/** * {@inheritdoc} */ public function getCoordinates($street = null, $postal = null, $city = null, $country = null, $fullAddress = null) { // Generate a new container. $objReturn = new Container(); // Set the query string. $sQuery = $this->getQueryString($street, $postal, $city, $country, $fullAddress); $objReturn->setSearchParam($sQuery); $oRequest = null; $oRequest = new \Request(); $oRequest->send(sprintf($this->strGoogleUrl, rawurlencode($sQuery))); $objReturn->setUri(sprintf($this->strGoogleUrl, rawurlencode($sQuery))); if ($oRequest->code == 200) { $aResponse = json_decode($oRequest->response, 1); if (!empty($aResponse['status']) && $aResponse['status'] == 'OK') { $objReturn->setLatitude($aResponse['results'][0]['geometry']['location']['lat']); $objReturn->setLongitude($aResponse['results'][0]['geometry']['location']['lng']); } elseif (!empty($aResponse['error_message'])) { $objReturn->setError(true); $objReturn->setErrorMsg($aResponse['error_message']); } else { $objReturn->setError(true); $objReturn->setErrorMsg($aResponse['Status']['error_message']); } } else { // Okay nothing work. So set all to Error. $objReturn->setError(true); $objReturn->setErrorMsg('Could not find coordinates for address "' . $sQuery . '"'); } return $objReturn; }
function getCommand(Request $req) { $previous = $req->getLastCommand(); if (!$previous) { $cmd = $req->getProperty('cmd'); if (!$cmd) { $req->setProperty('cmd', 'default'); return self::$default_cmd; } } else { $cmd = $this->getForward($req); if (!$cmd) { return null; } } $cmd_obj = $this->resolveCommand($cmd); if (!$cmd_obj) { throw new \woo\base\AppException("couldn't resolve '{$cmd}'"); } $cmd_class = get_class($cmd_obj); if (isset($this->invoked[$cmd_class])) { throw new \woo\base\AppException("circular forwarding"); } $this->invoked[$cmd_class] = 1; return $cmd_obj; }
public static function run(Request $peticion) { $controller = $peticion->getControlador() . 'Controller'; $rutaControlador = ROOT . 'controllers' . DS . $controller . '.php'; $metodo = $peticion->getMetodo(); $args = $peticion->getArgs(); if (is_readable($rutaControlador)) { require_once $rutaControlador; $controller = new $controller(); //instanciando clase del indexController if (is_callable(array($controller, $metodo))) { $metodo = $peticion->getMetodo(); } else { $metodo = 'index'; } if ($args != null) { call_user_func_array(array($controller, $metodo), $args); //en un arreglo enviamos nombre de clase y metodo que queremos llamar y parametros que queremos pasar } else { call_user_func(array($controller, $metodo)); } } else { throw new Exception('Controller no encontrado: ' . $rutaControlador); } }
function outputMoveHref() { $request = new Request(); $request->setView('MoveProducts'); $request->setAction('MoveToProducts'); return $request->getURL(); }
public static function run() { spl_autoload_register(['Bootstrap', 'autoload']); putenv('LANG=en_US.UTF-8'); setlocale(LC_CTYPE, 'en_US.UTF-8'); date_default_timezone_set(@date_default_timezone_get()); session_start(); $session = new Session($_SESSION); $request = new Request($_REQUEST); $setup = new Setup($request->query_boolean('refresh', false)); $context = new Context($session, $request, $setup); if ($context->is_api_request()) { (new Api($context))->apply(); } else { if ($context->is_info_request()) { $public_href = $setup->get('PUBLIC_HREF'); $x_head_tags = $context->get_x_head_html(); require __DIR__ . '/pages/info.php'; } else { $public_href = $setup->get('PUBLIC_HREF'); $x_head_tags = $context->get_x_head_html(); $fallback_html = (new Fallback($context))->get_html(); require __DIR__ . '/pages/index.php'; } } }
/** * Run the Live Update * @param \BackendTemplate */ protected function runLiveUpdate(\BackendTemplate $objTemplate) { $archive = 'system/tmp/' . \Input::get('token'); // Download the archive if (!file_exists(TL_ROOT . '/' . $archive)) { $objRequest = new \Request(); $objRequest->send(\Config::get('liveUpdateBase') . 'request.php?token=' . \Input::get('token')); if ($objRequest->hasError()) { $objTemplate->updateClass = 'tl_error'; $objTemplate->updateMessage = $objRequest->response; return; } \File::putContent($archive, $objRequest->response); } $objArchive = new \ZipReader($archive); // Extract while ($objArchive->next()) { if ($objArchive->file_name != 'TOC.txt') { try { \File::putContent($objArchive->file_name, $objArchive->unzip()); } catch (\Exception $e) { $objTemplate->updateClass = 'tl_error'; $objTemplate->updateMessage = 'Error updating ' . $objArchive->file_name . ': ' . $e->getMessage(); return; } } } // Delete the archive $this->import('Files'); $this->Files->delete($archive); // Run once $this->handleRunOnce(); }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { // $room_type = new RoomType($request->all()); $room_type->save(); return $room_type; }
/** * package serverを立ち上げる * * @param string $package_root パッケージ名 */ public static function handler($package_root = null) { if (empty($package_root) || Rhaco::path() == "") { $debug = debug_backtrace(); $first_action = array_pop($debug); if ($package_root === null) { $package_root = basename(dirname($first_action["file"])); } if (Rhaco::path() == "") { Rhaco::init($first_action["file"]); } } $base_dir = Rhaco::path(); $request = new Request(); $package_root_path = str_replace(".", "/", $package_root); $preg_quote = (empty($package_root_path) ? "" : preg_quote($package_root_path, "/") . "\\/") . "(.+)"; $tag = new Tag("rest"); if (preg_match("/^\\/state\\/" . $preg_quote . "\$/", $request->args(), $match)) { $tag->add(new Tag("package", $match[1])); if (self::parse_package($package_root_path, $base_dir, $match[1], $tgz_filename)) { $tag->add(new Tag("status", "success")); $tag->output(); } } else { if (preg_match("/^\\/download\\/" . $preg_quote . "\$/", $request->args(), $match)) { if (self::parse_package($package_root_path, $base_dir, $match[1], $tgz_filename)) { Http::attach(new File($tgz_filename)); } } } Http::status_header(403); $tag->add(new Tag("status", "fail")); $tag->output(); exit; }
/** * add a new request to the pool. */ public function add(Request $request, array $opts = array()) { $ch = $request->build($opts); $this->requests[(int) $request->resource] = $request; curl_multi_add_handle($this->resource, $request->resource); return $request; }
public function testJSONRequestIsConvertedToConvertedBodyRequest() { $request = new Request(Request::POST, '/entities/something/1'); $request->setHeaderField('Content-Type', 'application/json')->setBody('{"some": "value"}'); $serviceRequest = $this->requestConverter->fromHTTPRequest($request); $this->assertEquals((object) array('some' => 'value'), $serviceRequest->getBody()); }
/** * Tries to match a URL path with a set of routes. * * If the matcher can not find information, it must throw one of the * exceptions documented below. * * @param string $pathinfo The path info to be parsed (raw format, i.e. not * urldecoded) * * @return array An array of parameters * * @throws ResourceNotFoundException If the resource could not be found * @throws MethodNotAllowedException If the resource was found but the * request method is not allowed */ public function match($pathinfo) { $urlMatcher = new UrlMatcher($this->routeCollection, $this->getContext()); $result = $urlMatcher->match($pathinfo); if (!empty($result)) { try { // The route matches, now check if it actually exists $result['content'] = $this->contentManager->findActiveBySlug($result['slug']); } catch (NoResultException $e) { try { //is it directory index if (substr($result['slug'], -1) == '/' || $result['slug'] == '') { $result['content'] = $this->contentManager->findActiveBySlug($result['slug'] . 'index'); } else { if ($this->contentManager->findActiveBySlug($result['slug'] . '/index')) { $redirect = new RedirectResponse($this->request->getBaseUrl() . "/" . $result['slug'] . '/'); $redirect->sendHeaders(); exit; } } } catch (NoResultException $ex) { try { $result['content'] = $this->contentManager->findActiveByAlias($result['slug']); } catch (NoResultException $ex) { throw new ResourceNotFoundException('No page found for slug ' . $pathinfo); } } } } return $result; }
/** * */ function onAction() { global $application; $request = $application->getInstance('Request'); $SessionPost = array(); if (modApiFunc('Session', 'is_Set', 'SessionPost')) { _fatal(array("CODE" => "CORE_050"), __CLASS__, __FUNCTION__); } $SessionPost = $_POST; switch ($SessionPost["ViewState"]["FormSubmitValue"]) { case "save": $SessionPost["ViewState"]["ErrorsArray"] = array(); if (empty($SessionPost["ModuleName"]) == true || trim($SessionPost["ModuleName"]) == '') { $SessionPost["ViewState"]["ErrorsArray"][] = "MODULE_ERROR_NO_NAME"; } $nErrors = sizeof($SessionPost["ViewState"]["ErrorsArray"]); if ($nErrors == 0) { unset($SessionPost["ViewState"]["ErrorsArray"]); $this->saveDataToDB($SessionPost); $SessionPost["ViewState"]["hasCloseScript"] = "true"; } break; default: _fatal(array("CODE" => "CORE_051"), __CLASS__, __FUNCTION__, $request->getValueByKey('FormSubmitValue')); break; } modApiFunc('Session', 'set', 'SessionPost', $SessionPost); // get view name by action name. $request = new Request(); $request->setView(CURRENT_REQUEST_URL); $application->redirect($request); }
public function testGenerateUri() { $request = new Request(); $request->pattern('test/<action>'); $params = array('action' => 'index'); $this->assertSame('test/index', $request->generate_uri($params)); }
public function __construct(Request $peticion) { global $debugbar; $app = $peticion->getControlador(); $apps = new AppsBuilder(require __DIR__ . '/Config/aplications.php'); $this->app = new \Elephant\Bootstrap\AppBuilder($apps->getAppName($app)); }
/** * MailInfo constructor */ function MailInfo() { global $application; $MR =& $application->getInstance('MessageResources'); //initialize form data with null values when adding a new notification $this->currentNotificationId = modApiFunc("Notifications", "getCurrentNotificationId"); if ($this->currentNotificationId == 'Add') { $this->notificationInfo = array('Id' => '', 'Name' => '', 'Subject' => '', 'Body' => '', 'JavascriptBody' => '', 'From_addr' => '', 'Email_Code' => '', 'Active' => 'checked', 'Action_id' => 1); $request = new Request(); $request->setView('NotificationInfo'); $request->setAction('AddNotification'); $formAction = $request->getURL(); $this->properties = array('SubmitButton' => $MR->getMessage('BTN_ADD'), 'FormAction' => $formAction); } else { //initialize form data with database values when editing the notification $this->notificationInfo = modApiFunc("Notifications", "getNotificationInfo", $this->currentNotificationId); if (sizeof($this->notificationInfo) == 1) { $this->notificationInfo = $this->notificationInfo[0]; $this->notificationInfo['JavascriptBody'] = addcslashes(addslashes($this->notificationInfo['Body']), "