src/GoogleDriveAdapter.php
protected function getFileObject($path, $checkDir = false)
    {
        list ($parentId, $itemId) = $this->splitPath($path, true);
        if (isset($this->cacheFileObjects[$itemId])) {
            return $this->cacheFileObjects[$itemId];
        } else if (isset($this->cacheFileObjectsByName[$parentId . '/' . $itemId])) {
            return $this->cacheFileObjectsByName[$parentId . '/' . $itemId];
        }

        $service = $this->service;
        $client = $service->getClient();

        $client->setUseBatch(true);
        $batch = $service->createBatch();

        $opts = [
            'fields' => $this->fetchfieldsGet
        ];

        $batch->add($this->service->files->get($itemId, $this->applyDefaultParams($opts, 'files.get')), 'obj');
        if ($checkDir && $this->useHasDir) {
            $batch->add($service->files->listFiles($this->applyDefaultParams([
                'pageSize' => 1,
                'q' => sprintf('trashed = false and "%s" in parents and mimeType = "%s"', $itemId, self::DIRMIME)
            ], 'files.list')), 'hasdir');
        }
        $results = array_values($batch->execute());

        list ($fileObj, $hasdir) = array_pad($results, 2, null);
        $client->setUseBatch(false);

        if ($fileObj instanceof Google_Service_Drive_DriveFile) {
            if ($hasdir && $fileObj->mimeType === self::DIRMIME) {
                if ($hasdir instanceof Google_Service_Drive_FileList) {
                    $this->cacheHasDirs[$fileObj->getId()] = (bool) $hasdir->getFiles();
                }
            }
        } else {
            $fileObj = NULL;
        }
        $this->cacheFileObjects[$itemId] = $fileObj;

        return $fileObj;
    }
protected function getFileObject($path, $checkDir = false)
    {
        list ($parentId, $itemId) = $this->splitPath($path, true);
        if (isset($this->cacheFileObjects[$itemId])) {
            return $this->cacheFileObjects[$itemId];
        } else if (isset($this->cacheFileObjectsByName[$parentId . '/' . $itemId])) {
            return $this->cacheFileObjectsByName[$parentId . '/' . $itemId];
        }

        $service = $this->service;
        $client = $service->getClient();

        $client->setUseBatch(true);
        $batch = $service->createBatch();

        $opts = [
            'fields' => $this->fetchfieldsGet
        ];

        $batch->add($this->service->files->get($itemId, $this->applyDefaultParams($opts, 'files.get')), 'obj');
        if ($checkDir && $this->useHasDir) {
            $batch->add($service->files->listFiles($this->applyDefaultParams([
                'pageSize' => 1,
                'q' => sprintf('trashed = false and "%s" in parents and mimeType = "%s"', $itemId, self::DIRMIME)
            ], 'files.list')), 'hasdir');
        }
        $results = array_values($batch->execute());

        list ($fileObj, $hasdir) = array_pad($results, 2, null);
        $client->setUseBatch(false);

        if ($fileObj instanceof Google_Service_Drive_DriveFile) {
            if ($hasdir && $fileObj->mimeType === self::DIRMIME) {
                if ($hasdir instanceof Google_Service_Drive_FileList) {
                    $this->cacheHasDirs[$fileObj->getId()] = (bool) $hasdir->getFiles();
                }
            }
        } else {
            $fileObj = NULL;
        }
        $this->cacheFileObjects[$itemId] = $fileObj;

        return $fileObj;
    }
protected function getFileObject ( $ path , $ checkDir = false ) { list ( $ parentId , $ itemId ) = $ this -> splitPath ( $ path , true ) ; if ( isset ( $ this -> cacheFileObjects [ $ itemId ] ) ) { return $ this -> cacheFileObjects [ $ itemId ] ; } else if ( isset ( $ this -> cacheFileObjectsByName [ $ parentId . '/' . $ itemId ] ) ) { return $ this -> cacheFileObjectsByName [ $ parentId . '/' . $ itemId ] ; } $ service = $ this -> service ; $ client = $ service -> getClient ( ) ; $ client -> setUseBatch ( true ) ; $ batch = $ service -> createBatch ( ) ; $ opts = [ 'fields' => $ this -> fetchfieldsGet ] ; $ batch -> add ( $ this -> service -> files -> get ( $ itemId , $ this -> applyDefaultParams ( $ opts , 'files.get' ) ) , 'obj' ) ; if ( $ checkDir && $ this -> useHasDir ) { $ batch -> add ( $ service -> files -> listFiles ( $ this -> applyDefaultParams ( [ 'pageSize' => 1 , 'q' => sprintf ( 'trashed = false and "%s" in parents and mimeType = "%s"' , $ itemId , self :: DIRMIME ) ] , 'files.list' ) ) , 'hasdir' ) ; } $ results = array_values ( $ batch -> execute ( ) ) ; list ( $ fileObj , $ hasdir ) = array_pad ( $ results , 2 , null ) ; $ client -> setUseBatch ( false ) ; if ( $ fileObj instanceof Google_Service_Drive_DriveFile ) { if ( $ hasdir && $ fileObj -> mimeType === self :: DIRMIME ) { if ( $ hasdir instanceof Google_Service_Drive_FileList ) { $ this -> cacheHasDirs [ $ fileObj -> getId ( ) ] = ( bool ) $ hasdir -> getFiles ( ) ; } } } else { $ fileObj = NULL ; } $ this -> cacheFileObjects [ $ itemId ] = $ fileObj ; return $ fileObj ; }
Get file oblect Google_Service_Drive_DriveFile

@param string $path
itemId path
@param string $checkDir
do check hasdir

@return Google_Service_Drive_DriveFile|null
Get file oblect Google_Service_Drive_DriveFile