Example #1
1
 public static function Run(Request $request)
 {
     $controller = $request->getController() . 'Controller';
     $route = ROOT . '../' . 'app' . DS . 'Controllers' . DS . $controller . '.php';
     $method = $request->getMethod();
     if ($method == 'index.php') {
         $method = 'Index';
     }
     $parameters = $request->getParameters();
     if (is_readable($route)) {
         require_once $route;
         $function = "App\\Controllers\\" . $controller;
         $controller = new $function();
         if (!isset($parameters)) {
             $data = call_user_func(array($controller, $method));
         } else {
             $data = call_user_func_array(array($controller, $method), $parameters);
         }
     }
 }
Example #2
1
 public function __construct(Request $request)
 {
     $this->yaml = sfYaml::load($this->fileRouting);
     $this->params = $request->getParameters();
     $this->getRoute();
 }
Example #3
0
 public function testSetParameters()
 {
     $request = new Request('http://google.com', 'GET');
     $request->setParameters(array('foo' => 'bar'), true);
     $this->assertEquals(array('foo' => 'bar'), $request->getParameters(), 'Set parameters failed');
     $request->setParameters(array('foo' => 'bar2'), true);
     $this->assertEquals(array('foo' => 'bar2'), $request->getParameters(), 'Overwrite parameter failed');
     $request->setParameters(array('foo2' => 'bar'), true);
     $this->assertEquals(array('foo' => 'bar2', 'foo2' => 'bar'), $request->getParameters(), 'Set second parameter failed');
     $request->setParameters(array('bla' => 'blub'));
     $this->assertEquals(array('bla' => 'blub'), $request->getParameters(), 'Reset parameter failed');
 }
 public function resolve(Request $request)
 {
     $behaviour = null;
     if (array_key_exists('behaviour', $request->getParameters())) {
         $behaviour = $request->getParameter('behaviour');
     }
     if (array_key_exists('pageid', $request->getParameters())) {
         $page = PageMap::get()->getPageById($request->getParameter('pageid'));
         if ($page != null) {
             return new ListenerRequestTarget($page, $request->getParameter('listener'), $behaviour);
         }
         return new PageRequestTarget(\SessionExpiredPage::getIdentifier());
     } else {
         return new ListenerRequestTarget($this->getPageClassForPath($request), $request->getParameter('listener'), $behaviour);
     }
 }
 public function updateOrganization(Request $request, Session $session, $view)
 {
     $service = new SecurityService();
     $id = $request->getParameter('id');
     if (!$request->getParameter(SUBMIT_PARAM)) {
         $info = $service->getOrganizationById($id);
         $this->setAttribute('original_org_name', $info->name);
         if (isset($info)) {
             $this->setAttributes(get_object_vars($info));
         }
         self::dumpObject($info, self::$_debug);
         return new Template('update_organization');
     } else {
         $name = trim($request->getParameter('name'));
         $org = $service->getOrganizationByName($name);
         $orginalOrgName = $request->getParameter('original_org_name');
         $orgName = $org->name;
         if (!empty($org) && strcmp($orgName, $orginalOrgName) != 0) {
             $result['response_code'] = -1;
             $result['message'] = 'This organization name is taken. Please enter a different one.';
         } else {
             $data = $request->getParameters(true);
             $service->updateOrganization($id, $data);
             $result['response_code'] = 1;
         }
         return $this->showJsonResponse($result);
     }
 }
