/** * Return a Model found in the db checking the array * @param String $array * @param mixed $value * @return \App\Component\Model */ public static function getOneBy($array) { $object = Database::getOne(self::getCollectionName(), $array); if (!$object) { return null; } $className = get_called_class(); $model = new $className(); $model->hydrate($object); return $model; }
$objects = array(); foreach ($cursor as $object) { $objects[] = $object; } return $objects; } /** * Save an Object in the DB * @param String $table * @param \App\Component\Model $object */ public static function save($table, $object) { $collection = self::$database->{$table}; $array = $object->toArray(); $collection->save($array); $object->setId($array['_id']); } /** * Remove a given Object from the DB * @param String $table * @param \App\Component\Model $object */ public static function delete($table, $object) { $collection = self::$database->{$table}; $collection->remove($object->toArray()); } } Database::setInstance();