/** * {@inheritdoc} */ public function write(Profile $profile) { $this->cleanup(); $record = array('_id' => $profile->getToken(), 'parent' => $profile->getParentToken(), 'data' => base64_encode(serialize($profile->getCollectors())), 'ip' => $profile->getIp(), 'method' => $profile->getMethod(), 'url' => $profile->getUrl(), 'time' => $profile->getTime()); return $this->getMongo()->update(array('_id' => $profile->getToken()), array_filter($record, function ($v) { return !empty($v); }), array('upsert' => true)); }
/** * Write data associated with the given token. * * @param Profile $profile A Profile instance * * @return Boolean Write operation successful */ public function write(Profile $profile) { $this->cleanup(); $record = array('_id' => $profile->getToken(), 'parent' => $profile->getParent() ? $profile->getParent()->getToken() : null, 'data' => serialize($profile->getCollectors()), 'ip' => $profile->getIp(), 'url' => $profile->getUrl(), 'time' => $profile->getTime()); return $this->getMongo()->insert(array_filter($record, function ($v) { return !empty($v); })); }
/** * {@inheritdoc} */ public function write(Profile $profile) { $db = $this->initDb(); $args = array(':token' => $profile->getToken(), ':parent' => $profile->getParentToken(), ':data' => base64_encode(serialize($profile->getCollectors())), ':ip' => $profile->getIp(), ':method' => $profile->getMethod(), ':url' => $profile->getUrl(), ':time' => $profile->getTime(), ':created_at' => time()); try { if ($this->has($profile->getToken())) { $this->exec($db, 'UPDATE sf_profiler_data SET parent = :parent, data = :data, ip = :ip, method = :method, url = :url, time = :time, created_at = :created_at WHERE token = :token', $args); } else { $this->exec($db, 'INSERT INTO sf_profiler_data (token, parent, data, ip, method, url, time, created_at) VALUES (:token, :parent, :data, :ip, :method, :url, :time, :created_at)', $args); } $this->cleanup(); $status = true; } catch (\Exception $e) { $status = false; } $this->close($db); return $status; }
/** * {@inheritdoc} */ 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; }
/** * {@inheritdoc} */ public function write(Profile $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()); $profileIndexed = false !== $this->getValue($this->getItemName($profile->getToken())); if ($this->setValue($this->getItemName($profile->getToken()), $data, $this->lifetime)) { if (!$profileIndexed) { // Add to index $indexName = $this->getIndexName(); $indexRow = implode("\t", array($profile->getToken(), $profile->getIp(), $profile->getMethod(), $profile->getUrl(), $profile->getTime(), $profile->getParentToken(), $profile->getStatusCode())) . "\n"; return $this->appendValue($indexName, $indexRow, $this->lifetime); } return true; } return false; }
/** * Write data associated with the given token. * * @param Profile $profile A Profile instance * * @return Boolean Write operation successful */ public function write(Profile $profile) { return $this->getMongo()->insert(array('token' => $profile->getToken(), 'ip' => $profile->getIp(), 'url' => $profile->getUrl() === null ? '' : $profile->getUrl(), 'profile' => serialize($profile))); }