예제 #1
0
  | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT      |
  | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS   |
  | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE                     |
  +---------------------------------------------------------------------------------+
  | Authors: César Rodas <*****@*****.**>                                           |
  +---------------------------------------------------------------------------------+
*/
require "../../lib/ActiveMongo.php";
require "Post.php";
require "Author.php";
ActiveMongo::connect("activemongo_blog");
/* delete collections */
PostModel::drop();
AuthorModel::drop();
/* This should be done just once */
ActiveMongo::install();
/* Create a new author
 * The property country is not defined
 * as an AuthorModel property, but it will
 * be saved. 
 */
$author = new AuthorModel();
$author->username = "******";
$author->name = "Cesar Rodas";
$author->country = "PY";
$author->save();
/* Add one blog post */
$post = new PostModel();
$post->uri = "/hello-world";
$post->title = "Hello World";
$post->author = $author->getID();
예제 #2
0
 /**
  *  Prepare a "selector" document to search treaing the property
  *  as a reference to the given ActiveMongo object.
  *
  */
 final function getColumnDeference(&$document, $property, ActiveMongo $obj)
 {
     $document["{$property}.\$id"] = $obj->getID();
 }
예제 #3
0
 function testSuperHooks()
 {
     ActiveMongo::addEvent('test_event', array($this, 'super_hook'));
     $c = new Model1();
     $c->triggerEvent('test_event', array('param1'));
 }
예제 #4
0
 /**
  *  Class contructor
  *
  *  This is class is private, so it can be contructed
  *  only using the singleton interfaz.
  *
  *  This method also setup all needed hooks
  *
  *  @return void
  */
 private function __construct()
 {
     ActiveMongo::addEvent('before_query', array($this, 'QueryRead'));
     ActiveMongo::addEvent('after_query', array($this, 'QuerySave'));
     ActiveMongo::addEvent('after_create', array($this, 'UpdateDocumentHook'));
     ActiveMongo::addEvent('after_update', array($this, 'UpdateDocumentHook'));
 }
예제 #5
0
 function testDisconnect()
 {
     $this->assertTrue(ActiveMongo::isConnected());
     ActiveMongo::Disconnect();
     $this->assertFalse(ActiveMongo::isConnected());
 }
예제 #6
0
 /**
  *  @depends testInit
  */
 function testCacheSimple()
 {
     $c = new CacheableModel();
     $c->prop = 'bar';
     $c->save();
     $id = $c->getID();
     $c->reset();
     $c->where('_id', $id);
     $c->doQuery();
     $this->assertFalse($c->servedFromCache());
     /* Disconnect to test the cache works properly */
     ActiveMongo::disconnect();
     $this->assertFalse(ActiveMongo::isConnected());
     $d = new CacheableModel();
     $d->where('_id', $id);
     $d->doQuery();
     $this->assertFalse(ActiveMongo::isConnected());
     $this->assertTrue($d->servedFromCache());
     $this->assertEquals($c->prop, $d->prop);
     /* non-cached query, to see if it is reconnected to mongodb */
     $d = new CacheableModel();
     $d->where('_id', 'foobar');
     $d->doQuery();
     $this->assertFalse($d->servedFromCache());
     $this->assertTrue(ActiveMongo::isConnected());
     return $id;
 }
예제 #7
0
 private static final function _hook($action, $method)
 {
     ActiveMongo::addEvent($action, array(__CLASS__, $method));
 }
예제 #8
0
  | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE          |
  | DISCLAIMED. IN NO EVENT SHALL CÉSAR D. RODAS BE LIABLE FOR ANY                  |
  | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES      |
  | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;    |
  | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND     |
  | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT      |
  | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS   |
  | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE                     |
  +---------------------------------------------------------------------------------+
  | Authors: César Rodas <*****@*****.**>                                           |
  +---------------------------------------------------------------------------------+
*/
require "../../lib/ActiveMongo.php";
require "User.php";
require "Services.php";
ActiveMongo::connect("test");
User::drop();
Twitter::drop();
Blog::drop();
/* Create an user for our 'aggregator' */
$user = new User();
$user->username = "******";
$user->password = "******";
$user->save();
/* Create one service */
$twt = new Twitter();
$twt->user = $user;
$twt->rss = "http://twitter.com/statuses/user_timeline/crodas.rss";
$twt->save();
/* Create another service */
$blg = new Blog();
예제 #9
0
  |                                                                                 |
  | 3. All advertising materials mentioning features or use of this software        |
  |    must display the following acknowledgement:                                  |
  |    This product includes software developed by César D. Rodas.                  |
  |                                                                                 |
  | 4. Neither the name of the César D. Rodas nor the                               |
  |    names of its contributors may be used to endorse or promote products         |
  |    derived from this software without specific prior written permission.        |
  |                                                                                 |
  | THIS SOFTWARE IS PROVIDED BY CÉSAR D. RODAS ''AS IS'' AND ANY                   |
  | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED       |
  | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE          |
  | DISCLAIMED. IN NO EVENT SHALL CÉSAR D. RODAS BE LIABLE FOR ANY                  |
  | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES      |
  | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;    |
  | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND     |
  | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT      |
  | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS   |
  | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE                     |
  +---------------------------------------------------------------------------------+
  | Authors: César Rodas <*****@*****.**>                                           |
  +---------------------------------------------------------------------------------+
*/
require "../../lib/ActiveMongo.php";
require "logger.php";
/* Connect */
ActiveMongo::connect("activemongo");
MongoLogger::Init();
/* Generate errors */
fopen("/foo-bar-file", "w");
throw new Exception("error");
예제 #10
0
파일: Core.php 프로젝트: momoim/momo-api
 public static function initGridFS($dbname)
 {
     ActiveMongo::disconnect();
     $gridfs_conf = self::config('gridfs_servers');
     ActiveMongo::connect($gridfs_conf['db'][$dbname], $gridfs_conf['host'], $gridfs_conf['user'], $gridfs_conf['pwd'], $gridfs_conf['opt']);
 }