Увеличительная линза открывает голубую структуру внутри стопки стеклянных слоёв.
Возможность · Отлаживаемость

Никакой магии, которую нельзя отладить по шагам.

Сгенерированный код не содержит скрытую логику. Фреймворк создаёт читаемый PHP, который можно изучить, сравнить, отлаживать и проходить по шагам привычными инструментами.

Ваш класс и то, что выполняется на самом деле

Посмотрим на сервис подготовки отчёта с подключенным поведением кеширования, а также на два файла, которые фреймворк для него формирует. Это настоящие файлы из отладочной XDebug сессии, которую можно пройти по шагам ниже.

Ваш исходный код

Поведение кеширования подключается с помощью атрибута #[Cacheable]. Исходный файл сервиса вы можете открыть, чиать и ставите в нём точки останова.

ReportService.phpваш код

        
        
        <?php
        
        
        
      
        
        
         
        
        
        
      
        
        
        declare(strict_types=1);
        
        
        
      
        
        
         
        
        
        
      
        
        
        namespace App\Report;
        
        
        
      
        
        
         
        
        
        
      
        
        
        use App\Attribute\Cacheable;
        
        
        
      
        
        
         
        
        
        
      
        
        
        class ReportService
        
        
        
      
        
        
        {
        
        
        
      
        
        
            public function __construct(private OrderRepository $orders) {}
        
        
        
      
        
        
         
        
        
        
      
        
        
            #[Cacheable(ttl: 300)]
        точка подключения кеширования
        
        
      
        
        
            public function monthlyRevenue(string $month): int
        
        
        
      
        
        
            {
        
        
        
      
        
        
                $total = 0;
        здесь сработает точка останова
        
        
      
        
        
                foreach ($this->orders->forMonth($month) as $order) {
        
        
        
      
        
        
                    $total += $order->cents;
        
        
        
      
        
        
                }
        
        
        
      
        
        
         
        
        
        
      
        
        
                return $total;
        
        
        
      
        
        
            }
        
        
        
      
        
        
        }
        
        
        
      

Скомпилированный исходный код

Исходный код вашего класса в виде трейта. Изменяется только строка объявления, все исходные номера строк сохраняются. В режиме отладки PHP загружает его через фильтр по вашему исходному пути, поэтому отладчик останавливается в src/Report/ReportService.php.

ReportServiceOriginalTrait.phpскомпилировано

        
        
        <?php
        
        
        
      
        
        
         
        
        
        
      
        
        
        declare(strict_types=1);
        
        
        
      
        
        
         
        
        
        
      
        
        
        namespace App\Report;
        
        
        
      
        
        
         
        
        
        
      
        
        
        use App\Attribute\Cacheable;
        
        
        
      
        
        
         
        
        
        
      
        
        
        trait ReportServiceOriginalTrait
        было: class ReportService
        
        
      
        
        
        {
        
        
        
      
        
        
            public function __construct(private OrderRepository $orders) {}
        
        
        
      
        
        
         
        
        
        
      
        
        
            #[Cacheable(ttl: 300)]
        
        
        
      
        
        
            public function monthlyRevenue(string $month): int
        
        
        
      
        
        
            {
        
        
        
      
        
        
                $total = 0;
        
        
        
      
        
        
                foreach ($this->orders->forMonth($month) as $order) {
        
        
        
      
        
        
                    $total += $order->cents;
        
        
        
      
        
        
                }
        
        
        
      
        
        
         
        
        
        
      
        
        
                return $total;
        
        
        
      
        
        
            }
        
        
        
      
        
        
        }
        
        
        
      
        
        
        include_once AOP_CACHE_DIR . '/Report/ReportService.php';
        
        
        
      

Прокси-класс

Класс, который загружает PHP, будет иметь имя вашего исходного класса, поэтому в трассировках стека указан ReportService. Middleware — один читаемый метод: построить joinpoint (точку соединения) один раз, затем выполнить его.

ReportService.phpсгенерировано

        
        
        <?php
        
        
        
      
        
        
        declare(strict_types=1);
        
        
        
      
        
        
        namespace App\Report;
        
        
        
      
        
        
         
        
        
        
      
        
        
        use Go\Aop\Framework\InterceptorInjector;
        
        
        
      
        
        
        use Go\Aop\Framework\Interceptor;
        
        
        
      
        
        
        use Go\Aop\Framework\The;
        
        
        
      
        
        
        use App\Aspect\CachingAspect;
        
        
        
      
        
        
        use Go\Aop\Intercept\DynamicMethodInvocation;
        
        
        
      
        
        
        use App\Attribute\Cacheable as Cacheable;
        
        
        
      
        
        
        class ReportService implements \Go\Aop\Proxy
        имя вашего класса
        
        
      
        
        
        {
        
        
        
      
        
        
            use ReportServiceOriginalTrait {
        тело вашего класса
        
        
      
        
        
                ReportServiceOriginalTrait::monthlyRevenue as private monthlyRevenueOriginalAlias;
        
        
        
      
        
        
            }
        
        
        
      
        
        
            #[\App\Attribute\Cacheable(ttl: 300)]
        
        
        
      
        
        
            public function monthlyRevenue(string $month): int
        
        
        
      
        
        
            {
        
        
        
      
        
        
                /** @var DynamicMethodInvocation<self, int> $__joinPoint */
        
        
        
      
        
        
                static $__joinPoint = InterceptorInjector::forMethod(
        создаётся при первом вызове
        
        
      
        
        
                    self::class,
        
        
        
      
        
        
                    'monthlyRevenue',
        
        
        
      
        
        
                    [
        
        
        
      
        
        
                        Interceptor::around(The::aspect(CachingAspect::class)->cache(...)),
        Ctrl+клик откроет CachingAspect::cache()
        
        
      
        
        
                    ],
        
        
        
      
        
        
                    $this->monthlyRevenueOriginalAlias(...),
        ваш исходный метод
        
        
      
        
        
                );
        
        
        
      
        
        
                return $__joinPoint->__invoke($this, [$month]);
        запускает middleware
        
        
      
        
        
            }
        
        
        
      
        
        
        }
        
        
        
      

