public function testParams() { $request = new Request(); $params = array('id' => '1', 'text' => 'test'); $request->params($params); $this->assertEquals($params, $request->params()); $this->assertEquals($params['id'], $request->params('id')); }
public function setUp() { $_POST = array(); $_GET = array(); WaxUrl::$params = false; Request::$params = false; }
function execute() { $user = connectionUserModel::create()->getInfo((int) Request::params('user_id')); if (!$user || !isset($user['avatar'])) { $this->notFound(); } $file = connectionUserPhotoModel::create()->getImageSize((int) $user['avatar']['id'], (int) Request::params('user_id'), (int) Request::params('photo_size')); $this->showFile($file); }
public function init() { if (!self::$init) { self::$get = WaxUrl::get_params(); self::$post = $_POST; self::$params = array_merge(self::$get, self::$post); self::$init = true; } }
public function testShoudGetParams() { $_GET = ['city' => 'city A']; $this->assertEquals(['paginate' => false, 'page' => 1, 'offset' => $this->object->getDefaultOffset(), 'filter' => ['city' => ['=' => ['city A']]], 'embed' => [], 'sort' => [], 'search' => ''], $this->object->params()); $this->object->set('add', ['city' => 'city B']); $this->assertEquals(['paginate' => false, 'page' => 1, 'offset' => $this->object->getDefaultOffset(), 'filter' => ['city' => ['=' => ['city A', 'city B']]], 'embed' => [], 'sort' => [], 'search' => ''], $this->object->params()); // passing true should discart changes made with 'set' $this->assertEquals(['paginate' => false, 'page' => 1, 'offset' => $this->object->getDefaultOffset(), 'filter' => ['city' => ['=' => ['city A']]], 'embed' => [], 'sort' => [], 'search' => ''], $this->object->params(true)); }
function execute() { $id = Request::params('id'); $model = new connectionUserAttachmentModel(); $file = $model->getFile($id, Request::params('size') ? (int) Request::params('size') : false); if ($file) { $this->showFile($file); } else { $this->notFound(); } }
function execute() { $user = ConnectionHelper::userLogin(); $id = Request::params('video_id'); if (!$id) { return array('status' => 'error', 'message' => '[`Title error view video not found`]'); } $video = connectionUserVideoModel::create()->where(array('id' => (int) $id))->fetchOne(); if (!$video) { return array('status' => 'error', 'message' => '[`Title error view video not found`]'); } if ($video['status'] != 'published' && $video['user'] != $user['id']) { return array('status' => 'error', 'message' => '[`Title error view video not permission`]'); } $file = '/me-uploads/connection/user_video/user' . $video['user'] . '/' . $video['id'] . '/video.flv'; return array('status' => 'success', 'file' => $file, 'title' => $video['title']); }
private static function parseRoute($route) { $route = substr($route, 0, 1) != '/' ? String::glue('/', $route) : $route; $route = substr($route, -1) != '/' ? String::glue($route, '/') : $route; $result = array(); preg_match_all('/\\<(.*)\\>/U', $route, $matches); if (sizeof($matches[1]) > 0) { foreach ($matches[1] as $param) { $result['params'][] = $param; $route = str_replace(String::glue('<', $param, '>'), '(.*)', $route); } } $result['route'] = String::glue('/^', str_replace('/', '\\/', $route), '' . (Request::params('app') ? '$' : '') . '/U'); return $result; }
/** * Executes a route handler. * * @param array|string $route array('controller','method') or array('controller') * or 'method' * @param Request $req * @param Response $res * @param array $args * * @throws Exception when the route cannot be resolved. * * @return Response */ public function resolve($route, $req, $res, array $args) { $result = false; if (is_array($route) || is_string($route)) { // method name and controller supplied if (is_string($route) && $req->params('controller')) { $route = [$req->params('controller'), $route]; // method name supplied } elseif (is_string($route)) { $route = [$this->defaultController, $route]; // no method name? fallback to the index() method } elseif (count($route) == 1) { $route[] = $this->defaultAction; } list($controller, $method) = $route; $controller = $this->namespace . '\\' . $controller; if (!class_exists($controller)) { throw new \Exception("Controller does not exist: {$controller}"); } $controllerObj = new $controller(); // give the controller access to the DI container if (method_exists($controllerObj, 'setApp')) { $controllerObj->setApp($this->app); } // collect any preset route parameters if (isset($route[2])) { $params = $route[2]; $req->setParams($params); } $result = $controllerObj->{$method}($req, $res, $args); } elseif (is_callable($route)) { $result = call_user_func($route, $req, $res, $args); } if ($result instanceof View) { $res->render($result); } return $res; }
/** * Test the params/get/put/post functions for retrieving input data. * * Pre-conditions: * Data is present in input arrays (POST, GET, COOKIE, etc) * * Post-conditions: * Requested data is returned if it is present, otherwise null. */ public function testParamFunctions() { $_GET = array('get_foo' => 'get_bar'); $_POST = array('post_foo' => 'post_bar'); $_COOKIE = array('cookie_foo' => 'cookie_bar'); $_SERVER['REQUEST_URI'] = ''; $request = new Request(); $this->assertEquals($request->params('get_foo'), 'get_bar'); $this->assertEquals($request->params('post_foo'), 'post_bar'); $this->assertNull($request->params('null')); $this->assertEquals($request->get(), $_GET); $this->assertEquals($request->post(), $_POST); $this->assertEquals($request->get('get_foo'), 'get_bar'); $this->assertEquals($request->post('post_foo'), 'post_bar'); $this->assertEquals($request->cookie('cookie_foo'), 'cookie_bar'); $this->assertEquals($request->header('HOST'), 'slim'); // Handle overriding PUT $_POST = array('put_foo' => 'put_bar', '_METHOD' => 'PUT'); $request = new Request(); $this->assertEquals($request->put('put_foo'), 'put_bar'); $this->assertEquals($request->put(), array('put_foo' => 'put_bar')); }
static function parse_request() { self::$params = new RequestParams(); # Get method self::$method = $_SERVER['REQUEST_METHOD']; self::$remote_ip = $_SERVER['REMOTE_ADDR']; if (self::$method === 'POST') { self::$post = true; } elseif (self::$method === 'GET') { self::$get = true; } self::$abs_url =& $_SERVER['REQUEST_URI']; self::$url = preg_replace('~\\?.*~', '', $_SERVER['REQUEST_URI']); if (!System::$conf->php_parses_routes) { if (empty($_GET['URLtoken'])) { exit_with_status(404); die('Impossible to find route. Bad htaccess config?'); } # $_GET is filled with parameters from htaccess. # Parse them accordingly and fill $_GET with url parameters. list($_GET['controller'], $_GET['action']) = explode('@', $_GET['URLtoken']); empty($_GET['controller']) && exit_with_status(404); empty($_GET['action']) && ($_GET['action'] = 'index'); unset($_GET['URLtoken']); foreach ($_GET as $param => $value) { if (!property_exists('Request', $param)) { continue; } self::${$param} = $value; unset($_GET[$param]); } empty(self::$format) && (self::$format = 'html'); # Parse GET params from $abs_url if (!is_bool(strpos(self::$abs_url, '?'))) { $get_params = urldecode(substr(self::$abs_url, strpos(self::$abs_url, '?') + 1)); $get_params = explode('&', $get_params); foreach ($get_params as $gp) { $param = explode('=', $gp); if (empty($param[0]) || empty($param[1])) { continue; } $_GET[$param[0]] = $param[1]; } } } # Get post/get parameters add_props(self::$params, $_GET, false); add_props(self::$params, $_POST, false); self::$get_params =& $_GET; self::$post_params =& $_POST; }