Share
Embed
Transcript
29 slides
-
ࣗݾհ • ιʔγϟϧήʔϜ։ൃΤϯδχΞ • Laravelྺ2 (4.2, 5.0, 5.1LTS) • ࣾ༻ͷComposerϥΠϒϥϦ࡞ͬͨΓ
• Unityͱ͔ΫϥΠΞϯταΠυ৮Γ·͢ -
<?php require __DIR__.'/../bootstrap/autoload.php'; $app = require_once __DIR__.'/../bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class); $response = $kernel->handle( $request = Illuminate\Http\Request::capture() ); $response->send(); $kernel->terminate($request, $response); -
Kernel • ϒϥοΫϘοΫεʹΞϓϦέʔγϣϯશମΛૢ࡞͢ΔΫϥε • Http͔ConsoleϦΫΤετʹΑͬͯੜ͢ΔKernelΫϥε͕มΘΔ • handleϝιουͰΞϓϦέʔγϣϯͷ͋Ε͜ΕΛૢ࡞ • Env, Config,
Handler, Facade, Service ProviderͷॳظԽॲཧ • PipelineΫϥεΛ༻͠MiddlewareͷϋϯυϦϯάɾRouterͱ ControllerσΟεύονΛߦ͏ -
<?php namespace Illuminate\Foundation\Http; use Exception; use Throwable; use
Illuminate\Routing\Router; use Illuminate\Pipeline\Pipeline; use Illuminate\Support\Facades\Facade; use Illuminate\Contracts\Foundation\Application; use Illuminate\Contracts\Http\Kernel as KernelContract; use Symfony\Component\Debug\Exception\FatalThrowableError class Kernel implements KernelContract { protected $app; protected $router; protected $bootstrappers = [ 'Illuminate\Foundation\Bootstrap\DetectEnvironment', 'Illuminate\Foundation\Bootstrap\LoadConfiguration', 'Illuminate\Foundation\Bootstrap\ConfigureLogging', 'Illuminate\Foundation\Bootstrap\HandleExceptions', 'Illuminate\Foundation\Bootstrap\RegisterFacades', 'Illuminate\Foundation\Bootstrap\RegisterProviders', 'Illuminate\Foundation\Bootstrap\BootProviders', ]; // লུ } -
Application (Container) • αʔϏείϯςφͱͯ͠ΠϯελϯεͷཧΛߦ͏ • KernelͱผʹLog, Event, RoutingͷServiceProviderΛ ཧ͍ͯ͠Δ •
Laravelόʔδϣϯɺ.envϑΝΠϧ໊ΛϓϩύςΟʹ࣋ͭ • Kernel͔ΒґཔΛड͚ServiceProviderͷregisterΛݺͼ ग़͢ -
<?php namespace Illuminate\Foundation; use Closure; use RuntimeException; use
Illuminate\Support\Arr; use Illuminate\Support\Str; use Illuminate\Http\Request; use Illuminate\Container\Container; use Illuminate\Filesystem\Filesystem; use Illuminate\Log\LogServiceProvider; use Illuminate\Support\ServiceProvider; use Illuminate\Events\EventServiceProvider; use Illuminate\Routing\RoutingServiceProvider; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\Exception\HttpException; use Illuminate\Contracts\Http\Kernel as HttpKernelContract; use Illuminate\Foundation\Bootstrap\LoadEnvironmentVariables; use Symfony\Component\HttpFoundation\Request as SymfonyRequest; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Illuminate\Contracts\Foundation\Application as ApplicationContract; class Application extends Container implements ApplicationContract, HttpKernelInterface { /** * The Laravel framework version. * * @var string */ const VERSION = '5.4.21'; /** * The environment file to load during bootstrapping. * * @var string */ protected $environmentFile = ‘.env'; // লུ } -
Service Provider • αʔϏε(֤ػೳ)ʹಛԽͨ͠ॳظԽΫϥε • ओʹregister, bootϝιουͰߏ͞ΕΔ • registerίϯςφʹొ͢ΔͨΊͷϝιου •
bootregisterͷޙʹݺΕΔͨΊશͯͷ ServiceProviderʹΞΫηεͰ͖ΔɻArtisan vendor:publishͱ͔͜͜Ͱߦ͏ -
/** * Send the given request through the middleware
/ router. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ protected function sendRequestThroughRouter($request) { $this->app->instance('request', $request); Facade::clearResolvedInstance('request'); $this->bootstrap(); return (new Pipeline($this->app)) ->send($request) ->through($this->app->shouldSkipMiddleware() ? [] : $this->middleware) ->then($this->dispatchToRouter()); } -
/** * Run the route action and return the response.
* * @return mixed * * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException */ protected function runController() { return (new ControllerDispatcher($this->container)) ->dispatch( $this, $this->getController(), $this->getControllerMethod() ); } -
<?php namespace Illuminate\Http; use ArrayObject; use JsonSerializable; use
Illuminate\Contracts\Support\Jsonable; use Illuminate\Contracts\Support\Renderable; use Symfony\Component\HttpFoundation\Response as BaseResponse; class Response extends BaseResponse { use ResponseTrait; public function setContent($content) { $this->original = $content; if ($this->shouldBeJson($content)) { $this->header('Content-Type', 'application/json'); $content = $this->morphToJson($content); } elseif ($content instanceof Renderable) { $content = $content->render(); } return parent::setContent($content); }