Отлаживайте как код, написанный вами

Эмуляция сессии отладки кода, записанная и воспроизводимая в вашем браузере. Сделайте шаг в вызов, ставьте точки останова на полях, открывайте любой фрейм. Подсказки объясняют, что происходит на каждом шаге.

Debug: php bin/report.phpreplay
bin/report.php
<?php
declare(strict_types=1);
use App\Report\OrderRepository;
use App\Report\ReportService;
require dirname(__DIR__) . '/bootstrap.php';
$reports = new ReportService(new OrderRepository());
foreach (['2026-10', '2026-10'] as $month) {
$start = hrtime(true);
$cents = $reports->monthlyRevenue($month);
printf("%s: %d cents in %.2f ms\n", $month, $cents, (hrtime(true) - $start) / 1e6);
}

Frames

    Variables

    Console timed under the debugger

    stop 1 of 84

    Из консоли

    Спросите компилятор, что он сделал

    Консоль, которая поставляется с фреймворком, отвечает на вопросы о вашем ядре: какие классы поведений в нём есть и что затрагивает каждый из них. Ещё она заранее компилирует кеш. Пролистайте команды: терминал показывает их настоящий вывод для приложения выше.

    1. Run the app

      php bin/report.php

      The same app, without the debugger. The first call runs the slow query; the second comes from the caching behavior in a hundredth of a millisecond.

    2. List the behavior classes

      vendor/bin/aspect debug:aspect bootstrap.php

      Every behavior class (an aspect, in the API) your kernel registers, the file it is defined in, and the advisors it declares. The loader file only boots the kernel; it must not handle a request.

    3. List the advisors

      vendor/bin/aspect debug:advisor bootstrap.php

      Each advisor with its pointcut. Here there is one: cache(), for every method marked #[Cacheable].

    4. See what an advisor reaches

      vendor/bin/aspect debug:advisor bootstrap.php --advisor='App\Aspect\CachingAspect->cache'

      Analyzes every file below the include paths and lists the members the advisor matches: monthlyRevenue(), and nothing else.

    5. Weave ahead of time

      vendor/bin/aspect cache:warmup:aop bootstrap.php

      Weaves every file at deploy time, so production serves the prebuilt cache. It fails when a file can’t be woven; --workers=8 weaves in parallel.

    Terminalrecorded
    php bin/report.php
    2026-10: 21199 cents in 156.16 ms
    2026-10: 21199 cents in 0.01 ms
    vendor/bin/aspect debug:aspect bootstrap.php
    Aspect debug information
    ========================
    
     App\AppKernel has following enabled aspects:
    
    App\Aspect\CachingAspect
    ------------------------
    
    Defined in: /app/src/Aspect/CachingAspect.php
    Pointcuts and advices
     --------- ---------------------------------
      Type      Identifier
     --------- ---------------------------------
      Advisor   App\Aspect\CachingAspect->cache
     --------- ---------------------------------
    vendor/bin/aspect debug:advisor bootstrap.php
    Advisor debug information
    =========================
    
    List of registered advisors in the container
     --------------------------------- -------------------------------------
      Id                                Expression
     --------------------------------- -------------------------------------
      App\Aspect\CachingAspect->cache   @execution(App\Attribute\Cacheable)
     --------------------------------- -------------------------------------
    
    If you want to query an information about concrete advisor, then just query it
    by adding --advisor="Advisor\Name" to the command
    vendor/bin/aspect debug:advisor bootstrap.php --advisor='App\Aspect\CachingAspect->cache'
    Advisor debug information
    =========================
    
    Total 6 files to analyze.
      -> matching method App\Report\ReportService->monthlyRevenue
    vendor/bin/aspect cache:warmup:aop bootstrap.php
    Total 6 files to process.
    
    [DONE]: Total processed 6, 0 errors in 5 ms.

    Описывайте поведение. Сохраняйте прозрачность.

    Большинство фреймворков просят поверить в магию. Здесь каждую строку можно открыть, изучить и пройти по шагам.