Saves a Profile.
Profile $profile A Profile instance:
Boolean Write operation successful
Overrides ProfilerStorageInterface::write
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;
}