MediaWiki  master
SwiftFileBackendList.php
Go to the documentation of this file.
1 <?php
32 abstract class SwiftFileBackendList implements Iterator {
34  protected $bufferIter = [];
35 
37  protected $bufferAfter = null;
38 
40  protected $pos = 0;
41 
43  protected $params = [];
44 
46  protected $backend;
47 
49  protected $container;
50 
52  protected $dir;
53 
55  protected $suffixStart;
56 
57  private const PAGE_SIZE = 9000; // file listing buffer size
58 
65  public function __construct( SwiftFileBackend $backend, $fullCont, $dir, array $params ) {
66  $this->backend = $backend;
67  $this->container = $fullCont;
68  $this->dir = $dir;
69  if ( substr( $this->dir, -1 ) === '/' ) {
70  $this->dir = substr( $this->dir, 0, -1 ); // remove trailing slash
71  }
72  if ( $this->dir == '' ) { // whole container
73  $this->suffixStart = 0;
74  } else { // dir within container
75  $this->suffixStart = strlen( $this->dir ) + 1; // size of "path/to/dir/"
76  }
77  $this->params = $params;
78  }
79 
84  public function key() {
85  return $this->pos;
86  }
87 
91  public function next() {
92  // Advance to the next file in the page
93  next( $this->bufferIter );
94  ++$this->pos;
95  // Check if there are no files left in this page and
96  // advance to the next page if this page was not empty.
97  if ( !$this->valid() && count( $this->bufferIter ) ) {
98  $this->bufferIter = $this->pageFromList(
99  $this->container, $this->dir, $this->bufferAfter, self::PAGE_SIZE, $this->params
100  ); // updates $this->bufferAfter
101  }
102  }
103 
107  public function rewind() {
108  $this->pos = 0;
109  $this->bufferAfter = null;
110  $this->bufferIter = $this->pageFromList(
111  // @phan-suppress-next-line PhanTypeMismatchArgumentPropertyReferenceReal
112  $this->container, $this->dir, $this->bufferAfter, self::PAGE_SIZE, $this->params
113  ); // updates $this->bufferAfter
114  }
115 
120  public function valid() {
121  if ( $this->bufferIter === null ) {
122  return false; // some failure?
123  } else {
124  return ( current( $this->bufferIter ) !== false ); // no paths can have this value
125  }
126  }
127 
138  abstract protected function pageFromList( $container, $dir, &$after, $limit, array $params );
139 }
SwiftFileBackendList\rewind
rewind()
Definition: SwiftFileBackendList.php:107
SwiftFileBackendList\PAGE_SIZE
const PAGE_SIZE
Definition: SwiftFileBackendList.php:57
SwiftFileBackendList\$suffixStart
int $suffixStart
Definition: SwiftFileBackendList.php:55
SwiftFileBackendList\$params
array $params
Definition: SwiftFileBackendList.php:43
SwiftFileBackend
Class for an OpenStack Swift (or Ceph RGW) based file backend.
Definition: SwiftFileBackend.php:36
SwiftFileBackendList
SwiftFileBackend helper class to page through listings.
Definition: SwiftFileBackendList.php:32
SwiftFileBackendList\valid
valid()
Definition: SwiftFileBackendList.php:120
SwiftFileBackendList\$dir
string $dir
Storage directory.
Definition: SwiftFileBackendList.php:52
SwiftFileBackendList\pageFromList
pageFromList( $container, $dir, &$after, $limit, array $params)
Get the given list portion (page)
SwiftFileBackendList\$container
string $container
Container name.
Definition: SwiftFileBackendList.php:49
SwiftFileBackendList\$bufferIter
array $bufferIter
List of path or (path,stat array) entries.
Definition: SwiftFileBackendList.php:34
SwiftFileBackendList\$backend
SwiftFileBackend $backend
Definition: SwiftFileBackendList.php:46
SwiftFileBackendList\$pos
int $pos
Definition: SwiftFileBackendList.php:40
SwiftFileBackendList\$bufferAfter
string null $bufferAfter
List items after this path.
Definition: SwiftFileBackendList.php:37
SwiftFileBackendList\next
next()
Definition: SwiftFileBackendList.php:91
SwiftFileBackendList\__construct
__construct(SwiftFileBackend $backend, $fullCont, $dir, array $params)
Definition: SwiftFileBackendList.php:65
SwiftFileBackendList\key
key()
Definition: SwiftFileBackendList.php:84