private function fillFileBuffer() {
    $headers = $this->getOAuthTokenHeader(parent::READ_SCOPE);
    if ($headers === false) {
      trigger_error("Unable to acquire OAuth token.", E_USER_WARNING);
      return false;
    }

    $query_arr = [
        'delimiter' => parent::DELIMITER,
        'max-keys' => self::MAX_KEYS,
    ];
    if (isset($this->prefix)) {
      $query_arr['prefix'] = $this->prefix;
    }
    if (isset($this->next_marker)) {
      $query_arr['marker'] = $this->next_marker;
    }
    $query_str = http_build_query($query_arr);
    $url = $this->createObjectUrl($this->bucket_name);
    $http_response = $this->makeHttpRequest(sprintf("%s?%s", $url, $query_str),
                                            "GET",
                                            $headers);

    if (false === $http_response) {
      trigger_error("Unable to connect to Google Cloud Storage Service.",
                    E_USER_WARNING);
      return false;
    }
    $status_code = $http_response['status_code'];
    if (HttpResponse::OK != $status_code) {
      trigger_error($this->getErrorMessage($status_code,
                                           $http_response['body']),
                    E_USER_WARNING);
      return false;
    }

    // Extract the files into the result array.
    $xml = simplexml_load_string($http_response['body']);

    if (isset($xml->NextMarker)) {
      $this->next_marker = (string) $xml->NextMarker;
    } else {
      $this->next_marker = null;
    }

    if (is_null($this->current_file_list)) {
      $this->current_file_list = [];
    }

    $prefix_len = isset($this->prefix) ? strlen($this->prefix) : 0;
    foreach($xml->Contents as $content) {
      $key = (string) $content->Key;

      // Skip objects end with "_$folder$" or "/" as they exist solely for
      // the purpose of representing empty directories. Since we create
      // empty direcotires using the delimiter ("/"), they will always be
      // captured in the <CommonPrefixies> section.
      if (StringUtil::endsWith($key, parent::FOLDER_SUFFIX) ||
          StringUtil::endsWith($key, parent::DELIMITER)) {
        continue;
      }

      if ($prefix_len != 0) {
        $key = substr($key, $prefix_len);
      }

      array_push($this->current_file_list, $key);
    }

    // All "Subdirectories" are listed as <CommonPrefixes>. See
    // https://developers.google.com/storage/docs/reference-methods#getbucket
    foreach($xml->CommonPrefixes as $common_prefixes) {
      $key = (string) $common_prefixes->Prefix;
      if ($prefix_len != 0) {
        $key = substr($key, $prefix_len);
      }
      array_push($this->current_file_list, $key);
    }

    return true;
  }
private function fillFileBuffer() {
    $headers = $this->getOAuthTokenHeader(parent::READ_SCOPE);
    if ($headers === false) {
      trigger_error("Unable to acquire OAuth token.", E_USER_WARNING);
      return false;
    }

    $query_arr = [
        'delimiter' => parent::DELIMITER,
        'max-keys' => self::MAX_KEYS,
    ];
    if (isset($this->prefix)) {
      $query_arr['prefix'] = $this->prefix;
    }
    if (isset($this->next_marker)) {
      $query_arr['marker'] = $this->next_marker;
    }
    $query_str = http_build_query($query_arr);
    $url = $this->createObjectUrl($this->bucket_name);
    $http_response = $this->makeHttpRequest(sprintf("%s?%s", $url, $query_str),
                                            "GET",
                                            $headers);

    if (false === $http_response) {
      trigger_error("Unable to connect to Google Cloud Storage Service.",
                    E_USER_WARNING);
      return false;
    }
    $status_code = $http_response['status_code'];
    if (HttpResponse::OK != $status_code) {
      trigger_error($this->getErrorMessage($status_code,
                                           $http_response['body']),
                    E_USER_WARNING);
      return false;
    }

    // Extract the files into the result array.
    $xml = simplexml_load_string($http_response['body']);

    if (isset($xml->NextMarker)) {
      $this->next_marker = (string) $xml->NextMarker;
    } else {
      $this->next_marker = null;
    }

    if (is_null($this->current_file_list)) {
      $this->current_file_list = [];
    }

    $prefix_len = isset($this->prefix) ? strlen($this->prefix) : 0;
    foreach($xml->Contents as $content) {
      $key = (string) $content->Key;

      // Skip objects end with "_$folder$" or "/" as they exist solely for
      // the purpose of representing empty directories. Since we create
      // empty direcotires using the delimiter ("/"), they will always be
      // captured in the <CommonPrefixies> section.
      if (StringUtil::endsWith($key, parent::FOLDER_SUFFIX) ||
          StringUtil::endsWith($key, parent::DELIMITER)) {
        continue;
      }

      if ($prefix_len != 0) {
        $key = substr($key, $prefix_len);
      }

      array_push($this->current_file_list, $key);
    }

    // All "Subdirectories" are listed as <CommonPrefixes>. See
    // https://developers.google.com/storage/docs/reference-methods#getbucket
    foreach($xml->CommonPrefixes as $common_prefixes) {
      $key = (string) $common_prefixes->Prefix;
      if ($prefix_len != 0) {
        $key = substr($key, $prefix_len);
      }
      array_push($this->current_file_list, $key);
    }

    return true;
  }