Example #6
0
 public function execute(Request $request)
 {
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $request->getUrl());
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
     $username = $request->getUsername();
     $password = $request->getPassword();
     if ($username && $password) {
         curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password);
     }
     switch ($request->getMethod()) {
         case self::POST:
         case self::PUT:
             curl_setopt($ch, CURLOPT_POST, 1);
             curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($request->getParameters()));
             break;
         case self::DELETE:
             curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
             break;
         case self::GET:
         default:
             break;
     }
     $result = curl_exec($ch);
     if (!$result) {
         $errorNumber = curl_errno($ch);
         $error = curl_error($ch);
         curl_close($ch);
         throw new \Exception($errorNumer . ': ' . $error);
     }
     curl_close($ch);
     return $request->getResponseTransformerImpl()->transform($result);
 }
 public function testParamSplit()
 {
     $request = new Request("/my-request/param1/param2");
     $params = $request->getParameters();
     $this->assertEquals($params[0], "param1");
     $this->assertEquals($params[1], "param2");
 }
Example #8
0
 /**
  * Sign request with private key
  * 
  * @param Request request
  */
 function signRequest(Request $request)
 {
     $request->set('clientId', $this->clientId);
     $params = $request->getParameters();
     ksort($params);
     $token = $this->privateKey;
     foreach ($params as $key => $value) {
         $token .= $key . $value;
     }
     $request->set('hash', hash('sha256', $token));
 }
Example #9
0
 /**
  * Makes a request.
  *
  * @param Request $request A Request instance
  *
  * @return Response A Response instance
  */
 protected function doRequest($request)
 {
     curl_setopt($this->curl, CURLOPT_URL, $request->getUri());
     curl_setopt($this->curl, CURLOPT_POSTFIELDS, $request->getParameters());
     curl_setopt($this->curl, CURLOPT_CUSTOMREQUEST, $request->getMethod());
     curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, 1);
     $content = curl_exec($this->curl);
     $this->assertCurlError();
     $requestInfo = curl_getinfo($this->curl);
     return new Response($content, $requestInfo['http_code']);
 }
Example #10
0
 public function __construct(Request $request)
 {
     if (count($request->getParameters(true)) > 1) {
         $this->response = Response::fourOhFour();
         return;
     }
     $user = CurrentUser::getUserSession();
     if (!$user->isLoggedIn()) {
         $this->response = new Response(200, "@home/notLoggedIn.twig", "Welcome", "home");
         return;
     }
     $this->response = new Response(200, "@home/main.twig", "Hi {$user->getFirstName()}", "home", $user);
 }
Example #11
0
 /**
  * Template factory.
  * @param  string
  * @param  callable
  * @return Application\UI\ITemplate
  */
 public function createTemplate($class = NULL, $latteFactory = NULL)
 {
     $latte = $latteFactory ? $latteFactory() : $this->getContext()->getByType('Nette\\Bridges\\ApplicationLatte\\ILatteFactory')->create();
     $template = $class ? new $class() : new Nette\Bridges\ApplicationLatte\Template($latte);
     $template->setParameters($this->request->getParameters());
     $template->presenter = $this;
     $template->context = $this->context;
     if ($this->httpRequest) {
         $url = $this->httpRequest->getUrl();
         $template->baseUrl = rtrim($url->getBaseUrl(), '/');
         $template->basePath = rtrim($url->getBasePath(), '/');
     }
     return $template;
 }
 public function passThrough(Request $request)
 {
     $params = $request->getParameters();
     if (array_key_exists('api_key', $params)) {
         throw new \ErrorException('Request contains parameter with a reserved name: \'api_key\'');
     }
     if (array_key_exists('api_sig', $params)) {
         throw new \ErrorException('Request contains parameter with a reserved name: \'api_sig\'');
     }
     $params['api_key'] = $this->consumerKey;
     $baseString = BaseString::compute($request->getMethod(), $request->getUrl(), $params);
     $signature = base64_encode(hash_hmac('sha1', $baseString, rawurlencode($this->consumerSecret), true));
     $request->setParameter('api_key', $this->consumerKey);
     $request->setParameter('api_sig', $signature);
 }
 public function __construct(LoggerInterface $Logger, Request $Request, RequestContext $RequestContext, TransactionManagerInterface $TransactionManager, Nonces $Nonces, Permissions $Permissions, DateFactory $DateFactory, ModelMapper $ModelMapper, Session $Session, Response $Response, $isCommandLine)
 {
     $this->Logger = $Logger;
     $this->Request = $Request;
     $this->Response = $Response;
     $this->RequestContext = $RequestContext;
     $this->TransactionManager = $TransactionManager;
     $this->Permissions = $Permissions;
     $this->Nonces = $Nonces;
     $this->DateFactory = $DateFactory;
     $this->ModelMapper = $ModelMapper;
     $this->Session = $Session;
     $this->isCommandLine = $isCommandLine;
     $this->params = $Request->getParameters();
     $this->rawParams = $Request->getRawParameters();
 }
