Debian Codegraph @

vendor/wikimedia/shellbox/src/Command/OutputFileToUrl.php

raw
1 <?php
2
3 namespace Shellbox\Command;
4
5 use Psr\Http\Message\UriInterface;
6
7 /**
8 * Encapsulation of an output file which is sent to a server using a PUT
9 * request.
10 *
11 * @since 4.1.0
12 */
13 class OutputFileToUrl extends OutputFile {
14 /** @var string|UriInterface */
15 private $url;
16 /** @var array */
17 private $headers = [];
18 /** @var bool */
19 private $mwContentHash = false;
20
21 /**
22 * @internal
23 * @param string|UriInterface $url
24 */
25 public function __construct( $url ) {
26 $this->url = $url;
27 }
28
29 /**
30 * Replace the current array of headers with the specified list. The array
31 * should be in Guzzle's format: an associative array where the key is the
32 * header name and the value is either a string or an array of strings.
33 * Array values are used to send multiple headers with the same name.
34 *
35 * @param array $headers
36 * @return $this
37 */
38 public function headers( array $headers ) {
39 $this->headers = $headers;
40 return $this;
41 }
42
43 /**
44 * Set a flag which, if enabled, will cause etag and x-object-meta-sha1base36
45 * headers to be set from the content of the file, according to Swift and
46 * MediaWiki conventions.
47 *
48 * @param bool $enable
49 * @return $this
50 */
51 public function enableMwContentHash( bool $enable = true ) {
52 $this->mwContentHash = $enable;
53 return $this;
54 }
55
56 public function getClientData() {
57 return [
58 'type' => 'url',
59 'url' => (string)$this->url,
60 'headers' => $this->headers,
61 'mwContentHash' => $this->mwContentHash,
62 ];
63 }
64
65 /**
66 * Get the URL
67 *
68 * @internal
69 * @return UriInterface|string
70 */
71 public function getUrl() {
72 return $this->url;
73 }
74
75 /**
76 * Get the headers
77 *
78 * @internal
79 * @return array
80 */
81 public function getHeaders() {
82 return $this->headers;
83 }
84
85 /**
86 * Determine whether MW content hashing is enabled
87 *
88 * @internal
89 * @return bool
90 */
91 public function isMwContentHashEnabled() {
92 return $this->mwContentHash;
93 }
94 }