private function fillFileBuffer ( ) { $ headers = $ this -> getOAuthTokenHeader ( parent :: READ_SCOPE ) ; if ( $ headers === false ) { trigger_error ( "Unable to acquire OAuth token." , E_USER_WARNING ) ; return false ; } $ query_arr = [ 'delimiter' => parent :: DELIMITER , 'max-keys' => self :: MAX_KEYS , ] ; if ( isset ( $ this -> prefix ) ) { $ query_arr [ 'prefix' ] = $ this -> prefix ; } if ( isset ( $ this -> next_marker ) ) { $ query_arr [ 'marker' ] = $ this -> next_marker ; } $ query_str = http_build_query ( $ query_arr ) ; $ url = $ this -> createObjectUrl ( $ this -> bucket_name ) ; $ http_response = $ this -> makeHttpRequest ( sprintf ( "%s?%s" , $ url , $ query_str ) , "GET" , $ headers ) ; if ( false === $ http_response ) { trigger_error ( "Unable to connect to Google Cloud Storage Service." , E_USER_WARNING ) ; return false ; } $ status_code = $ http_response [ 'status_code' ] ; if ( HttpResponse :: OK != $ status_code ) { trigger_error ( $ this -> getErrorMessage ( $ status_code , $ http_response [ 'body' ] ) , E_USER_WARNING ) ; return false ; } // Extract the files into the result array. $ xml = simplexml_load_string ( $ http_response [ 'body' ] ) ; if ( isset ( $ xml -> NextMarker ) ) { $ this -> next_marker = ( string ) $ xml -> NextMarker ; } else { $ this -> next_marker = null ; } if ( is_null ( $ this -> current_file_list ) ) { $ this -> current_file_list = [ ] ; } $ prefix_len = isset ( $ this -> prefix ) ? strlen ( $ this -> prefix ) : 0 ; foreach ( $ xml -> Contents as $ content ) { $ key = ( string ) $ content -> Key ; // Skip objects end with "_$folder$" or "/" as they exist solely for // the purpose of representing empty directories. Since we create // empty direcotires using the delimiter ("/"), they will always be // captured in the <CommonPrefixies> section. if ( StringUtil :: endsWith ( $ key , parent :: FOLDER_SUFFIX ) || StringUtil :: endsWith ( $ key , parent :: DELIMITER ) ) { continue ; } if ( $ prefix_len != 0 ) { $ key = substr ( $ key , $ prefix_len ) ; } array_push ( $ this -> current_file_list , $ key ) ; } // All "Subdirectories" are listed as <CommonPrefixes>. See // https://developers.google.com/storage/docs/reference-methods#getbucket foreach ( $ xml -> CommonPrefixes as $ common_prefixes ) { $ key = ( string ) $ common_prefixes -> Prefix ; if ( $ prefix_len != 0 ) { $ key = substr ( $ key , $ prefix_len ) ; } array_push ( $ this -> current_file_list , $ key ) ; } return true ; }
Retrieve more directory entries from Cloud Storage.

@access private
Retrieve more directory entries from Cloud Storage .