Example #14
0
 private function executePut($curlHandle, Request $request)
 {
     curl_setopt($curlHandle, CURLOPT_URL, $request->getServiceUrl() . $request->getUri());
     $requestBody = '';
     $requestLength = 0;
     $requestVars = $request->getParameters();
     if (count($requestVars) > 0) {
         $requestBody = $this->buildPostBody($requestVars);
         $requestLength = strlen($requestBody);
     }
     $fh = fopen('php://memory', 'rw');
     fwrite($fh, $requestBody);
     rewind($fh);
     curl_setopt($curlHandle, CURLOPT_INFILE, $fh);
     curl_setopt($curlHandle, CURLOPT_INFILESIZE, $requestLength);
     curl_setopt($curlHandle, CURLOPT_PUT, true);
     $response = $this->doExecute($curlHandle, $request);
     fclose($fh);
     return $response;
 }
 public function __construct(Request $request)
 {
     $inParams = $request->getParameters(true);
     if (isset($inParams[3])) {
         $this->response = Response::fourOhFour();
         return;
     }
     if ($inParams[1] !== "forgotPassword") {
         $this->response = Response::fourOhFour();
         return;
     }
     $this->request = $request;
     $lockoutEngine = LockoutEngine::getInstance();
     if ($lockoutEngine->isLockedOut($_SERVER['REMOTE_ADDR'])) {
         $this->response = Response::redirect(new Link("users/login"));
         return;
     }
     if (isset($inParams[2])) {
         $this->secondStep($inParams[2]);
         return;
     }
     $this->forgotPasswordContent();
 }
