/** * "Mount" volume. * Return true if volume available for read or write, * false - otherwise * * @return bool * @author Naoki Sawada **/ public function mount(array $opts) { $creds = null; if (isset($opts['access_token'])) { $this->netMountKey = md5(join('-', array('googledrive', $opts['path'], isset($opts['access_token']['refresh_token']) ? $opts['access_token']['refresh_token'] : $opts['access_token']['access_token']))); } $client = new \Google_Client(); $client->setClientId($opts['client_id']); $client->setClientSecret($opts['client_secret']); if (!empty($opts['access_token'])) { $client->setAccessToken($opts['access_token']); } if ($client->isAccessTokenExpired()) { try { $creds = $client->fetchAccessTokenWithRefreshToken(); } catch (LogicException $e) { $this->session->remove('GoogleDriveAuthParams'); throw $e; } } $service = new \Google_Service_Drive($client); // If path is not set, use the root if (!isset($opts['path']) || $opts['path'] === '') { $opts['path'] = 'root'; } $googleDrive = new GoogleDriveAdapter($service, $opts['path'], ['useHasDir' => true]); $opts['fscache'] = null; if ($this->options['gdCacheDir'] && is_writeable($this->options['gdCacheDir'])) { if ($this->options['gdCacheExpire']) { $opts['fscache'] = new elFinderVolumeFlysystemGoogleDriveCache(new Local($this->options['gdCacheDir']), $this->options['gdCachePrefix'] . $this->netMountKey, $this->options['gdCacheExpire']); } } if ($opts['fscache']) { $filesystem = new Filesystem(new CachedAdapter($googleDrive, $opts['fscache'])); } else { $filesystem = new Filesystem($googleDrive); } $opts['driver'] = 'Flysystem' . (class_exists('elFinderVolumeFlysystemExt') ? 'Ext' : ''); $opts['filesystem'] = $filesystem; $opts['checkSubfolders'] = true; if (!isset($opts['alias'])) { $opts['alias'] = 'GoogleDrive'; } if ($res = parent::mount($opts)) { // update access_token of session data if ($creds) { $netVolumes = $this->session->get('netvolume'); $netVolumes[$this->netMountKey]['access_token'] = array_merge($netVolumes[$this->netMountKey]['access_token'], $creds); $this->session->set('netvolume', $netVolumes); } } return $res; }