find() public méthode

public find ( array $query = [], array $fields = [] ) : MongoGridFSCursor
$query array The query
$fields array Fields to return
Résultat MongoGridFSCursor A MongoGridFSCursor
Exemple #1
0
 /**
  * Returns an an unsorted file list of the specified directory.
  *
  * @param string $path       The path of the directory.
  * @param mixed $filter      String/hash to filter file/dirname on.
  * @param boolean $dotfiles  Show dotfiles?
  * @param boolean $dironly   Show only directories?
  *
  * @return array  File list.
  * @throws Horde_Vfs_Exception
  */
 protected function _listFolder($path, $filter = null, $dotfiles = true, $dironly = false)
 {
     if (!$this->_isFolder($path)) {
         throw new Horde_Vfs_Exception(sprintf('Folder "%s" does not exist', $path));
     }
     $out = array();
     $path = $this->_convertPath($path);
     if (!$dironly) {
         try {
             $files = $this->_files->find(array($this->_mdKey(self::PATH) => $this->_convertPath($path)));
         } catch (MongoException $e) {
             throw new Horde_Vfs_Exception($e);
         }
         foreach ($files as $val) {
             $name = $val->file[self::MD][self::FNAME];
             // Filter out dotfiles if they aren't wanted.
             if (!$dotfiles && $name[0] == '.') {
                 continue;
             }
             // Filtering.
             if ($this->_filterMatch($filter, $name)) {
                 continue;
             }
             $tmp = array('date' => $val->file['uploadDate']->sec, 'group' => '', 'name' => $name, 'owner' => $val->file[self::MD][self::OWNER], 'perms' => '', 'size' => $val->getSize());
             $type = explode('.', $name);
             $tmp['type'] = count($type) == 1 ? '**none' : Horde_String::lower(array_pop($type));
             $out[$name] = $tmp;
         }
     }
     try {
         $folders = $this->_folders->find(array(self::FOLDER_PATH => array('$regex' => '^' . (strlen($path) ? $path . '/' : '') . '[^\\/]+$')));
     } catch (MongoException $e) {
         throw new Horde_Vfs_Exception($e);
     }
     foreach ($folders as $val) {
         $tmp = explode('/', $val[self::FOLDER_PATH]);
         $path = array_pop($tmp);
         if (isset($out[$path]) || $this->_filterMatch($filter, $path)) {
             continue;
         }
         $out[$path] = array('date' => $val[self::FOLDER_TS]->sec, 'group' => '', 'name' => $path, 'owner' => $val[self::FOLDER_OWNER], 'perms' => '', 'size' => -1, 'type' => '**dir');
     }
     return $out;
 }
 /**
  * Return stat for given path.
  * Stat contains following fields:
  * - (int)    size    file size in b. required
  * - (string) name    file name. required
  * - (int)    ts      file modification time in unix time. required
  * - (string) mime    mimetype. required for folders, others - optionally
  * - (bool)   read    read permissions. required
  * - (bool)   write   write permissions. required
  * - (bool)   locked  is object locked. optionally
  * - (bool)   hidden  is object hidden. optionally
  * - (string) alias   for symlinks - link target path relative to root path. optionally
  * - (string) target  for symlinks - link target path. optionally
  *
  * If file does not exists - returns empty array or false.
  *
  * @param  string  $path    file path 
  * @return array|false
  **/
 protected function _stat($path)
 {
     $file = $this->getFile($path);
     if (!$file) {
         // It could be a directory...
         $path = preg_replace('~/$~', '', $path);
         $file = $this->db->find(array("metadata.path" => $path));
         $file->sort(array("uploadDate" => -1));
         if ($file->count() == 0 && $path != $this->root) {
             return false;
         }
         $parent_dir = preg_replace('~[/]{0,1}[^\\/]+$~', '', $path);
         $subdir = count($this->subdirs($path));
         $out = array("name" => $this->_basename($path), "size" => 0, "ts" => $file->current()->file['uploadDate']->sec, "mime" => "directory", "dirs" => $subdir, "read" => true, "write" => true, "parent_id" => $parent_dir);
         if ($path == $this->root) {
             unset($out['parent_id']);
         }
         return $out;
     }
     return $this->format_stat($file);
 }
 /**
  * @param \MongoGridFS $gridFs
  */
 function it_should_get_keys($gridFs, $file, $otherFile)
 {
     $gridFs->find(array(), array('filename'))->willReturn(array(new File('filename'), new File('otherFilename')));
     $this->keys()->shouldReturn(array('filename', 'otherFilename'));
 }
Exemple #4
0
 /**
  * 根据查询条件获取指定数量的结果集
  *
  * @param array $query            
  * @param number $start            
  * @param number $limit            
  * @return multitype:
  */
 public function getGridFsFileBy($query, $sort = array('_id' => -1), $start = 0, $limit = 20, $fields = array())
 {
     if (!is_array($query)) {
         $query = array();
     }
     $cursor = $this->_fs->find($query, $fields);
     $cursor->sort($sort)->skip($start)->limit($limit);
     $rst = iterator_to_array($cursor, false);
     return $rst;
 }