You are here

function google_api_client_load_library in Google API PHP Client 8.4

Same name and namespace in other branches
  1. 8.2 google_api_client.module \google_api_client_load_library()
  2. 8.3 google_api_client.module \google_api_client_load_library()

Function loads the google api php client library.

Parameters

bool $return_path: Pass true if you want the path to the library.

Return value

bool|string Returns lib path if requested else true if loaded.

6 calls to google_api_client_load_library()
Callback::callbackUrl in src/Controller/Callback.php
Callback URL for Google API Auth.
GoogleApiClientForm::buildForm in src/Form/GoogleApiClientForm.php
Form constructor.
GoogleApiClientService::getClient in src/Service/GoogleApiClientService.php
Function to retrieve the google client for different operations.
GoogleApiServiceClientService::getClient in src/Service/GoogleApiServiceClientService.php
Function to retrieve the google client for different operations.
google_api_client_requirements in ./google_api_client.install
Implements hook_requirements().

... See full list

File

./google_api_client.module, line 168
Google Api Client for drupal.

Code

function google_api_client_load_library($return_path = FALSE) {
  $library = \Drupal::service('library.discovery')
    ->getLibraryByName('google_api_client', 'google-api-php-client');
  $finder = new \Drupal\Component\ClassFinder\ClassFinder();
  $file = $finder
    ->findFile('Google_Client');
  if ($library) {
    if (class_exists('Google_Client') && strpos($file, 'vendor') !== FALSE) {

      // Composer install so no problem with lib.
      if ($return_path) {
        $pos = strpos($file, 'vendor');
        if ($pos !== FALSE) {
          $file = substr($file, 0, $pos);
        }
        return $file;
      }
      return TRUE;
    }
    else {
      $php_files = array_keys($library['php']);
      $library_exists = file_exists($php_files[0]);
      if ($library_exists) {
        require_once $php_files[0];
        if ($return_path) {
          return 'libraries/google-api-php-client/';
        }
        return TRUE;
      }
    }
  }
  return FALSE;
}