@@ -27,190 +27,190 @@ |
||
| 27 | 27 | * @author Yuuki Takezawa <[email protected]> |
| 28 | 28 | */ |
| 29 | 29 | class AuthenticatedClientSession { |
| 30 | - /** @var string */ |
|
| 31 | - protected $host; |
|
| 32 | - |
|
| 33 | - /** @var string */ |
|
| 34 | - protected $catalog; |
|
| 35 | - |
|
| 36 | - /** @var UuidInterface */ |
|
| 37 | - protected $transactionId; |
|
| 38 | - |
|
| 39 | - /** @var string */ |
|
| 40 | - protected $schema = 'default'; |
|
| 41 | - |
|
| 42 | - /** @var string */ |
|
| 43 | - protected $header = []; |
|
| 44 | - |
|
| 45 | - /** @var string */ |
|
| 46 | - protected $user = 'presto'; |
|
| 47 | - /** @var string */ |
|
| 48 | - protected $username = 'admin'; |
|
| 49 | - /** @var string */ |
|
| 50 | - protected $password = 'password'; |
|
| 51 | - /** @var string */ |
|
| 52 | - protected $source = PrestoHeaders::PRESTO_SOURCE_VALUE; |
|
| 53 | - |
|
| 54 | - /** @var Property[] */ |
|
| 55 | - protected $property = []; |
|
| 56 | - |
|
| 57 | - /** @var PreparedStatement[] */ |
|
| 58 | - protected $preparedStatement = []; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * PrestoSession constructor. |
|
| 62 | - * |
|
| 63 | - * @param string $host |
|
| 64 | - * @param string $catalog |
|
| 65 | - */ |
|
| 66 | - public function __construct(string $host, string $catalog, string $username, string $password) |
|
| 67 | - { |
|
| 30 | + /** @var string */ |
|
| 31 | + protected $host; |
|
| 32 | + |
|
| 33 | + /** @var string */ |
|
| 34 | + protected $catalog; |
|
| 35 | + |
|
| 36 | + /** @var UuidInterface */ |
|
| 37 | + protected $transactionId; |
|
| 38 | + |
|
| 39 | + /** @var string */ |
|
| 40 | + protected $schema = 'default'; |
|
| 41 | + |
|
| 42 | + /** @var string */ |
|
| 43 | + protected $header = []; |
|
| 44 | + |
|
| 45 | + /** @var string */ |
|
| 46 | + protected $user = 'presto'; |
|
| 47 | + /** @var string */ |
|
| 48 | + protected $username = 'admin'; |
|
| 49 | + /** @var string */ |
|
| 50 | + protected $password = 'password'; |
|
| 51 | + /** @var string */ |
|
| 52 | + protected $source = PrestoHeaders::PRESTO_SOURCE_VALUE; |
|
| 53 | + |
|
| 54 | + /** @var Property[] */ |
|
| 55 | + protected $property = []; |
|
| 56 | + |
|
| 57 | + /** @var PreparedStatement[] */ |
|
| 58 | + protected $preparedStatement = []; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * PrestoSession constructor. |
|
| 62 | + * |
|
| 63 | + * @param string $host |
|
| 64 | + * @param string $catalog |
|
| 65 | + */ |
|
| 66 | + public function __construct(string $host, string $catalog, string $username, string $password) |
|
| 67 | + { |
|
| 68 | 68 | $this->host = $host; |
| 69 | 69 | $this->catalog = $catalog; |
| 70 | 70 | $this->username = $username; |
| 71 | 71 | $this->password = $password; |
| 72 | - } |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * @param string $schema |
|
| 76 | - */ |
|
| 77 | - public function setSchema(string $schema) |
|
| 78 | - { |
|
| 74 | + /** |
|
| 75 | + * @param string $schema |
|
| 76 | + */ |
|
| 77 | + public function setSchema(string $schema) |
|
| 78 | + { |
|
| 79 | 79 | $this->schema = $schema; |
| 80 | - } |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * @param array $header |
|
| 84 | - */ |
|
| 85 | - public function setHeader(array $header) |
|
| 86 | - { |
|
| 82 | + /** |
|
| 83 | + * @param array $header |
|
| 84 | + */ |
|
| 85 | + public function setHeader(array $header) |
|
| 86 | + { |
|
| 87 | 87 | $this->header = $header; |
| 88 | - } |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * @param string $user |
|
| 92 | - */ |
|
| 93 | - public function setUser(string $user) |
|
| 94 | - { |
|
| 90 | + /** |
|
| 91 | + * @param string $user |
|
| 92 | + */ |
|
| 93 | + public function setUser(string $user) |
|
| 94 | + { |
|
| 95 | 95 | $this->user = $user; |
| 96 | - } |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * @param string $source |
|
| 100 | - */ |
|
| 101 | - public function setSource(string $source) |
|
| 102 | - { |
|
| 98 | + /** |
|
| 99 | + * @param string $source |
|
| 100 | + */ |
|
| 101 | + public function setSource(string $source) |
|
| 102 | + { |
|
| 103 | 103 | $this->source = $source; |
| 104 | - } |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * @param UuidInterface $transactionId |
|
| 108 | - */ |
|
| 109 | - public function setTransactionId(UuidInterface $transactionId) |
|
| 110 | - { |
|
| 106 | + /** |
|
| 107 | + * @param UuidInterface $transactionId |
|
| 108 | + */ |
|
| 109 | + public function setTransactionId(UuidInterface $transactionId) |
|
| 110 | + { |
|
| 111 | 111 | $this->transactionId = $transactionId; |
| 112 | - } |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - /** |
|
| 115 | - * @param Property $property |
|
| 116 | - */ |
|
| 117 | - public function setProperty(Property $property) |
|
| 118 | - { |
|
| 114 | + /** |
|
| 115 | + * @param Property $property |
|
| 116 | + */ |
|
| 117 | + public function setProperty(Property $property) |
|
| 118 | + { |
|
| 119 | 119 | $this->property[] = $property; |
| 120 | - } |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * @param PreparedStatement $preparedStatement |
|
| 124 | - */ |
|
| 125 | - public function setPreparedStatement(PreparedStatement $preparedStatement) |
|
| 126 | - { |
|
| 122 | + /** |
|
| 123 | + * @param PreparedStatement $preparedStatement |
|
| 124 | + */ |
|
| 125 | + public function setPreparedStatement(PreparedStatement $preparedStatement) |
|
| 126 | + { |
|
| 127 | 127 | $this->preparedStatement[] = $preparedStatement; |
| 128 | - } |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - /** |
|
| 131 | - * @return Property[] |
|
| 132 | - */ |
|
| 133 | - public function getProperty(): array |
|
| 134 | - { |
|
| 130 | + /** |
|
| 131 | + * @return Property[] |
|
| 132 | + */ |
|
| 133 | + public function getProperty(): array |
|
| 134 | + { |
|
| 135 | 135 | return $this->property; |
| 136 | - } |
|
| 136 | + } |
|
| 137 | 137 | |
| 138 | - /** |
|
| 139 | - * @return PreparedStatement[] |
|
| 140 | - */ |
|
| 141 | - public function getPreparedStatement(): array |
|
| 142 | - { |
|
| 138 | + /** |
|
| 139 | + * @return PreparedStatement[] |
|
| 140 | + */ |
|
| 141 | + public function getPreparedStatement(): array |
|
| 142 | + { |
|
| 143 | 143 | return $this->preparedStatement; |
| 144 | - } |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | - /** |
|
| 147 | - * @return string |
|
| 148 | - */ |
|
| 149 | - public function getHost(): string |
|
| 150 | - { |
|
| 146 | + /** |
|
| 147 | + * @return string |
|
| 148 | + */ |
|
| 149 | + public function getHost(): string |
|
| 150 | + { |
|
| 151 | 151 | return $this->host; |
| 152 | - } |
|
| 152 | + } |
|
| 153 | 153 | |
| 154 | - /** |
|
| 155 | - * @return string |
|
| 156 | - */ |
|
| 157 | - public function getCatalog(): string |
|
| 158 | - { |
|
| 154 | + /** |
|
| 155 | + * @return string |
|
| 156 | + */ |
|
| 157 | + public function getCatalog(): string |
|
| 158 | + { |
|
| 159 | 159 | return $this->catalog; |
| 160 | - } |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | - /** |
|
| 163 | - * @return array |
|
| 164 | - */ |
|
| 165 | - public function getHeader(): array |
|
| 166 | - { |
|
| 162 | + /** |
|
| 163 | + * @return array |
|
| 164 | + */ |
|
| 165 | + public function getHeader(): array |
|
| 166 | + { |
|
| 167 | 167 | return $this->header; |
| 168 | - } |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | - /** |
|
| 171 | - * @return string |
|
| 172 | - */ |
|
| 173 | - public function getSchema(): string |
|
| 174 | - { |
|
| 170 | + /** |
|
| 171 | + * @return string |
|
| 172 | + */ |
|
| 173 | + public function getSchema(): string |
|
| 174 | + { |
|
| 175 | 175 | return $this->schema; |
| 176 | - } |
|
| 176 | + } |
|
| 177 | 177 | |
| 178 | - /** |
|
| 179 | - * @return string |
|
| 180 | - */ |
|
| 181 | - public function getUser(): string |
|
| 182 | - { |
|
| 178 | + /** |
|
| 179 | + * @return string |
|
| 180 | + */ |
|
| 181 | + public function getUser(): string |
|
| 182 | + { |
|
| 183 | 183 | return $this->user; |
| 184 | - } |
|
| 184 | + } |
|
| 185 | 185 | |
| 186 | - /** |
|
| 187 | - * @return string |
|
| 188 | - */ |
|
| 189 | - public function getSource(): string |
|
| 190 | - { |
|
| 186 | + /** |
|
| 187 | + * @return string |
|
| 188 | + */ |
|
| 189 | + public function getSource(): string |
|
| 190 | + { |
|
| 191 | 191 | return $this->source; |
| 192 | - } |
|
| 193 | - /** |
|
| 194 | - * @return string |
|
| 195 | - */ |
|
| 196 | - public function getUsername(): string |
|
| 197 | - { |
|
| 192 | + } |
|
| 193 | + /** |
|
| 194 | + * @return string |
|
| 195 | + */ |
|
| 196 | + public function getUsername(): string |
|
| 197 | + { |
|
| 198 | 198 | return $this->username; |
| 199 | - } |
|
| 200 | - /** |
|
| 201 | - * @return string |
|
| 202 | - */ |
|
| 203 | - public function getPassword(): string |
|
| 204 | - { |
|
| 199 | + } |
|
| 200 | + /** |
|
| 201 | + * @return string |
|
| 202 | + */ |
|
| 203 | + public function getPassword(): string |
|
| 204 | + { |
|
| 205 | 205 | return $this->password; |
| 206 | - } |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | - /** |
|
| 209 | - * @return UuidInterface|null |
|
| 210 | - */ |
|
| 211 | - public function getTransactionId() |
|
| 212 | - { |
|
| 208 | + /** |
|
| 209 | + * @return UuidInterface|null |
|
| 210 | + */ |
|
| 211 | + public function getTransactionId() |
|
| 212 | + { |
|
| 213 | 213 | return $this->transactionId; |
| 214 | - } |
|
| 214 | + } |
|
| 215 | 215 | |
| 216 | 216 | } |
@@ -94,8 +94,8 @@ discard block |
||
| 94 | 94 | $this->headers = array_merge( |
| 95 | 95 | [ |
| 96 | 96 | PrestoHeaders::PRESTO_USER => $this->session->getUser(), |
| 97 | - 'User-Agent' => $this->session->getSource() . '/' . PrestoHeaders::VERSION, |
|
| 98 | - 'Authorization' => 'Basic ' . base64_encode($this->session->getUsername() . ':' . $this->session->getPassword()), |
|
| 97 | + 'User-Agent' => $this->session->getSource().'/'.PrestoHeaders::VERSION, |
|
| 98 | + 'Authorization' => 'Basic '.base64_encode($this->session->getUsername().':'.$this->session->getPassword()), |
|
| 99 | 99 | ], |
| 100 | 100 | $this->session->getHeader() |
| 101 | 101 | ); |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | $sessions = []; |
| 120 | 120 | /** @var Property $property */ |
| 121 | 121 | foreach ($sessionProperty as $property) { |
| 122 | - $sessions[] = $property->getKey() . '=' . $property->getValue(); |
|
| 122 | + $sessions[] = $property->getKey().'='.$property->getValue(); |
|
| 123 | 123 | } |
| 124 | 124 | $request = $request->withAddedHeader( |
| 125 | 125 | PrestoHeaders::PRESTO_SESSION, |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | $statements = []; |
| 132 | 132 | foreach ($preparedStatements as $preparedStatement) { |
| 133 | 133 | $statements[] = urlencode($preparedStatement->getKey()) |
| 134 | - . '=' . urlencode($preparedStatement->getValue()); |
|
| 134 | + . '='.urlencode($preparedStatement->getValue()); |
|
| 135 | 135 | } |
| 136 | 136 | $request = $request->withAddedHeader( |
| 137 | 137 | PrestoHeaders::PRESTO_PREPARED_STATEMENT, |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | public function execute(int $timeout = 500000, bool $debug = false) |
| 153 | 153 | { |
| 154 | 154 | $normalize = UriNormalizer::normalize( |
| 155 | - new Uri($this->session->getHost() . StatementClient::STATEMENT_URI), |
|
| 155 | + new Uri($this->session->getHost().StatementClient::STATEMENT_URI), |
|
| 156 | 156 | UriNormalizer::REMOVE_DUPLICATE_SLASHES |
| 157 | 157 | ); |
| 158 | 158 | $request = new Request(RequestMethodInterface::METHOD_POST, $normalize, $this->headers); |
@@ -212,9 +212,9 @@ discard block |
||
| 212 | 212 | 'timeout' => $timeout, |
| 213 | 213 | 'debug' => $debug, |
| 214 | 214 | ]); |
| 215 | - $promise->then(function (ResponseInterface $response) { |
|
| 215 | + $promise->then(function(ResponseInterface $response) { |
|
| 216 | 216 | $this->fulfilled = (StatusCodeInterface::STATUS_NO_CONTENT === $response->getStatusCode()); |
| 217 | - }, function (RequestException $e) { |
|
| 217 | + }, function(RequestException $e) { |
|
| 218 | 218 | throw new RequestFailedException($e->getMessage(), $e->getCode(), $e); |
| 219 | 219 | }); |
| 220 | 220 | $promise->wait(); |