Xdebug在Composer自动加载时触发断点(当我不希望它出现时)

时间:2019-11-26 10:40:44

标签: php composer-php xdebug

我建立了一个Laravel项目,该项目正常进行Composer自动加载。自动加载器通过composer.json文件中的Laravel安装中的默认映射:

    "autoload": {
        "psr-4": {
            "App\\": "app/"
        },
    }

我的问题是,当我在PhpStorm中使用Xdebug时,当通过自动加载器包含该类时,它会触发一个断点,而不是在我已设置断点的那一行。

例如:

<?php

namespace App\Http\Controllers;

use App\Bases\BaseJsonApiController;
use CloudCreativity\LaravelJsonApi\Contracts\Store\StoreInterface;
use CloudCreativity\LaravelJsonApi\Http\Requests\FetchResource;
use CloudCreativity\LaravelJsonApi\Http\Requests\FetchResources;

/**
 * Class IndexController
 *
 * @package App\Http\Controllers
 */
class IndexController extends BaseJsonApiController
{
    public function index(StoreInterface $store, FetchResources $request)
    {
        $a = 1;
        return parent::index($store, $request);
    }
}

我只添加了$a = 1;行来测试添加断点。

如果我在$a = 1;行上放置一个断点,那么我遇到的第一个断点是Composer自动加载包含此文件的时间,因此它在class IndexController处停止。如果我跳到下一个断点,它将到达预期的行$a = 1;

第一个触发的断点处的堆栈跟踪为:

IndexController.php:15, include()
ClassLoader.php:444, Composer\Autoload\includeFile()
ClassLoader.php:322, Composer\Autoload\ClassLoader->loadClass()
Container.php:803, spl_autoload_call()
Container.php:803, ReflectionClass->__construct()
Container.php:803, Illuminate\Foundation\Application->build()
Container.php:681, Illuminate\Foundation\Application->resolve()
Container.php:629, Illuminate\Foundation\Application->make()
Application.php:768, Illuminate\Foundation\Application->make()
Route.php:233, Illuminate\Routing\Route->getController()
Route.php:833, Illuminate\Routing\Route->controllerMiddleware()
Route.php:794, Illuminate\Routing\Route->gatherMiddleware()
Router.php:693, Illuminate\Routing\Router->gatherRouteMiddleware()
Router.php:673, Illuminate\Routing\Router->runRouteWithinStack()
Router.php:657, Illuminate\Routing\Router->runRoute()
Router.php:623, Illuminate\Routing\Router->dispatchToRoute()
Router.php:612, Illuminate\Routing\Router->dispatch()
Kernel.php:176, App\Http\Kernel->Illuminate\Foundation\Http\{closure:/var/www/open-banking-api/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:173-177}()
Pipeline.php:130, Illuminate\Routing\Pipeline->Illuminate\Pipeline\{closure:/var/www/open-banking-api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:128-136}()
InjectDebugbar.php:65, Barryvdh\Debugbar\Middleware\InjectDebugbar->handle()
Pipeline.php:171, Illuminate\Routing\Pipeline->Illuminate\Pipeline\{closure:/var/www/open-banking-api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:147-180}()
TransformsRequest.php:21, Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull->handle()
Pipeline.php:171, Illuminate\Routing\Pipeline->Illuminate\Pipeline\{closure:/var/www/open-banking-api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:147-180}()
TransformsRequest.php:21, App\Http\Middleware\TrimStrings->handle()
Pipeline.php:171, Illuminate\Routing\Pipeline->Illuminate\Pipeline\{closure:/var/www/open-banking-api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:147-180}()
ValidatePostSize.php:27, Illuminate\Foundation\Http\Middleware\ValidatePostSize->handle()
Pipeline.php:171, Illuminate\Routing\Pipeline->Illuminate\Pipeline\{closure:/var/www/open-banking-api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:147-180}()
CheckForMaintenanceMode.php:62, App\Http\Middleware\CheckForMaintenanceMode->handle()
Pipeline.php:171, Illuminate\Routing\Pipeline->Illuminate\Pipeline\{closure:/var/www/open-banking-api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:147-180}()
TrustProxies.php:57, App\Http\Middleware\TrustProxies->handle()
Pipeline.php:171, Illuminate\Routing\Pipeline->Illuminate\Pipeline\{closure:/var/www/open-banking-api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:147-180}()
Pipeline.php:105, Illuminate\Routing\Pipeline->then()
Kernel.php:151, App\Http\Kernel->sendRequestThroughRouter()
Kernel.php:116, App\Http\Kernel->handle()
index.php:55, {main}()

我想目前的解决方法是跳过第一个断点,但是我很想找出它发生的原因以及如何阻止它发生。

----编辑

xdebug的自定义php.ini设置:

zend_extension="xdebug.so"
xdebug.remote_enable=1
xdebug.remote_host=docker.for.mac.localhost
xdebug.remote_port=9001
xdebug.remote_autostart=1
xdebug.idekey=PHPSTORM

0 个答案:

没有答案