Example #16
0
// DETERMINAR ENTORNO DE DESARROLLO O DE PRODUCCION
// ----------------------------------------------------------------
$_SESSION['EntornoDesarrollo'] = $rq->isDevelopment();
if ($rq->isOldBrowser()) {
    $controller = 'OldBrowser';
    $action = 'Index';
} else {
    //-----------------------------------------------------------------
    // INSTANCIAR UN OBJETO DE LA CLASE REQUEST PARA TENER DISPONIBLES
    // TODOS LOS VALORES QUE CONSTITUYEN LA PETICION E IDENTIFICAR
    // SI LA PETICION ES 'GET' O 'POST', ASI COMO EL CONTROLADOR Y
    // ACCION SOLICITADA.
    //-----------------------------------------------------------------
    switch ($rq->getMethod()) {
        case 'GET':
            $request = $rq->getParameters($app['path']);
            $request['METHOD'] = "GET";
            $controller = ucfirst($request[0]);
            $action = isset($request[1]) ? $request[1] : "";
            break;
        case 'POST':
            $request = $rq->getRequest();
            $request['METHOD'] = "POST";
            $controller = ucfirst($request['controller']);
            $action = $request['action'];
            break;
    }
    if (!$_SESSION['usuarioPortal']['Id']) {
        // No está logeado
        $controller = "Index";
        $action = "Login";
Example #17
0
 /**
  * Act as an internal constructor.
  * 
  * @param Request request, the request
  * @param Response response, the response
  */
 private function instantiate(Request $request, Response $response)
 {
     // class memebers
     $this->request = $request;
     $this->response = $response;
     $this->params = $request->getParameters();
     $this->logger = Registry::get('__logger');
     $this->injector = Registry::get('__injector');
     $this->config = Registry::get('__configurator');
     $this->session = $request->getSession();
     $this->app_path = $this->injector->getPath('__base');
     $this->template_root = $this->injector->getPath('views') . $this->params['controller'] . DIRECTORY_SEPARATOR;
     $this->template = ActionView::factory('php');
     // register session container if any
     // TODO: this should be moved elsewhere
     if ($this->config->getWebContext()->session !== NULL && $this->config->getWebContext()->session->container !== NULL) {
         // container location.
         $c_location = str_replace('.', DIRECTORY_SEPARATOR, (string) $this->config->getWebContext()->session->container) . '.php';
         include_once $c_location;
         // container class name.
         $e = explode('.', (string) $this->config->getWebContext()->session->container);
         // reflect on container.
         $container = new ReflectionClass(end($e));
         if ($container->implementsInterface('ISessionContainer')) {
             $this->session->setContainer($container->newInstance());
         }
     }
     // predefined variables:
     // TODO: check if we have a / at the end, if not, add one
     $this->template->assign('__base', (string) $this->config->getWebContext()->document_root);
     $this->template->assign('__server', (string) $this->config->getWebContext()->server_name);
     $this->template->assign('__controller', $this->params['controller']);
     $this->template->assign('__version', Medick::getVersion());
     $this->template->assign('__self', $this->__base . $this->request->getRequestUri());
     $this->logger->debug($this->request->toString());
 }
 public function testGetParameters()
 {
     $this->assertThat($this->object->getParameters(), $this->equalTo(array('get1' => 'value', 'post1' => 'another value')));
 }
Example #19
0
<?php

include_once '/var/www/html/Lux/Core/Helper.php';
$OUTPUT = new Output();
$REQUEST = new Request();
$document = $REQUEST->getParameters();
$OUTPUT->success(0, $document, null);
Example #20
0
 public function getCalendar()
 {
     date_default_timezone_set("Europe/Madrid");
     header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
     header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");
     header("Cache-Control: no-cache, must-revalidate");
     header("Pragma: no-cache");
     header("Content-Type: text/xml; charset=utf-8");
     $xml = '<?xml version="1.0" ?><response><content><![CDATA[';
     if (Request::getGetParam("event") != '') {
         //TODO: Write in a future some element to get events from the database
     } else {
         $month = 0;
         $year = 0;
         $event = 0;
         $params = Request::getParameters();
         if (isset($params["month"])) {
             $month = $params["month"]["value"];
         }
         if (isset($params["year"])) {
             $year = $params["year"]["value"];
         }
         if (isset($params["event"])) {
             $event = $params["event"]["value"];
         }
         if ($month == "1") {
             $time = time();
             $month = date("n", $time);
         }
         if ($year == "1") {
             $time = time();
             $year = date('Y', $time);
         }
         $month = intval($month);
         $year = intval($year);
         $date = getdate(mktime(0, 0, 0, $month, 1, $year));
         $today = getdate();
         $hours = $today['hours'];
         $mins = $today['minutes'];
         $secs = $today['seconds'];
         if (strlen($hours) < 2) {
             $hours = "0" . $hours;
         }
         if (strlen($mins) < 2) {
             $mins = "0" . $mins;
         }
         if (strlen($secs) < 2) {
             $secs = "0" . $secs;
         }
         $days = date("t", mktime(0, 0, 0, $month, 1, $year));
         $start = $date['wday'];
         $name = $date['month'];
         $year2 = $date['year'];
         $offset = $days + $start - 1;
         if ($month == 12) {
             $next = 1;
             $nexty = $year + 1;
         } else {
             $next = $month + 1;
             $nexty = $year;
         }
         if ($month == 1) {
             $prev = 12;
             $prevy = $year - 1;
         } else {
             $prev = $month - 1;
             $prevy = $year;
         }
         if ($offset <= 28) {
             $weeks = 28;
         } elseif ($offset > 35) {
             $weeks = 42;
         } else {
             $weeks = 35;
         }
         switch ($name) {
             case "January":
                 $aname = _("Enero");
                 break;
             case "February":
                 $aname = _("Febrero");
                 break;
             case "March":
                 $aname = _("Marzo");
                 break;
             case "April":
                 $aname = _("Abril");
                 break;
             case "May":
                 $aname = _("Mayo");
                 break;
             case "June":
                 $aname = _("Junio");
                 break;
             case "July":
                 $aname = _("Julio");
                 break;
             case "August":
                 $aname = _("Agosto");
                 break;
             case "September":
                 $aname = _("Septiembre");
                 break;
             case "October":
                 $aname = _("Octubre");
                 break;
             case "November":
                 $aname = _("Noviembre");
                 break;
             case "December":
                 $aname = _("Diciembre");
                 break;
         }
         $xml .= "<table class='cal' cellpadding='0' cellspacing='1'>\n                    <tr>\n                        <td colspan='7' class='calhead'>\n                            <table>\n                            <tr>\n                                <td>\n                                    <a href='javascript:navigate({$prev},{$prevy},\"\")' style='border:none'><img src='" . BASE_URL . "style/default/images/calLeft.gif' alt='prev' /></a> <a href='javascript:navigate(\"\",\"\",\"\")' style='border:none'><img src='" . BASE_URL . "style/default/images/calCenter.gif' alt='current' /></a> <a href='javascript:navigate({$next},{$nexty},\"\")' style='border:none'><img src='" . BASE_URL . "style/default/images/calRight.gif' alt='next' /></a> <a href='javascript:void(0)' onClick='showJump(this)' style='border:none'><img src='" . BASE_URL . "style/default/images/calDown.gif' alt='jump' /></a>\n                                </td>\n                                <td align='right' class='monthHead'>\n                                    {$aname} {$year2}\n                                </td>\n                            </tr>\n                            </table>\n                        </td>\n                    </tr>\n                    <tr class='dayhead'>\n                        <td>" . _("L") . "</td>\n                        <td>" . _("M") . "</td>\n                        <td>" . _("X") . "</td>\n                        <td>" . _("J") . "</td>\n                        <td>" . _("V") . "</td>\n                        <td>" . _("S") . "</td>\n                        <td>" . _("D") . "</td>\n                    </tr>";
         $col = 1;
         $cur = 1;
         $next = 0;
         for ($i = 1; $i <= $weeks; $i++) {
             if ($next == 3) {
                 $next = 0;
             }
             if ($col == 1) {
                 $xml .= "\n<tr class='dayrow'>";
             }
             $xml .= "\t<td valign='top' onMouseOver=\"this.className='dayover'\" onMouseOut=\"this.className='dayout'\">";
             if ($i <= $days + ($start - 1) && $i >= $start) {
                 if ($cur == $today["mday"] && $name == $today["month"] && $year2 == $today["year"]) {
                     $xml .= "<div class='day'><b style='color:#C00'>{$cur}</b></div>";
                 } else {
                     $xml .= "<div class='day'><b";
                     $xml .= ">{$cur}</b></div>";
                 }
                 //$xml.="<div class='calevent'><a href='javascript:navigate(\"\",\"\",\"".$row[0]."\")'>Event</a></div>";
                 $xml .= "\n\t</td>\n";
                 $cur++;
                 $col++;
             } else {
                 $xml .= "&nbsp;\n\t</td>\n";
                 $col++;
             }
             if ($col == 8) {
                 $xml .= "\n</tr>\n";
                 $col = 1;
             }
         }
         $xml .= "</table>";
     }
     $xml .= "]]></content></response>";
     print $xml;
 }
Example #21
0
 public function updateRolePermission(Request $request, Session $session, $view)
 {
     $service = new SecurityService();
     if (!$request->getParameter(SUBMIT_PARAM)) {
         $id = $request->getParameter('id');
         $info = $service->getRolePermissionById($id);
         $this->setAttribute('id', $id);
         $this->setAttribute('role_id', $request->getParameter('role_id'));
         $this->setAttribute('original_permission_handle', $info->permission);
         $this->setAttributes(get_object_vars($info));
         return new Template('update_role_permission');
     } else {
         $id = $request->getParameter('id');
         $roleId = $request->getParameter('role_id');
         $orginalPermissionHandle = $request->getParameter('original_permission_handle');
         $permission = $request->getParameter('permission');
         $info = $service->getRolePermissionByHandle($roleId, $permission);
         $permissionName = $info->permission;
         if (!empty($info) && strcmp($permissionName, $orginalPermissionHandle) != 0) {
             $result['response_code'] = -1;
             $result['message'] = 'This permission handle is taken. Please enter a different one.';
         } else {
             $responseCode = 1;
             self::$_logger->debug('pattern = ' . $request->getParameter('pattern'));
             $data = $request->getParameters(true);
             $service->updateRolePermission($id, $data);
             $result['response_code'] = $responseCode;
         }
         return $this->showJsonResponse($result);
     }
 }
Example #22
-1
 public function __construct(Request $request)
 {
     if (count($request->getParameters(true)) > 2) {
         $this->response = Response::fourOhFour();
         return;
     }
     $currentUser = CurrentUser::getUserSession();
     if (!$currentUser->isLoggedIn()) {
         $this->response = Response::fourOhFour();
         return;
     }
     $hookEngine = HookEngine::getInstance();
     $hookEngine->runAction('userIsLoggingOut');
     $currentUser->logOut();
     session_regenerate_id(true);
     $hookEngine->runAction('userLoggedOut');
     NoticeEngine::getInstance()->addNotice(new Notice("neutral", "You're now logged out."));
     $this->response = Response::redirect(new Link(""));
 }
Example #23
-1
 /**
  * Metodo para ejecutar la aplicacion.
  * 
  * Permite iniciar la aplicacion, analiza el objeto Request.
  * Valida que el controlador y la accion solicitada se puedan cargar de lo contrario genera
  * un error que luego es enviado al usuario.
  * 
  * @param Request $request
  * @throws Exception
  */
 public static function Run(Request $request)
 {
     $controllerName = '\\application\\controllers\\' . $request->getController() . 'Controller';
     $action = $request->getAction();
     $parameters = $request->getParameters();
     if (class_exists($controllerName)) {
         $controller = new $controllerName();
         if (is_callable(array($controller, $action))) {
             $action = $request->getAction();
         } else {
             throw new \core\AppException("Ruta no valida", 1002);
         }
         if (isset($parameters)) {
             call_user_func_array(array($controller, $action), $parameters);
         } else {
             call_user_func(array($controller, $action));
         }
     } else {
         throw new \core\AppException("Controlador solicitada no es valido.", 1002);
     }
 }
Example #24
-1
 public function __construct(Request $request)
 {
     if (count($request->getParameters(true)) > 2) {
         $this->response = Response::fourOhFour();
         return;
     }
     if (currentUser::getUserSession()->isLoggedIn()) {
         $this->response = Response::fourOhFour();
         return;
     }
     $lockoutEngine = LockoutEngine::getInstance();
     if ($lockoutEngine->isLockedOut($_SERVER['REMOTE_ADDR'])) {
         $minutesLeft = $this->minutesLeftInLockout();
         $this->response = new Response(403, "@users/lockedOut.twig", "Locked Out", "lockedOut", $minutesLeft);
         return;
     }
     if ($request->isPostRequest()) {
         $this->response = $this->doLogIn();
         return;
     }
     $this->response = new Response(200, "@users/login.twig", "Login", "login");
 }