Skip to content
This repository has been archived by the owner on Sep 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #6 from 1ma/resolve-cp-conflicts
Browse files Browse the repository at this point in the history
Resolve copypaste conflicts
  • Loading branch information
markstory authored Mar 6, 2018
2 parents 8fadfe3 + 4db8bae commit 066108d
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 60 deletions.
2 changes: 1 addition & 1 deletion src/Xhgui/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
class Xhgui_Config
{
static $_config = array();
private static $_config = array();

/**
* Load a config file, it will replace
Expand Down
44 changes: 0 additions & 44 deletions src/Xhgui/Profiles.php

This file was deleted.

6 changes: 3 additions & 3 deletions src/Xhgui/Saver.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public static function factory($config)
case 'mongodb':
default:
$mongo = new MongoClient($config['db.host'], $config['db.options']);
$mongo->{$config['db.db']}->results->findOne();
$profiles = new Xhgui_Profiles($mongo->{$config['db.db']});
return new Xhgui_Saver_Mongo($profiles);
$collection = $mongo->{$config['db.do']}->results;
$collection->findOne();
return new Xhgui_Saver_Mongo($collection);
}
}
}
8 changes: 4 additions & 4 deletions src/Xhgui/Saver/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

class Xhgui_Saver_File implements Xhgui_Saver_Interface
{
protected $_file;
private $_file;

public function __construct($file)
public function __construct($file)
{
$this->_file = $file;
}
public function save($data)

public function save(array $data)
{
$json = json_encode($data);
return file_put_contents($this->_file, $json.PHP_EOL, FILE_APPEND);
Expand Down
2 changes: 1 addition & 1 deletion src/Xhgui/Saver/Interface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

interface Xhgui_Saver_Interface
{
public function save($data);
public function save(array $data);
}
35 changes: 28 additions & 7 deletions src/Xhgui/Saver/Mongo.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,36 @@

class Xhgui_Saver_Mongo implements Xhgui_Saver_Interface
{
protected $_profiles;

public function __construct(Xhgui_Profiles $profiles)
/**
* @var MongoCollection
*/
private $_collection;

/**
* @var MongoId lastProfilingId
*/
private static $lastProfilingId;

public function __construct(MongoCollection $collection)
{
$this->_profiles = $profiles;
$this->_collection = $collection;
}
public function save($data)

public function save(array $data)
{
return $this->_profiles->insert($data);
$data['_id'] = self::getLastProfilingId();

return $this->_collection->insert($data, array('w' => 0));
}

/**
* Return profiling ID
* @return MongoId lastProfilingId
*/
public static function getLastProfilingId() {
if (!self::$lastProfilingId) {
self::$lastProfilingId = new MongoId();
}
return self::$lastProfilingId;
}
}

0 comments on commit 066108d

Please sign in to comment.