GoogleDriveManager class
package |
Default |
---|
__construct(string $googleApiPhpCLientRoot)
How to use this class:
Before creating an instance of GoogleDriveManager, the google-api-php-client library must be downloaded from github and deployed into our project (We can use composer or download it directly).
We must login on the google api console and make sure we have a service account and a service account key. Service accounts are a special type of google user accounts that represent non human applications. The service account key is a file containing the account credentials that allow the related application to login into the google api. We must save this file so it is accessible by our project.
Throws |
|
---|
string
A full file system path to the root of the downloaded google-api-php-client library, that must be accessible by our project. A "vendor" folder must exist at the root of the provided folder.
clearCache()
enableCache(string $rootPath, string $zoneName = 'google-drive', integer $listsTimeToLive, integer $filesTimeToLive) : void
see | \org\turbodepot\src\main\php\managers\CacheManager::__construct |
---|---|
Throws |
|
string
Full file system path to the root of a folder where all the cached data will be stored.
string
To isolate all the cached data from any other elements that may exist on the cache folder, we must define a cache zone name. we can leave here the default name or use any other we want.
integer
Defines the number of seconds after which the operations related to listing files and folder cache data will be deleted. Set it to 0 to for an infinite time. (1 hour = 3600 seconds, 1 day = 86400 seconds, 1 month = 2592000, 1 year = 31536000)
integer
Defines the number of seconds after which the operations related to getting files content cache data will be deleted. Set it to 0 to for an infinite time. (1 hour = 3600 seconds, 1 day = 86400 seconds, 1 month = 2592000, 1 year = 31536000)
getCacheZoneName()
Throws |
|
---|
getDirectoryList(string $parentId = '') : array<mixed,\stdClass>
string
The google drive identifier for the directory that contains the elements we want to list.
array<mixed,\stdClass>
An array with one object for each one of the child elements found. Each object will have three properties: id, with the id of the child element, isDirectory which will be true if the child element is a directory, and name which will contain the child element name
getFileLocalPath(string $id) : string
Before giving us this path, the method will download all the file data locally, and once all the file is stored in our machine, the path to it will be provided.
Cache must be enabled for this method to work, cause the local file copy is stored on the cache folder.
string
The google drive id for the file we want to retrieve
string
The full file system path to the file we want to get
getFilesTimeToLive() : integer
see | \org\turbodepot\src\main\php\managers\GoogleDriveManager::enableCache |
---|---|
integer
The number of defined seconds or -1 if cache is not enabled
getListsTimeToLive() : integer
see | \org\turbodepot\src\main\php\managers\GoogleDriveManager::enableCache |
---|---|
integer
The number of defined seconds or -1 if cache is not enabled
setServiceAccountCredentials(string $serviceAccountCredentials)
Throws |
|
---|
string
A full file system path to the json file that contains the service account credentials that will be used to authenticate with the google drive api (See this class constructor for more info on service accounts).