From c0175e64d97a2e2690f8bc691a0f153b85aa65fa Mon Sep 17 00:00:00 2001 From: diego mauricio herrera alzate Date: Thu, 8 Aug 2013 15:36:40 -0500 Subject: [PATCH 1/3] =?UTF-8?q?se=20adiciona=20el=20parametro=20de=20conex?= =?UTF-8?q?i=C3=B3n=20a=20la=20base=20de=20datos=20utf8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/EpiDatabase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/EpiDatabase.php b/src/EpiDatabase.php index 6e091d7..75ddc83 100644 --- a/src/EpiDatabase.php +++ b/src/EpiDatabase.php @@ -117,7 +117,7 @@ private function init() try { - $this->dbh = new PDO($this->_type . ':host=' . $this->_host . ';dbname=' . $this->_name, $this->_user, $this->_pass); + $this->dbh = new PDO($this->_type . ':host=' . $this->_host . ';dbname=' . $this->_name, $this->_user, $this->_pass, array(\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8')); $this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch(Exception $e) From 4ff134f7226f85a293af75840f123a2da7d70018 Mon Sep 17 00:00:00 2001 From: Diego Mauricio Herrera Alzate Date: Mon, 12 Aug 2013 15:57:34 -0500 Subject: [PATCH 2/3] Update Cache.markdown MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit se soluciona el problema del ttl en la documentación --- docs/Cache.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Cache.markdown b/docs/Cache.markdown index c131db0..0babb78 100644 --- a/docs/Cache.markdown +++ b/docs/Cache.markdown @@ -22,7 +22,7 @@ First you'll need to include the cache module and specify which caching engine y The available methods are `get`, `set` and `delete`. get($name); - set($name, $value[, $ttl]); + set($name, $value, $ttl); delete($name); The default value for `$ttl` is 0 which means it will be stored forever. For the Memcached engine the `$ttl` can be seconds from the current time as long as it is less than `60*60*24*30` (seconds in 30 days) otherwise it needs to be a Unix timestamp. From 1637dd53d10ddeb03ee43927124c29df44a77a02 Mon Sep 17 00:00:00 2001 From: diego mauricio herrera alzate Date: Wed, 21 Aug 2013 17:24:28 -0500 Subject: [PATCH 3/3] module is added to mongodb --- src/Epi.php | 3 ++ src/EpiMongo.php | 107 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 src/EpiMongo.php diff --git a/src/Epi.php b/src/Epi.php index f0cc91f..87a1bba 100644 --- a/src/Epi.php +++ b/src/Epi.php @@ -19,6 +19,7 @@ class Epi 'cache-memcached' => array('base', 'EpiCache.php', 'EpiCache_Memcached.php'), 'config' => array('base', 'EpiConfig.php'), 'database' => array('base', 'EpiDatabase.php'), + 'mongo' => array('EpiMongo.php'), 'debug' => array('EpiDebug.php'), 'route' => array('base', 'EpiRoute.php'), 'session' => array('base', 'EpiSession.php', 'session-php', 'session-apc', 'session-memcached'), @@ -31,6 +32,7 @@ class Epi public static function init() { + $args = func_get_args(); if(!empty($args)) { @@ -61,6 +63,7 @@ public static function getSetting($name) private static function loadDependency($dep) { + $value = isset(self::$manifest[$dep]) ? self::$manifest[$dep] : $dep; if(!is_array($value)) { diff --git a/src/EpiMongo.php b/src/EpiMongo.php new file mode 100644 index 0000000..a485222 --- /dev/null +++ b/src/EpiMongo.php @@ -0,0 +1,107 @@ +_type = $type; + self::$instances[$hash]->_dbname = $dbname; + self::$instances[$hash]->_host = $host; + self::$instances[$hash]->_port = $port; + self::$instances[$hash]->_port = $port; + + return self::$instances[$hash]; + } + + public static function employ($type = null, $dbname = null, $host = 'localhost', $port = '27017') + { + if(!empty($type) && !empty($dbname)) + { + self::$type = $type; + self::$dbname = $dbname; + self::$host = $host; + self::$port = $port; + } + + return array('type' => self::$type, 'dbname' => self::$dbname, 'host' => self::$host, 'port' => self::$port); + } + + + public function all($dbcollection = '', $params = array()) + { + + $this->init(); + $return = array(); + + $collection = $this->mongo->selectCollection($this->_dbname, $dbcollection); + $cursor = $collection->find($params); + + foreach ($cursor as $document) { + unset($document['_id']); + array_push($return, $document); + } + + return $return; + } + + public function create($dbcollection = '', $params = array()) + { + + $this->init(); + $return = array(); + + $collection = $this->mongo->selectCollection($this->_dbname, $dbcollection); + $cursor = $collection->insert($params); + + return $cursor; + } + + public function count($dbcollection = '', $params = array()) + { + + $this->init(); + $result = $this->db->command(array("distinct" => $dbcollection,"query" => $params)); + + return $result['stats']['n']; + } + + + + private function init() + { + + if(!isset($this->mongo)){ + $this->mongo = new MongoClient('mongodb://'.$this->_host.':'.$this->_port); + $this->db = $this->mongo->selectDB($this->_dbname); + } + + } + + + +} + + function getMongo() +{ + $employ = extract(EpiMongo::employ()); + + if(empty($type) || empty($dbname) || empty($host) || empty($port)) + EpiException::raise(new EpiCacheTypeDoesNotExistException('Could not determine which database module to load', 404)); + else + return EpiMongo::getInstance($type, $dbname, $host, $port); +}