From 7b24de512a34556a94dc12ca5b982db1ea2f06ba Mon Sep 17 00:00:00 2001 From: Wouter Van Hecke Date: Sun, 24 Jul 2011 20:45:33 +0200 Subject: [PATCH] Updated the code to follow the symfony coding standard using stof his remarks --- .../Profiler/MongoDbProfilerStorage.php | 51 ++++++++++--------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Profiler/MongoDbProfilerStorage.php b/src/Symfony/Component/HttpKernel/Profiler/MongoDbProfilerStorage.php index be782aa305..82db0e7fba 100644 --- a/src/Symfony/Component/HttpKernel/Profiler/MongoDbProfilerStorage.php +++ b/src/Symfony/Component/HttpKernel/Profiler/MongoDbProfilerStorage.php @@ -14,7 +14,7 @@ namespace Symfony\Component\HttpKernel\Profiler; class MongoDbProfilerStorage implements ProfilerStorageInterface { protected $dsn; - protected $mongo; + private $mongo; /** * Constructor. @@ -26,21 +26,6 @@ class MongoDbProfilerStorage implements ProfilerStorageInterface $this->dsn = $dsn; } - /** - * Internal convenience method that returns the instance of the MongoDB Collection - * - * @return \MongoCollection - */ - protected function mongo() - { - if ($this->mongo === null) { - $mongo = new \Mongo($this->dsn); - list($database, $collection,) = explode('/', substr(parse_url($this->dsn, PHP_URL_PATH), 1)); - $this->mongo = $mongo->selectCollection($database, $collection); - } - return $this->mongo; - } - /** * Finds profiler tokens for the given criteria. * @@ -50,22 +35,23 @@ class MongoDbProfilerStorage implements ProfilerStorageInterface * * @return array An array of tokens */ - function find($ip, $url, $limit) + public function find($ip, $url, $limit) { - $cursor = $this->mongo()->find(array('ip' => $ip, 'url' => $url))->limit($limit); + $cursor = $this->getMongo()->find(array('ip' => $ip, 'url' => $url))->limit($limit); $return = array(); foreach ($cursor as $profile) { $return[] = $profile['token']; } + return $return; } /** * Purges all data from the database. */ - function purge() + public function purge() { - $this->mongo()->remove(array()); + $this->getMongo()->remove(array()); } /** @@ -77,9 +63,10 @@ class MongoDbProfilerStorage implements ProfilerStorageInterface * * @return Profile The profile associated with token */ - function read($token) + public function read($token) { - $profile = $this->mongo()->findOne(array('token' => $token)); + $profile = $this->getMongo()->findOne(array('token' => $token)); + return $profile !== null ? unserialize($profile['profile']) : null; } @@ -90,13 +77,29 @@ class MongoDbProfilerStorage implements ProfilerStorageInterface * * @return Boolean Write operation successful */ - function write(Profile $profile) + public function write(Profile $profile) { - return $this->mongo()->insert(array( + return $this->getMongo()->insert(array( 'token' => $profile->getToken(), 'ip' => $profile->getIp(), 'url' => $profile->getUrl() === null ? '' : $profile->getUrl(), 'profile' => serialize($profile) )); } + + /** + * Internal convenience method that returns the instance of the MongoDB Collection + * + * @return \MongoCollection + */ + protected function getMongo() + { + if ($this->mongo === null) { + $mongo = new \Mongo($this->dsn); + list($database, $collection,) = explode('/', substr(parse_url($this->dsn, PHP_URL_PATH), 1)); + $this->mongo = $mongo->selectCollection($database, $collection); + } + + return $this->mongo; + } } \ No newline at end of file