laravel Æô¶¯Á÷³Ì
laravel ÊÇÒ»ÖÖÊ¢ÐÐµÄ php web ¿ª·¢¿ò¼Ü¡£ËüÌṩÁËÒ»ÖÖ¾«Á·¡¢Ò×ÓÚѧϰºÍʹÓõĿª·¢·½·¨¡£laravel µÄÆô¶¯Á÷³Ì°üÀ¨Á˶à¸ö°ì·¨£¬Ã¿¸ö°ì·¨¶¼ÓÐÆäÌض¨µÄ×÷Óá£ÔÚÄ»ºó£¬laravel ±³ºóµÄÊÂÇéÁ÷³ÌÊÇÖØ´óµÄ£¬µ« larevel µÄ¿ò¼ÜÉè¼ÆʹµÃÕû¸öÆô¶¯Á÷³Ì¸üΪ¼òÆÓÖ±¹Û¡£ÏÂÎĽ«ÏêϸÏÈÈÝ larevel µÄÆô¶¯Á÷³Ì¡£
Ò»¡¢¼ÓÔØ¿ò¼Ü½¹µã
Laravel µÄËùÓÐÆô¶¯Àú³Ì¶¼ÊÇͨ¹ý³ÌÐòÈë¿ÚÎļþ×îÏȵġ£Õû¸öÆô¶¯Á÷³Ì´Ó public/index.php Îļþ×îÏÈ¡£¸ÃÎļþΨһµÄ¹¦Ð§ÊǼÓÔØ Laravel ¿ò¼ÜµÄ½¹µãÎļþ¡£ÔÚ public/index.php ÖУ¬ÎÒÃÇ¿ÉÒÔ¿´µ½ÒÔÏ´úÂëƬ¶Ï£º
require __DIR__.'/../vendor/autoload.php'; $app = require_once __DIR__.'/../bootstrap/app.php';
µÇ¼ºó¸´ÖÆ
µÚÒ»ÐдúÂëÈÏÕæ¼ÓÔØ Composer ÌìÉúµÄ vendor Ŀ¼ÏµÄ×Ô¶¯¼ÓÔØÆ÷¡£¸Ã×Ô¶¯¼ÓÔØÆ÷ÎļþÔÚÔËÐÐʱ¶¯Ì¬µØ¼ÓÔØ¿ò¼ÜËùÐèµÄËùÓÐÒÀÀµ¡£
µÚ¶þÐÐÔòÈÏÕæ¼ÓÔØ Laravel Ó¦ÓóÌÐòµÄ½¹µã¡£¸ÃÐдúÂëͨ¹ýŲÓà bootstrap/app.php ÎļþÖÐµÄ bootstrap() º¯Êý·µ»ØÒ»¸öʵÀý»¯µÄÓ¦ÓóÌÐò¹¤¾ß $app¡£
¶þ¡¢ÔËÐÐ Bootstrap
bootstrap/app.php ÎļþÊÇ Laravel µÄÖ¸µ¼Îļþ¡£¸ÃÎļþ³õʼ»¯²¢ÉèÖøÿò¼ÜµÄÖÖÖÖЧÀͺÍ×é¼þ¡£±ðµÄ£¬¸ÃÎļþ»¹¼ÓÔØÁËÓ¦ÓóÌÐòµÄÉèÖá¢Â·ÓÉ¡¢ÖÐÑë¼þ¡¢Òì³£´¦Àí³ÌÐòµÈ¡£
ÔÚ bootstrap/app.php ÎļþÖУ¬ÎÒÃÇ¿ÉÒÔ¿´µ½ÒÔÏ´úÂëƬ¶Ï£º
$app = new IlluminateFoundationApplication( realpath(__DIR__.'/../') ); $app->singleton( IlluminateContractsHttpKernel::class, AppHttpKernel::class ); $app->singleton( IlluminateContractsConsoleKernel::class, AppConsoleKernel::class ); $app->singleton( IlluminateContractsDebugExceptionHandler::class, AppExceptionsHandler::class ); return $app;
µÇ¼ºó¸´ÖÆ
ÕâЩ´úÂëƬ¶Ï³õʼ»¯ÁËÓ¦ÓóÌÐòµÄ½¹µã£¬°üÀ¨£º
ʵÀý»¯Ò»¸ö Application ¹¤¾ß£¬¸Ã¹¤¾ßΪӦÓóÌÐòµÄ¿ØÖÆ̨ÔËÐÐʱºÍ HTTP ÔËÐÐʱÌṩ»ù´¡ÉèÊ©¡£
°ó¶¨ÖÖÖÖЧÀÍÌṩÕߣ¬Èç IlluminateContractsHttpKernel, IlluminateContractsConsoleKernel, ºÍ IlluminateContractsDebugExceptionHandler¡£
Èý¡¢¼ÓÔØЧÀÍÌṩÕß
ÎÒÃÇÔÚÉÏÒ»²½ÖÐÒѾÌáµ½Ó¦ÓÃÁËÈýÖÖЧÀÍÌṩÕß¡£Ð§ÀÍÌṩÕßÊÇ Laravel Ó¦ÓóÌÐòÄ£¿é»¯µÄ»ù´¡£¬ÈÏÕæΪӦÓóÌÐòµÄËùÓй¦Ð§ÌṩЧÀÍ¡£
ЧÀÍÌṩÕß±»½ç˵ÔÚ config/app.php ÎļþÖÐµÄ providers Êý×éÖУ¬¸ÃÊý×éÁгöÁËÓ¦ÓóÌÐòÖÐËùÓпÉÓõÄЧÀÍÌṩÕß¡£ÔÚÆô¶¯Ó¦ÓóÌÐòʱ£¬ Laravel ½«±éÀúËùÓеÄЧÀÍÌṩÕߣ¬²¢ÎªÖ®½¨Éèµ¥¸ö°ó¶¨¡£ÕâÑù£¬Ó¦ÓóÌÐòµÄÆäËû×é¼þ¾Í¿ÉÒÔÇáËɵػá¼ûËùÐèµÄЧÀÍ¡£
ÀýÈ磬ÈôÊÇÎÒÃÇÔÚ config/app.php ÎļþÖÐÌí¼ÓÒÔÏ´úÂëƬ¶Ï£º
'providers' => [ // ... AppProvidersCustomServiceProvider::class, // ... ],
µÇ¼ºó¸´ÖÆ
µ±Ó¦ÓóÌÐòÆô¶¯Ê±£¬ Laravel ʵÀý»¯²¢×¢²á AppProvidersCustomServiceProvider À࣬ÆäÒªÁìÓ¦·µ»ØÒ»¸öЧÀÍÈÝÆ÷ʵÀý¡£
ËÄ¡¢×Ô½ç˵Æô¶¯Âß¼
Laravel µÄ¿ò¼ÜÉè¼ÆʹµÃ×Ô½ç˵ӦÓóÌÐòÆô¶¯Á÷³ÌºÜÊÇÈÝÒס£¿ÉÒÔͨ¹ýÌí¼Ó×Ô½ç˵Âß¼À´ÔöÇ¿Ó¦ÓóÌÐòµÄ¹¦Ð§ºÍÐÔÄÜ¡£
ÔÚ bootstrap/app.php ÎļþÖУ¬ÓÐһЩԤ½ç˵µÄÆô¶¯Âß¼£¬ÈçÒÔÏ´úÂëƬ¶Ï£º
$app->registerCoreContainerAliases();
µÇ¼ºó¸´ÖÆ
ÈôÊÇÏ£ÍûÌí¼Ó×Ô½ç˵µÄÆô¶¯Âß¼£¬¿ÉÒÔÔÚ bootstrap/app.php ÎļþĩβÌí¼Ó´úÂë¡£ÀýÈ磬ÔÚÆô¶¯Ê±¿ÉÒÔΪӦÓóÌÐòÌí¼Ó×Ô½ç˵ÉèÖãº
$config = new MyCustomConfiguration(); $config->load();
µÇ¼ºó¸´ÖÆ
Îå¡¢Æô¶¯ HTTP / Console ÄÚºË
½ÓÏÂÀ´£¬Ó¦ÓóÌÐòÆô¶¯ HTTP Äں˻ò¿ØÖÆ̨Äںˣ¬ÕâÈ¡¾öÓÚÓ¦ÓóÌÐò½«ÔõÑùʹÓá£ÔÚ bootstrap/app.php ÎļþÖУ¬ÎÒÃÇÉèÖÃÁËÕâÁ½¸öÄںˣº
$app->singleton( IlluminateContractsHttpKernel::class, AppHttpKernel::class ); $app->singleton( IlluminateContractsConsoleKernel::class, AppConsoleKernel::class );
µÇ¼ºó¸´ÖÆ
ÏÖÔÚ£¬Ó¦ÓóÌÐòÒѾ׼±¸Í£µ±£¬¿ÉÒÔƾ֤ÐèÒªÆô¶¯¿ØÖÆ̨»ò HTTP ÔËÐÐʱ¡£ÔÚ Laravel ÖУ¬¿ÉÒÔͨ¹ý Artisan ÏÂÁîÐй¤¾ßÆô¶¯¿ØÖÆ̨£¬Ò²¿ÉÒÔÔÚÉèÖÃµÄ Web ЧÀÍÆ÷ÉÏÔËÐÐËüÀ´Æô¶¯ HTTP ÔËÐС£
Áù¡¢Ö´ÐÐÏìÓ¦ÇëÇó
ÈôÊÇÆô¶¯ HTTP »ù´¡¼Ü¹¹£¬µ±Óû§»á¼ûÓ¦ÓóÌÐòʱ£¬ÇëÇ󽫽øÈë Laravel ½¹µãµÄ public/index.php Îļþ¡£¸ÃÎļþͨ¹ý·ÓÉϵͳ½«ÇëÇóת´ïµ½×¼È·µÄ¿ØÖÆÆ÷ÒªÁì¡£
×ܵÄÀ´Ëµ£¬Laravel µÄÆô¶¯Á÷³ÌÉæ¼°Ðí¶à°ì·¨£¬´Ó¼ÓÔØ¿ò¼Ü½¹µã×îÏÈ£¬²¢Í¨¹ýЧÀÍÌṩÕß¡¢×Ô½ç˵Æô¶¯Âß¼ÒÔ¼°¿ØÖÆ̨ºÍ HTTP Äں˳ÌÐòÆô¶¯µÄÀú³Ì¡£ÕâÖÖÁ÷³ÌʽÉè¼ÆʹµÃ Laravel ÊÇÒ»ÖÖºÜÊÇÎÞа¡¢¿É¶¨ÖÆÇÒÒ×ÓÚʹÓõĿò¼Ü£¬ÊÊÓÃÓÚÖÖÖÖ¹æÄ£µÄÓ¦ÓóÌÐò¿ª·¢¡£
ÒÔÉϾÍÊÇlaravel Æô¶¯Á÷³ÌµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