Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. FileProfilerStorage.php

function FileProfilerStorage::find

Overrides ProfilerStorageInterface::find

File

vendor/symfony/http-kernel/Profiler/FileProfilerStorage.php, line 45

Class

FileProfilerStorage
Storage for profiler using files.

Namespace

Symfony\Component\HttpKernel\Profiler

Code

public function find(?string $ip, ?string $url, ?int $limit, ?string $method, ?int $start = null, ?int $end = null, ?string $statusCode = null, ?\Closure $filter = null) : array {
    $file = $this->getIndexFilename();
    if (!file_exists($file)) {
        return [];
    }
    $file = fopen($file, 'r');
    fseek($file, 0, \SEEK_END);
    $result = [];
    while (\count($result) < $limit && ($line = $this->readLineFromFile($file))) {
        $values = str_getcsv($line, ',', '"', '\\');
        if (7 > \count($values)) {
            // skip invalid lines
            continue;
        }
        [
            $csvToken,
            $csvIp,
            $csvMethod,
            $csvUrl,
            $csvTime,
            $csvParent,
            $csvStatusCode,
            $csvVirtualType,
        ] = $values + [
            7 => null,
        ];
        $csvTime = (int) $csvTime;
        $urlFilter = false;
        if ($url) {
            $urlFilter = str_starts_with($url, '!') ? str_contains($csvUrl, substr($url, 1)) : !str_contains($csvUrl, $url);
        }
        if ($ip && !str_contains($csvIp, $ip) || $urlFilter || $method && !str_contains($csvMethod, $method) || $statusCode && !str_contains($csvStatusCode, $statusCode)) {
            continue;
        }
        if ($start && $csvTime < $start) {
            continue;
        }
        if ($end && $csvTime > $end) {
            continue;
        }
        $profile = [
            'token' => $csvToken,
            'ip' => $csvIp,
            'method' => $csvMethod,
            'url' => $csvUrl,
            'time' => $csvTime,
            'parent' => $csvParent,
            'status_code' => $csvStatusCode,
            'virtual_type' => $csvVirtualType ?: 'request',
        ];
        if ($filter && !$filter($profile)) {
            continue;
        }
        $result[$csvToken] = $profile;
    }
    fclose($file);
    return array_values($result);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal