Debug AsgardCMS with xDebug, how to configure application?



  • This is a answer to my own question that i want share with others. I think i not the only one that like use xDebug for debug functions, request, life cicle of Laravel application.

    For do this we need some configuration, because xDebug can't login and pass some middleware in example generate a Csrf-Token etc.

    For xDebug AsgardCMS v1 i do the follow:

    // app/Http/Kernel.php 
    // i comment out the Csrf middleware
    ...
      protected $middleware = [ ...
        'App\Http\Middleware\VerifyCsrfToken',
        //'App\Http\Middleware\VerifyCsrfToken',
      ];
    
    // Modules/Core/Providers/RoutingServiceProvider.php 
    // In AsgardCMS Routing i remove all the middleware, for backend in my case
    
    // before: with middleware //$router->group(['namespace' => 'Admin', 'prefix' => config('asgard.core.core.admin-prefix'), 'middleware' => config('asgard.core.core.middleware.backend', [])], function (Router $router) use ($backend) {
    // after: without middleware
     $router->group(['namespace' => 'Admin', 'prefix' => config('asgard.core.core.admin-prefix')], function (Router $router) use ($backend) {
    
    // For the last thing, force authenticate user manually
    // Modules/User/Repositories/Sentinel/SentinelAuthentication.php 
    // Add User Entity for retrive user, return ever the admin user id=1 in check()
    ...
    use Modules\User\Entities\Sentinel\User;
    ...
    
      public function check()
      {
        return User::find(1);
        //return Sentinel::check();
      }
    


  • And for xDebug in AsgardCMS v2 the things are the same but with a litle difference in code:

    // app/Http/Kernel.php 
    // comment out Csrf Token
    ...
    //\App\Http\Middleware\VerifyCsrfToken::class,
    
    
    // Modules/Core/Http/Middleware/Authorization.php 
    // in authorization comment all logic of handle() method unless of return $next($request);
      public function handle($request, \Closure $next, $permission)
      {
        //if ($this->auth->hasAccess($permission) === false) {
        //    return $this->handleUnauthorizedRequest($request, $permission);
        //}
        return $next($request);
      }
    
    // config/asgard/core/core.php 
    // remove the auth.admin middleware
     'backend' => [
         //'auth.admin',
     ],
    
    
    // And for the last authenticate user and return user and id
    // Modules/User/Repositories/Sentinel/SentinelAuthentication.php 
    ...
    use Modules\User\Entities\Sentinel\User;
    ...
    
    public function hasAccess($permission) {
       return true;
    }
    
    public function check() {
        return true;
    }
    
    public function user() {
       return User::find(1);
    }
    
    public function id() {
        return 1;
    }
    

    And in this way i can xDebug with IDE phpStorm, my Laravel and AsgardCMS application, hope it help someone, happy coding guys!



  • Okay, after a conversation on asgardcms.slack.com channel with @joestrong i understand that my way of debug was not the best one!

    You can simply set

    • Debug -> Listen for PHP Debug Connections
    • Break at firstline in PHP script ||or|| put the breakpoint where ever you want
    • Start the debugging and add ?XDEBUG_SESSION_START=1xxxx5 to url (you can see your debug SESSION in the $_SERVER global var)

    Theres the conversation on slack:
    joestrong [11:00 AM]
    @withartur I already use xDebug. I've not had to disable any functionality though

    withartur [11:01 AM]
    Realy? :smile:

    [11:01]
    And how? How you login and pass the middleware?

    [11:02]
    I new to xDebug, maybe i missing something? I do it with phpStorm IDE, not in browser

    joestrong [11:04 AM]
    I browse the application in the browser, and set breakpoints in phpstorm. Is that how you are using xdebug?

    [11:07]
    xdebug should call phpstorm as the php executes, it shouldn't have to "log in"

    withartur [11:13 AM]
    I to set the breakpoint in code, but instead of browser i have a predefined requests GET, POST that call a specific url, and in IDE i see the execution of code with variables and console that in the end show me the result of page.

    [11:14]
    Now i can try to launch it in browser how you say! Are you use phpStorm or other IDE? You set the breakpoint from IDE or with the xDebug Syntax directly in code?

    joestrong [11:19 AM]
    i just set breakpoints in phpstorm and browse the site

    [11:20]
    I personally use https://chrome.google.com/webstore/detail/xdebug-helper/eadndfjplgieldjbigjakmdgkmoaaaoc?hl=en with chrome, and then listen for xdebug connections in phpstorm


Log in to reply
 

Looks like your connection to AsgardCms was lost, please wait while we try to reconnect.