ÔõÑùʹÓÃWhoopsµ÷ÊÔThinkPHP6µÄÒì³££¿
ÔÚ¿ª·¢Àú³ÌÖУ¬³£³£»á·ºÆðÖÖÖÖ¸÷ÑùµÄÒì³£ÇéÐΡ£Õë¶ÔÕâЩÒì³£ÇéÐεĴ¦Àí£¬¹ØÓÚ¿ª·¢Ö°Ô±À´ËµÊÇÒ»Ïî±ØÐèÕÆÎÕµÄÊÖÒÕ¡£thinkphp6ÊÇÏÖÔÚ½ÏÁ¿Ê¢ÐеÄphp¿ò¼ÜÖ®Ò»£¬ËüÌṩÁËһЩǿʢµÄÒì³£´¦Àí»úÖÆ£¬µ«ÔÚÏêϸʹÓÃʱ»¹ÐèҪ͎áµÚÈý·½¹¤¾ßÀ´¾ÙÐе÷ÊÔ¡£
±¾ÎĽ«ÏÈÈÝÒ»¸öºÜÊÇÊÊÓõÄPHPµ÷ÊÔ¹¤¾ß¡ª¡ªWhoops£¬ÒÔ¼°ÔõÑùÔÚThinkPHP6ÖÐʹÓÃËüÀ´µ÷ÊÔÖÖÖÖÒì³£ÇéÐΡ£
Ò»¡¢Ê²Ã´ÊÇWhoops?
WhoopsÊÇÒ»¸öÓÃÀ´²¶»ñPHP³ÌÐòÔËÐÐʱµÄ¹ýʧÓëÒì³£µÄ¿â£¬ÌṩÁËÒ»¸öÓѺõĹýʧÐÅϢչʾҳÃ棬±ãÓÚ³ÌÐòÔ±²éÕÒ¹ýʧ²¢ÇÒ¾ÙÐе÷ÊÔ¡£
WhoopsÖ§³Ö¶àÖÖÒì³£ÀàÐÍ£¬°üÀ¨PHPÄÚºËÒì³£¡¢ÖÂÃü¹ýʧ¡¢Óû§½ç˵Òì³£¡¢JavaScriptÒì³£µÈµÈ¡£Í¬Ê±£¬WhoopsËùÌṩµÄ¹ýʧÐÅϢչʾҳÃæÒ²ºÜÊÇÖ±¹Û¡¢ÑŹۡ¢Ò×ÓÚ¶¨ÖÆ¡£
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
¶þ¡¢ÎªÊ²Ã´ÒªÔÚThinkPHP6ÖÐʹÓÃWhoops£¿
ThinkPHP6¿ò¼ÜÄÚÖõÄÒì³£´¦Àí»úÖÆÊǺÜÊÇÇ¿Ê¢µÄ£¬µ«Æä¹ýʧÐÅÏ¢Ò²½ÏÁ¿¾«Á·£¬ÄÑÒÔÖ±¹ÛµØ·´Ó¦³öÎÊÌâËùÔÚ¡£¶øʹÓÃWhoopsÔò¿ÉÒÔÌṩһ¸ö¸üΪÓѺá¢ÑŹ۵ĹýʧÐÅϢչʾҳÃ棬±ãÓÚ²éÕÒÎÊÌâ¡£
³ý´ËÖ®Í⣬ʹÓÃWhoops»¹¿ÉÒÔÉÁ¿ª·¢Ö°Ô±ÏíÊܵ½¸üΪÎÞаµÄµ÷ÊÔ·½·¨¡£ÔÚʹÓÃWhoopsµÄÇéÐÎÏ£¬ÎÒÃÇ¿ÉÒÔʵʱÉó²é±äÁ¿µÄÖµ¡¢Å²ÓÿÍÕ»¡¢Cookie¡¢SessionµÈÐÅÏ¢£¬Õâ¹ØÓÚ³ÌÐòÔ±À´ËµÊǺÜÊÇÖ÷ÒªµÄ¡£
Èý¡¢ÔÚThinkPHP6ÖÐÔõÑùʹÓÃWhoops£¿
×°ÖÃWhoops
ʹÓÃComposer×°ÖÃWhoopsºÜÊǼòÆÓ£¬ÎÒÃÇÖ»ÐèÒªÔÚÏîÄ¿¸ùĿ¼ÏÂÖ´ÐÐÒÔÏÂÏÂÁî¼´¿É£º
composer require filp/whoops
µÇ¼ºó¸´ÖÆ
ÉèÖÃWhoops
ÔÚʹÓÃWhoops֮ǰ£¬ÎÒÃÇÐèÒª¾ÙÐÐһЩ¼òÆÓµÄÉèÖá£
Ê×ÏÈ£¬ÎÒÃÇÐèÒªÔÚconfig/app.phpÎļþÖÐÌí¼ÓWhoopsЧÀÍÌṩÕߣº
// Ìí¼ÓЧÀÍÌṩÕß 'services' => [ // ... hinkwhoopsServiceProvider::class, ],
µÇ¼ºó¸´ÖÆ
È»ºó£¬ÎÒÃÇÐèÒªÔÚconfig/whoops.phpÎļþÖоÙÐÐһЩÉèÖã¬ÏêϸÉèÖÃÈçÏ£º
return [ // ÊÇ·ñ¿ªÆôµ÷ÊÔģʽ 'debug' => true, // ÍŽáthinkphpµ÷ÊÔģʽ 'think' => true, // ÊÇ·ñ×Ô¶¯¼ì²â¿ØÖÆÆ÷¡¢Ä£×ÓµÈĿ¼ÏÂËùÓÐÀà 'auto_scan' => true, // ɨ³ýµÄĿ¼ÁÐ±í£¬Ö§³ÖÕýÔò±í´ïʽ 'exclude' => [ '/vendor/*', '/.git/*', '/runtime/*', '/public/*' ], // ×Ô½ç˵´¦Àí³ÌÐò 'handler' => null, // ÉèÖÃÎļþÉúÑÄ·¾¶£¬Ä¬ÈÏ·¾¶Îª'/runtime/whoops' 'log' => true, 'log_path' => app()->getRuntimePath() . 'whoops/', // ÉèÖñ¨¸æ 'report' => [ // Ö§³Ö'response'¡¢'json'¡¢'html'¡¢'xml'¡¢'console' 'type' => 'html', // Ö§³Ö'text/plain'¡¢'application/json'¡¢'text/html'¡¢'application/xml'¡¢WhoopsUtilMisc::getPreferredMimeType() 'content_type' => 'text/html', // ÉèÖñ¨¸æÒ³ÃæÕվɿØÖÆ̨£¬'auto'ÌåÏÖ×Ô¶¯Ñ¡Ôñ 'output' => 'auto', // ½ç˵ҳÃæÎÊÌâ 'page_title' => 'Whoops Error', // ÉèÖûá¼û¿ØÖÆ 'access_control' => [ // ÉèÖÃÔÊÐíµÄIPÁбí 'allow' => [], // ÉèÖþܾøµÄIPÁбí 'deny' => [], // ÉèÖÃÐèÒªµÇ¼µÄIPÁбí 'challenge' => [], ] ], ];
µÇ¼ºó¸´ÖÆ
ÒÔÉÏÊÇWhoopsµÄ»ù±¾ÉèÖÃÏÆäÖд󲿷ֶ¼¿ÉÒÔƾ֤×Ô¼ºµÄÐèÇó¾ÙÐÐÉèÖøü¸Ä¡£
ʹÓÃWhoops
¾ÓÉÁËÉÏÃæµÄ°ì·¨£¬ÎÒÃǾͿÉÒÔÕý³£Ê¹ÓÃWhoopsµ÷ÊÔ¹¤¾ßÁË¡£µ±ÎÒÃǵÄÓ¦ÓóÌÐòÔËÐÐÀú³ÌÖзºÆðÁ˹ýʧ»òÒ쳣ʱ£¬½«»á×Ô¶¯Ìøתµ½WhoopsµÄ¹ýʧÐÅϢչʾҳÃæ¡£
ÔÚÕâ¸öÒ³ÃæÖУ¬¿ÉÄÜ»á°üÀ¨Ò»Ð©ÓÐÓõÄÐÅÏ¢£¬ºÃ±È˵ŲÓÿÍÕ»¡¢ÇëÇó²ÎÊý¡¢ÇëÇóÍ·²¿¡¢Cookie¡¢SessionµÈÐÅÏ¢¡£ÕâЩÐÅÏ¢¶¼¿ÉÒÔ×ÊÖúÎÒÃǸü¿ìµØ¶¨Î»ÎÊÌâËùÔÚ²¢¾ÙÐнâ¾ö¡£
ËÄ¡¢×ܽá
ʹÓÃWhoops¿ÉÒÔÌṩԽ·¢Ö±¹Û¡¢ÑŹ۵ÄÒì³£ÐÅϢչʾҳÃ棬×ÊÖúÎÒÃǸü¿ìµØÕÒµ½ÎÊÌâËùÔÚ²¢¾ÙÐе÷ÊÔ¡£Whoops»¹Ö§³Ö¶àÖÖÒì³£ÀàÐÍ£¬°üÀ¨PHPÄÚºËÒì³£¡¢ÖÂÃü¹ýʧ¡¢Óû§½ç˵Òì³£¡¢JavaScriptÒì³£µÈµÈ£¬ºÜÊÇÊÊÓá£
ÔÚThinkPHP6¿ò¼ÜÖÐʹÓÃWhoopsºÜÊǼòÆÓ£¬ÎÒÃÇÖ»ÐèÒª¾ÙÐÐһЩ¼òÆÓµÄÉèÖü´¿ÉÕý³£Ê¹Óøù¤¾ß¾ÙÐе÷ÊÔ¡£ËäÈ»£¬ÉèÖÃÒ²ÊÇÐèҪƾ֤×Ô¼ºÏÖʵÐèÇó¾ÙÐе÷½âºÍÐ޸ĵġ£
×îºóҪעÖØ£¬Ê¹ÓÃWhoopsÖ»ÊÇÒ»ÖÖµ÷ÊÔ¹¤¾ß£¬¹ØÓÚ´úÂëµÄÖÊÁ¿ºÍÍêÕûÐÔ»¹ÐèÒªÎÒÃÇ¿ª·¢Ö°Ô±¼ÌÐøÆð¾¢£¬°ü¹Ü³ÌÐòµÄÎȹÌÐԺͿÉά»¤ÐÔ¡£
ÒÔÉϾÍÊÇÔõÑùʹÓÃWhoopsµ÷ÊÔThinkPHP6µÄÒì³££¿µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