public function FileProfilerStorage::write

Saves a Profile.

Parameters

Profile $profile A Profile instance:

Return value

Boolean Write operation successful

Overrides ProfilerStorageInterface::write

File

drupal/core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Profiler/FileProfilerStorage.php, line 128

Class

FileProfilerStorage
Storage for profiler using files.

Namespace

Symfony\Component\HttpKernel\Profiler

Code

public function write(Profile $profile) {
  $file = $this
    ->getFilename($profile
    ->getToken());
  $profileIndexed = is_file($file);
  if (!$profileIndexed) {

    // Create directory
    $dir = dirname($file);
    if (!is_dir($dir)) {
      mkdir($dir, 0777, true);
    }
  }

  // Store profile
  $data = array(
    'token' => $profile
      ->getToken(),
    'parent' => $profile
      ->getParentToken(),
    'children' => array_map(function ($p) {
      return $p
        ->getToken();
    }, $profile
      ->getChildren()),
    'data' => $profile
      ->getCollectors(),
    'ip' => $profile
      ->getIp(),
    'method' => $profile
      ->getMethod(),
    'url' => $profile
      ->getUrl(),
    'time' => $profile
      ->getTime(),
  );
  if (false === file_put_contents($file, serialize($data))) {
    return false;
  }
  if (!$profileIndexed) {

    // Add to index
    if (false === ($file = fopen($this
      ->getIndexFilename(), 'a'))) {
      return false;
    }
    fputcsv($file, array(
      $profile
        ->getToken(),
      $profile
        ->getIp(),
      $profile
        ->getMethod(),
      $profile
        ->getUrl(),
      $profile
        ->getTime(),
      $profile
        ->getParentToken(),
    ));
    fclose($file);
  }
  return true;
}