| 1 |
<?php |
| 2 |
/** |
| 3 |
* Copyright 2017 Google Inc. All Rights Reserved. |
| 4 |
* |
| 5 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 |
* you may not use this file except in compliance with the License. |
| 7 |
* You may obtain a copy of the License at |
| 8 |
* |
| 9 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 10 |
* |
| 11 |
* Unless required by applicable law or agreed to in writing, software |
| 12 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 13 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 |
* See the License for the specific language governing permissions and |
| 15 |
* limitations under the License. |
| 16 |
*/ |
| 17 |
|
| 18 |
namespace Google\Cloud\Storage; |
| 19 |
|
| 20 |
use Google\Cloud\Core\Iterator\PageIteratorTrait; |
| 21 |
|
| 22 |
/** |
| 23 |
* Iterates over a set of pages containing |
| 24 |
* {@see Google\Cloud\Storage\StorageObject} items. |
| 25 |
*/ |
| 26 |
class ObjectPageIterator implements \Iterator |
| 27 |
{ |
| 28 |
use PageIteratorTrait; |
| 29 |
|
| 30 |
/** |
| 31 |
* @var array |
| 32 |
*/ |
| 33 |
private $prefixes = []; |
| 34 |
|
| 35 |
/** |
| 36 |
* Gets a list of prefixes of objects matching-but-not-listed up to and |
| 37 |
* including the requested delimiter. |
| 38 |
* |
| 39 |
* @return array |
| 40 |
*/ |
| 41 |
public function prefixes() |
| 42 |
{ |
| 43 |
return $this->prefixes; |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Get the current page. |
| 48 |
* |
| 49 |
* @return array|null |
| 50 |
*/ |
| 51 |
public function current() |
| 52 |
{ |
| 53 |
if (!$this->page) { |
| 54 |
$this->page = $this->executeCall(); |
| 55 |
} |
| 56 |
|
| 57 |
if (isset($this->page['prefixes'])) { |
| 58 |
$this->updatePrefixes(); |
| 59 |
} |
| 60 |
|
| 61 |
return $this->get($this->itemsPath, $this->page); |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* Add new prefixes to the list. |
| 66 |
* |
| 67 |
* @return array |
| 68 |
*/ |
| 69 |
private function updatePrefixes() |
| 70 |
{ |
| 71 |
foreach ($this->page['prefixes'] as $prefix) { |
| 72 |
if (!in_array($prefix, $this->prefixes)) { |
| 73 |
$this->prefixes[] = $prefix; |
| 74 |
} |
| 75 |
} |
| 76 |
} |
| 77 |
} |
| 78 |
|