laravel prs4¼ÓÔØÒªÁì
laravelÊÇÒ»ÖÖÏÖ´úµÄphp¿ò¼Ü£¬Ëü¾ßÓÐÐí¶àÉÁ¿ª·¢±äµÃÔ½·¢¸ßЧºÍÇáÓ¯µÄ¹¦Ð§¡£ÆäÖÐÒ»¸öÌØÊâÓÐÓõĹ¦Ð§ÊÇprs-4£¨psr-4£©¼ÓÔØÒªÁì¡£ÔÚ±¾ÎÄÖУ¬ÎÒÃǽ«ÉîÈë̽ÌÖlaravelÖеÄprs-4¼ÓÔØÒªÁìÒÔ¼°ÔõÑùʹÓÃËüÀ´ÖÎÀíÎÒÃǵÄÓ¦ÓóÌÐòµÄÀàÎļþ¡£
ʲôÊÇPRS-4¼ÓÔØÒªÁ죿
PRS-4£¨PSR-4£©ÊÇPHP±ê×¼»¯ÕûÌ壨PHP-FIG£©Ìá³öµÄÒ»ÖÖ×Ô¶¯¼ÓÔØÆ÷¹æ·¶¡£Õâ¸ö¹æ·¶Ê¹µÃÎÒÃÇ¿ÉÒÔ±ãÍâµØ¼ÓÔØÀàÎļþ£¬¶ø²»±ØÊÖ¶¯°üÀ¨Ã¿Ò»¸öÀàÎļþ¡£
PRS-4µÄʵÏÖÒªÁìÊÇͨ¹ý½«ÃüÃû¿Õ¼äÓëÏÖʵ·¾¶Ó³ÉäÆðÀ´¡£ÕâÑù£¬µ±ÐèÒª¼ÓÔØÒ»¸öÀàʱ£¬ÏµÍ³ÖªµÀËüÔÚÄÇÀïÕÒµ½¡£
Laravel½ÓÄÉPRS-4¹æ·¶À´×Ô¶¯¼ÓÔØÀ࣬ÕâʹµÃÎÒÃDz»ÐèÒªÔÚ´úÂëÖÐÊÖ¶¯°üÀ¨Ã¿Ò»¸öÀàÎļþ¡£
LaravelÖÐÔõÑùʵÏÖPRS-4¼ÓÔØÒªÁ죿
Laravelͨ¹ýComposerÖеÄautoload¹¦Ð§À´ÊµÏÖPRS-4¹æ·¶µÄ×Ô¶¯¼ÓÔØÀà¡£ComposerÊÇPHPÖÐÓÃÓÚÒÀÀµÖÎÀíµÄ¹¤¾ß£¬Ëü¿ÉÒÔÇáËɵؼÓÔØ¡¢ÖÎÀíºÍ¸üÐÂÏîÄ¿µÄÒÀÀµÏî¡£
ÔÚÎÒÃǵÄLaravelÓ¦ÓóÌÐòÖУ¬ÎÒÃǽ«Í¨¹ýComposerÀ´½ç˵×Ô¶¯¼ÓÔØÀàµÄ¹æÔò¡£Composer»á½«ÎÒÃÇÖ¸¶¨µÄ¹æÔòÓ³Éäµ½ÏÖʵµÄ·¾¶£¬ÕâЩ¹æÔò½«ÓÃÓÚ×Ô¶¯¼ÓÔØÎÒÃǵÄÀàÎļþ¡£
ÏÂÃæÊÇÒ»¸öÔÚLaravelÖÐÆôÓÃPRS-4¹æ·¶µÄʾÀý¡£ÎÒÃÇÊ×ÏÈÐèÒª½ç˵ÎÒÃǵÄÃüÃû¿Õ¼äÓëÀàÎļþÏÖʵ´æ´¢µÄÎļþ·¾¶Ö®¼äµÄÓ³Éä¹Øϵ¡£
ÎÒÃÇ¿ÉÒÔÔÚcomposer.jsonÎļþÖÐʹÓÃautoloadÊôÐÔ½çËÃ÷ÈÕâЩӳÉä¹Øϵ¡£ÀýÈ磬ÏÂÃæÊǽç˵½«AppÃüÃû¿Õ¼äÓ³Éäµ½appĿ¼µÄÒªÁ죺
"autoload": { "psr-4": { "App\": "app/" } }
µÇ¼ºó¸´ÖÆ
ÔÚÉÏÃæµÄÀý×ÓÖУ¬ÎÒÃǽ«AppÃüÃû¿Õ¼äÓ³Éäµ½ÁËÎÒÃÇLaravelÓ¦ÓóÌÐòµÄappĿ¼¡£ÕâÒâζ×Å£¬µ±ÎÒÃÇÐèÒª¼ÓÔØÒ»¸öAppÃüÃû¿Õ¼äϵÄÀàʱ£¬Laravel½«»á×Ô¶¯¼ÓÔØλÓÚappĿ¼ÏµÄÏà¹ØÀàÎļþ¡£
ÔõÑùÔÚLaravelÖÐʹÓÃPRS-4¼ÓÔØÒªÁ죿
Ò»µ©ÎÒÃÇÔÚcomposer.jsonÎļþÖнç˵ÁË×Ô¶¯¼ÓÔعæÔò£¬Laravel½«»á×Ô¶¯¼ÓÔØÎÒÃÇÓ¦ÓóÌÐòÖеÄÀàÎļþ¡£
ÀýÈ磬ÈôÊÇÎÒÃÇÏëÒª½¨ÉèÒ»¸öÔÚAppÃüÃû¿Õ¼äϵÄUserControllerÀ࣬ÎÒÃÇ¿ÉÒÔÔÚappĿ¼Ï½¨ÉèÒ»¸öÃûΪUserController.phpµÄÎļþ£¬²¢ÔÚÎļþÖнç˵ÀàµÄÃüÃû¿Õ¼ä£º
<?php namespace App; class UserController { // ... }
µÇ¼ºó¸´ÖÆ
ÔÚÕâ¸öÀý×ÓÖУ¬ÎÒÃÇÔÚAppÃüÃû¿Õ¼äÖнç˵ÁËÒ»¸öUserControllerÀà¡£ÓÉÓÚÎÒÃÇÒѾÔÚcomposer.jsonÎļþÖнç˵ÁËÃüÃû¿Õ¼äÓëÏÖʵ·¾¶µÄÓ³Éä¹æÔò£¬Laravel½«»á×Ô¶¯¼ÓÔØÕâ¸öÀàÎļþ¡£
ΪÁËʹÓÃÕâ¸öÀ࣬ÎÒÃÇÖ»ÐèÒªÔÚÎÒÃǵÄÆäËû´úÂëÖÐʹÓÃAppUserControllerÀàÃû¼´¿É£º
$userController = new AppUserController();
µÇ¼ºó¸´ÖÆ
Laravel½«»á×Ô¶¯¼ÓÔØUserControllerÀ࣬²¢ÇÒÎÒÃDz»ÐèÒªÊÖ¶¯°üÀ¨Ïà¹ØÀàÎļþ¡£
×ܽá
ʹÓÃPRS-4×Ô¶¯¼ÓÔØÆ÷¹æ·¶¿ÉÒÔÈÃÎÒÃǵÄLaravelÓ¦ÓóÌÐòÔ½·¢ÓÐÓõØÖÎÀíÀàÎļþ¡£ÎÒÃÇ¿ÉÒÔʹÓÃcomposer.jsonÎļþÖеÄautoloadÊôÐÔÀ´½ç˵ÃüÃû¿Õ¼äÓëÏÖʵ·¾¶Ö®¼äµÄÓ³Éä¹Øϵ£¬²¢ÇÒLaravel½«»á×Ô¶¯¼ÓÔØÏìÓ¦µÄÀàÎļþ¡£
µ±ÎÒÃÇÐèÒª¼ÓÔØÒ»¸öÀàʱ£¬Laravel½«»á×Ô¶¯µ½½ç˵µÄÓ³Éä¹ØϵÖÐÑ°ÕÒÏà¹ØµÄÀàÎļþ£¬²¢ÇÒ½«ËüÃǼÓÔؽøÄÚ´æ¡£
ÔÚLaravelÖÐʹÓÃPRS-4×Ô¶¯¼ÓÔØÆ÷¹æ·¶£¬¿ÉÒÔʹÎÒÃǵĿª·¢Ô½·¢¸ßЧºÍ¼òÆÓ¡£
ÒÔÉϾÍÊÇlaravel prs4¼ÓÔØÒªÁìµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