MediaWiki REL1_34
SwiftFileBackendList.php
Go to the documentation of this file.
1<?php
32abstract 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 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}
SwiftFileBackend helper class to page through listings.
string $dir
Storage directory.
string null $bufferAfter
List items after this path.
string $container
Container name.
__construct(SwiftFileBackend $backend, $fullCont, $dir, array $params)
pageFromList( $container, $dir, &$after, $limit, array $params)
Get the given list portion (page)
array $bufferIter
List of path or (path,stat array) entries.
Class for an OpenStack Swift (or Ceph RGW) based file backend.