MongoGridFS::__construct PHP Méthode

__construct() public méthode

Files as stored across two collections, the first containing file meta information, the second containing chunks of the actual file. By default, fs.files and fs.chunks are the collection names used.
public __construct ( MongoDB $db, string $prefix = "fs", mixed $chunks = null )
$db MongoDB Database
$prefix string [optional]

Optional collection name prefix.

$chunks mixed [optional]
    public function __construct(MongoDB $db, $prefix = "fs", $chunks = null)
    {
        if ($chunks) {
            trigger_error("The 'chunks' argument is deprecated and ignored", E_DEPRECATED);
        }
        if (empty($prefix)) {
            throw new \Exception('MongoGridFS::__construct(): invalid prefix');
        }
        $this->database = $db;
        $this->prefix = (string) $prefix;
        $this->filesName = $prefix . '.files';
        $this->chunksName = $prefix . '.chunks';
        $this->chunks = $db->selectCollection($this->chunksName);
        parent::__construct($db, $this->filesName);
    }

Usage Example

 /**
  * Constructor.
  *
  * @param \Mongator\Logger\LoggableMongoDB $db     A LoggableMongoDB instance.
  * @param string                           $prefix The prefix (optional, fs by default).
  */
 public function __construct(LoggableMongoDB $db, $prefix = 'fs')
 {
     $this->db = $db;
     $this->time = new Time();
     parent::__construct($db, $prefix);
 }