Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A few extra helper functions, and close db #24

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions libraries/cimongo/Cimongo.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php

if (!defined('BASEPATH'))
exit('No direct script access allowed');
if (!defined('BASEPATH')) exit('No direct script access allowed');
require_once('Cimongo_cursor.php');
require_once('Cimongo_extras.php');
/**
Expand All @@ -10,12 +9,12 @@
* A library to interact with the NoSQL database MongoDB.
* For more information see http://www.mongodb.org
*
* @package CodeIgniter
* @author Alessandro Arnodo | [email protected] | @vesparny
* @copyright Copyright (c) 2012, Alessandro Arnodo.
* @license http://www.opensource.org/licenses/mit-license.php
* @package CodeIgniter
* @author Alessandro Arnodo | [email protected] | @vesparny
* @copyright Copyright (c) 2012, Alessandro Arnodo.
* @license http://www.opensource.org/licenses/mit-license.php
* @link
* @version Version 1.1.0
* @version Version 1.1.0
*
*/

Expand All @@ -40,11 +39,12 @@ public function __construct() {
}

/**
* Fake close function so you can bind $this->db=$this->cimongo
* Fake close function so you can bind $this->db=$this->cimongo.
* NO LONGER A FAKE.
*
*/
public function close() {

return $this->close_db();
}

/**
Expand Down
8 changes: 8 additions & 0 deletions libraries/cimongo/Cimongo_base.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ private function connect(){
}
}

/**
*
*/
private function close_db() {
$this->db = NULL;
return $this->connection->close();
}

/**
* Create connection string
*
Expand Down
46 changes: 45 additions & 1 deletion libraries/cimongo/Cimongo_extras.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,50 @@ public function create_dbref($collection = "", $id = "", $database = FALSE ){
}
}

/**
* Utility function that generates a MongoID instance.
* Original inspiration from https://github.com/chuckcfs/CodeIgniter-MongoDB
*
* @param string The string representation of the desired ID object
* @return MongoId
* @access public
*/
public function generate_id($id) {
return new MongoId($id);
}

/**
* Utility function to generate a 'MongoDate' object
* Original inspiration from https://github.com/chuckcfs/CodeIgniter-MongoDB
*
* @param mixed Either a unix timestamp(int) or a string based date. Suggest format yyyy/mm/dd
* @return MongoDate The date object, access the 'sec' property for the timestamp
* @access public
*/
public function generate_date($param = null) {
if($param) {
is_string($param) ? $date = new MongoDate(strtotime($param)) : $date = new MongoDate($param);
} else {
$date = new MongoDate();
}
return $date;
}

/**
* Utility function to generate a 'MongoBinData' object to store a file as part of a document.
* You must pass the binary data of the file and not a file path.
*
* @param string The content of the file to store
* @return MongoBinData A ready-to-store representation of the binary data
* @access public
*/
public function generate_bindata( $contents ) {
if(empty($contents)) {
show_error('You must provide the contents a file to this function', 500);
}
return new MongoBinData( $contents );
}

/**
* Get the documents where the value of a $field is greater than $x
* @since v1.0.0
Expand Down Expand Up @@ -437,4 +481,4 @@ public function rename_field($old, $new){
$this->updates['$rename'][] = array($old => $new);
return $this;
}
}
}