Dispatch the request to the application.
public static dispatch ( Illuminate\Http\Request $request ) : Illuminate\Http\Response | ||
$request | Illuminate\Http\Request | |
Результат | Illuminate\Http\Response |
public function bootstrap() { $this->constant(); //加载服务配置项 $servers = (require __DIR__ . '/service.php'); $config = (require ROOT_PATH . '/system/config/service.php'); $servers['providers'] = array_merge($config['providers'], $servers['providers']); $servers['facades'] = array_merge($config['facades'], $servers['facades']); $this->servers = $servers; //自动加载系统服务 Loader::register([$this, 'autoload']); //绑定核心服务提供者 $this->bindServiceProvider(); //添加初始实例 $this->instance('App', $this); //设置外观类APP属性 ServiceFacade::setFacadeApplication($this); //启动服务 $this->boot(); //定义错误/异常处理 Error::bootstrap(); //命令行模式 IS_CLI and die(Cli::bootstrap()); //导入类库别名 Loader::addMap(c('app.alias')); //自动加载文件 Loader::autoloadFile(); //开启会话 Session::start(); //执行全局中间件 Middleware::globals(); //解析路由 Route::dispatch(); }
/** * 解析路由 * * @return bool */ private function parseRoute() { //导入路由 require 'System/routes.php'; //分析处理 return Route::dispatch(); }
public function analyse() { $query = Input::get('q'); $analysisData = new stdClass(); $analysisData->keyword = $query; $analysisData->posts = array(); $analysisData->tools = array('all'); $postsRetrievers = array(new FacebookPostsRetriever(), new TwitterPostsRetriever()); foreach ($postsRetrievers as $postsRetriever) { $posts = $postsRetriever->retrieve($query, null); $analysisData->posts = array_merge($analysisData->posts, $posts); } $analysisDataJSON = json_encode($analysisData); // $response = Unirest::post("http://service/analyzer", // array( "Accept" => "application/json" ), // array('query' => $analysisDataJSON) // ); $request = Request::create('/service/analyzer', 'POST', array('query' => $analysisDataJSON)); Request::replace($request->input()); $response = Route::dispatch($request)->getContent(); // $analysisResult = json_decode($response->raw_body); $analysisResult = json_decode($response); foreach ($analysisResult->posts as $post) { foreach ($analysisData->posts as $postData) { if ($postData['id'] == $post->id) { $post->data = $postData; break; } } } return View::make('AnalysisResult')->with('analysisResult', $analysisResult); }
/** * 解析路由 * * @return bool */ private function parseRoute() { //导入路由 require APP_PATH . '/routes.php'; //分析处理 return Route::dispatch(); }
/** * Execute the console command. * * @return mixed */ public function fire() { $request = Request::create('/api/blocknotify', 'GET', array('secret' => !$this->option('secret') ? Config::get('bitcoin.callback_secret') : $this->option('secret'), 'blockhash' => $this->option('blockhash'))); Request::replace($request->input()); $response = Route::dispatch($request)->getContent(); if ($this->option('debug')) { $this->info($response); } }
public function __construct() { $route = new Route(); require_once "/../Routes.php"; $route->dispatch(); $render = $route->result(); if (is_array($render)) { echo json_encode($render); } else { echo $render; } }
public function bootstrap() { define('IS_CLI', PHP_SAPI == 'cli'); define('NOW', $_SERVER['REQUEST_TIME']); define('__ROOT__', IS_CLI ? '' : trim('http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_NAME']), '/\\')); IS_CLI or define('IS_GET', $_SERVER['REQUEST_METHOD'] == 'GET'); IS_CLI or define('IS_POST', $_SERVER['REQUEST_METHOD'] == 'POST'); IS_CLI or define('IS_DELETE', $_SERVER['REQUEST_METHOD'] == 'DELETE' ? TRUE : isset($_POST['_method']) && $_POST['_method'] == 'DELETE'); IS_CLI or define('IS_PUT', $_SERVER['REQUEST_METHOD'] == 'PUT' ? TRUE : isset($_POST['_method']) && $_POST['_method'] == 'PUT'); IS_CLI or define('IS_AJAX', isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'); IS_CLI or define('IS_WEIXIN', isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== FALSE); IS_CLI or define('__URL__', trim('http://' . $_SERVER['HTTP_HOST'] . '/' . trim($_SERVER['REQUEST_URI'], '/\\'), '/')); IS_CLI or define("__HISTORY__", isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : ''); //加载服务配置项 $servers = (require __DIR__ . '/service.php'); $config = (require ROOT_PATH . '/system/config/service.php'); $servers['providers'] = array_merge($config['providers'], $servers['providers']); $servers['facades'] = array_merge($config['facades'], $servers['facades']); $this->servers = $servers; //自动加载系统服务 Loader::register([$this, 'autoload']); //绑定核心服务提供者 $this->bindServiceProvider(); //添加初始实例 $this->instance('App', $this); //设置外观类APP属性 ServiceFacade::setFacadeApplication($this); //定义错误/异常处理 Error::bootstrap(); //导入类库别名 Loader::addMap(c('app.alias')); //自动加载文件 Loader::autoloadFile(); //启动服务 $this->boot(); //CLI模式 $this->cli(); //应用开始中间件 \Middleware::exe('app_start'); //解析路由 Route::dispatch(); //记录日志 Log::save(); //中间件 \Middleware::exe('app_end'); }
public function __construct($app) { $this->app = $app; //设置字符集 header("Content-type:text/html;charset=" . Config::get('app.charset')); //时区 date_default_timezone_set(Config::get('app.timezone')); //路由处理 Route::dispatch(); //导入钓子 $app['Hook']->import(Config::get('hook')); //定义常量 $this->DefineConsts(); //执行控制器方法 $this->ExecuteAction(); //保存日志 Log::save(); }
/** * Metodo para crear request entre controladores * * @param type $url Metodo destino * @param type $method Metodo de envio (GET o POST) * @param type $data Arreglo de datos * @param type $json Si el retorno es json o array * @return type JSON o ARRAY */ public static function ruta($url, $method, $data, $json = true) { //Datos enviados, vector Input::replace($data); //Crea Request via GET o POST $request = Request::create($url, $method); //Obtener response $response = Route::dispatch($request); //Solo contenido, en formato json $content = $response->getContent(); if ($json) { //Retorna formato JSON return $content; } else { //Retorna un arreglo return json_decode($content); } }
public function release($url, $method = 'GET', $input, $no_json) { // Store the original input of the request $originalInput = \Request::input(); // Create request to the API, adding the no-json parameter, since it's an internal request $request = \Request::create($url, $method); // Replace the input with the request instance input \Request::replace($input); // Fetch the response if ($no_json) { $content = \Route::dispatch($request)->getContent(); $result = json_decode($content, 1); } else { $result = \Route::dispatch($request)->getContent(); } // Replace the input again with the original request input. \Request::replace($originalInput); return $result; }
public function cargarDatos() { $request = Request::create('/estados', 'GET', array()); $estados = Route::dispatch($request)->original; return View::make('completar', array('nombre' => Input::get('nombre'), 'cotizacion_id' => Input::get('cotizacion_id'), 'pago' => Input::get('pago'), 'cobertura' => Input::get('cobertura'), 'formato' => Input::get('formato'), 'descripcion' => Input::get('descripcion'), 'estados' => $estados, 'tipo' => Input::get('tipo'), 'claveInterna' => Input::get('clave-interna'), 'modelo' => Input::get('modelo'), 'recibos' => Input::get('recibos'))); }
/** * Batch Operations * https://parse.com/docs/rest/guide#objects-batch-operations * * @return \Illuminate\Http\JsonResponse */ public function batch() { $requests = json_decode(file_get_contents('php://input')); $output = array(); foreach ($requests->requests as $request) { $url = parse_url($request->path); $query = array(); if (isset($url['query'])) { parse_str($url['query'], $query); } $body = isset($request->body) ? json_encode($request->body) : null; self::$currentRequest = \Request::create($request->path, $request->method, $query, array(), array(), array(), $body); $result = json_decode(\Route::dispatch(self::$currentRequest)->getContent()); if (!property_exists($result, 'error')) { $output[] = array("success" => $result); } else { $output[] = array("error" => $result); } } return \Response::json($output); }
| Here is where you will register all of the routes in an application. | It's a breeze. Simply tell Laravel the URIs it should respond to | and give it the controller to call when that URI is requested. | */ Route::group(['middleware' => ['api', 'web']], function ($account) { Route::get('/', function () { return 'Welcome to application'; }); //Route::get('/', function(){ // return redirect('/home'); //}); Route::get('/posts', function () { $token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJkb21haW4iOiJ0cmF2ZWwuY29tIiwic3ViIjoxLCJpc3MiOiJodHRwOlwvXC90cmF2ZWwuY29tXC9hcGlcL3YxXC9hdXRoZW50aWNhdGUiLCJpYXQiOjE0NTU2OTM2MDcsImV4cCI6MTQ1NTY5NzIwNywibmJmIjoxNDU1NjkzNjA3LCJqdGkiOiI3NTM0M2YzYTEyYTg1NGI2ZmI5Yjc0MWY2ZDFhYzQ1ZiJ9.3nGMHHXALcOGKPqiiuKqrAmxaJnUQasg1HX3pfYGZyA'; $request = Request::create(Request::root() . '/api/v1/posts', 'GET', ['token' => $token]); $response = Route::dispatch($request)->getData(); $result = json_decode(json_encode($response), true); echo '<pre>'; print_r($result); //return $result; }); }); Route::group(['prefix' => 'api/v1', 'middleware' => ['cors', 'api.jwt']], function () { Route::resource('authenticate', 'AuthenticateController', ['only' => ['index']]); Route::post('authenticate', 'AuthenticateController@authenticate'); Route::get('authenticate/user', 'AuthenticateController@getAuthenticatedUser'); Route::get('refresh_token', 'AuthenticateController@refresh_token'); // Api calls Route::resource('posts', 'Api\\V1\\postsController'); Route::get('my_posts', 'Api\\V1\\postsController@getUserPosts'); });
public function postAuthForm() { //delegate to default api function $request = \Request::create(\URL::route('api.auth.auth'), 'POST', \Input::all()); return \Route::dispatch($request); }
protected static function requestOriginalApi($uri, $method = 'GET', $params = array()) { $request = Request::create($uri, $method, $params); $response = Route::dispatch($request)->getContent(); return $response; }
/** * @dataProvider dispatchProvider * * @covers Route::dispatch * * @param array $config * @param string $controller * @param string $action * @param Request $request * @param string $expectedException * @param integer $expectedExceptionCode * * @throws Exception */ public function testDispatch(array $config, $controller, $action, Request $request, $expectedException = false, $expectedExceptionCode = false) { $db = 'database'; $route = new Route($controller, $action); try { $this->assertEquals('val', $route->dispatch($request, $db, $config)); } catch (Exception $ex) { if (!$expectedException) { throw $ex; } $this->assertInstanceOf($expectedException, $ex); if ($expectedExceptionCode !== false) { $this->assertEquals($expectedExceptionCode, $ex->getCode()); } } }
public function send() { try { Route::dispatch($this->response)->send(); } catch (Illuminate\Database\Eloquent\ModelNotFoundException $e) { echo view('errors.404'); } catch (Exception $e) { echo view('errors.500'); } }
private function denyRequest() { // Store return path to allow redirect after auth, ... \Session::put('laraguard_lastDenied', $this->request->decodedPath()); \Session::put('laraguard_lastDeniedLifetime', $this->permissionParser->getDeniedUrlLifetime()); // Redirect to permissionDenied method of controller if ($this->requestParser->hasControllerPermissionDeniedMethod()) { // Modify request action to direct to method 'permissionDenied' $action = $this->request->route()->getAction(); $controllerPath = $this->requestParser->getControllerPath(); $action['uses'] = $controllerPath . '@permissionDenied'; $action['controller'] = $controllerPath . '@permissionDenied'; // Set new action $this->request->route()->setAction($action); if ($this->permissionParser->debugging()) { \Log::info('[Laraguard] DENY - with permissionDenied(): ' . $action['uses']); } return \Route::dispatch($this->request); } else { if ($this->permissionParser->hasNoPermissionRoute()) { $noPermissionRoute = $this->permissionParser->getNoPermissionRoute(); if ($this->permissionParser->debugging()) { \Log::info('[Laraguard] DENY - with defaultNoPermissionRoute: ' . $noPermissionRoute); } return redirect($noPermissionRoute); } else { if ($this->permissionParser->debugging()) { \Log::info('[Laraguard] DENY - with 501 Error'); } return $this->returnError(['Permission denied']); } } }
function getCity($id = '') { $request = Request::create('api/ongkir/city/' . $id, 'GET'); return Route::dispatch($request)->getContent(); }
public function testFirstPageView() { // Register fake named route Route::any('/foobar', function () { return 'hello world'; }); $headers = Request::instance()->server->getHeaders(); $request = Request::create('http://localhost/foobar', 'get', [], [], [], $headers); Route::dispatch($request); $ab = App::make('ab'); $ab->track($request); $ab->experiment(); $this->assertEquals(1, Experiment::find('a')->visitors); $this->assertEquals(0, Experiment::find('a')->engagement); }
protected function seedWithRequest($http_type, $uri, array $params) { $request = Request::create($uri, $http_type, $params); // Replace the input with your request instance input Request::replace($request->input()); Route::dispatch($request)->getContent(); }
<?php require 'config/init.php'; Route::dispatch();
public function testRoutePostLaraeval() { $code = <<<CODE echo "Foo Bar"; CODE; $post = array('code' => $code); Input::merge($post); $request = Request::create('/laraeval', 'POST', $post); $content = Route::dispatch($request)->getContent(); // check the response content, it should containts string 'Foo Bar' // inside the div output $this->assertGreaterThan(0, strpos($content, '<div id="output" tabindex="0">Foo Bar</div>')); }