@@ -27,147 +27,147 @@ |
||
27 | 27 | use function sprintf; |
28 | 28 | trait EndpointTrait |
29 | 29 | { |
30 | - /** |
|
31 | - * Check if an array containts nested array |
|
32 | - */ |
|
33 | - private function isNestedArray(array $a) : bool |
|
34 | - { |
|
35 | - foreach ($a as $v) { |
|
36 | - if (\is_array($v)) { |
|
37 | - return \true; |
|
38 | - } |
|
39 | - } |
|
40 | - return \false; |
|
41 | - } |
|
42 | - /** |
|
43 | - * Check if an array is associative, i.e. has a string as key |
|
44 | - */ |
|
45 | - protected function isAssociativeArray(array $array) : bool |
|
46 | - { |
|
47 | - foreach ($array as $k => $v) { |
|
48 | - if (\is_string($k)) { |
|
49 | - return \true; |
|
50 | - } |
|
51 | - } |
|
52 | - return \false; |
|
53 | - } |
|
54 | - /** |
|
55 | - * Converts array to comma-separated list; |
|
56 | - * Converts boolean value to true', 'false' string |
|
57 | - * |
|
58 | - * @param mixed $value |
|
59 | - */ |
|
60 | - private function convertValue($value) : string |
|
61 | - { |
|
62 | - // Convert a boolean value in 'true' or 'false' string |
|
63 | - if (\is_bool($value)) { |
|
64 | - return $value ? 'true' : 'false'; |
|
65 | - // Convert to comma-separated list if array |
|
66 | - } elseif (\is_array($value) && $this->isNestedArray($value) === \false) { |
|
67 | - return \implode(',', $value); |
|
68 | - } |
|
69 | - return (string) $value; |
|
70 | - } |
|
71 | - /** |
|
72 | - * Encode a value for a valid URL |
|
73 | - * |
|
74 | - * @param mixed $value |
|
75 | - */ |
|
76 | - protected function encode($value) : string |
|
77 | - { |
|
78 | - return Utility::urlencode($this->convertValue($value)); |
|
79 | - } |
|
80 | - /** |
|
81 | - * Returns the URL with the query string from $params |
|
82 | - * extracting the array keys specified in $keys |
|
83 | - */ |
|
84 | - protected function addQueryString(string $url, array $params, array $keys) : string |
|
85 | - { |
|
86 | - $queryParams = []; |
|
87 | - foreach ($keys as $k) { |
|
88 | - if (isset($params[$k])) { |
|
89 | - $queryParams[$k] = $this->convertValue($params[$k]); |
|
90 | - } |
|
91 | - } |
|
92 | - if (empty($queryParams)) { |
|
93 | - return $url; |
|
94 | - } |
|
95 | - return $url . '?' . http_build_query($queryParams); |
|
96 | - } |
|
97 | - /** |
|
98 | - * Serialize the body using the Content-Type |
|
99 | - * |
|
100 | - * @param mixed $body |
|
101 | - */ |
|
102 | - protected function bodySerialize($body, string $contentType) : string |
|
103 | - { |
|
104 | - if (strpos($contentType, 'application/x-ndjson') !== \false || strpos($contentType, 'application/vnd.elasticsearch+x-ndjson') !== \false) { |
|
105 | - return NDJsonSerializer::serialize($body, ['remove_null' => \false]); |
|
106 | - } |
|
107 | - if (strpos($contentType, 'application/json') !== \false || strpos($contentType, 'application/vnd.elasticsearch+json') !== \false) { |
|
108 | - return JsonSerializer::serialize($body, ['remove_null' => \false]); |
|
109 | - } |
|
110 | - throw new ContentTypeException(sprintf("The Content-Type %s is not managed by Elasticsearch serializer", $contentType)); |
|
111 | - } |
|
112 | - /** |
|
113 | - * Create a PSR-7 request |
|
114 | - * |
|
115 | - * @param array|string $body |
|
116 | - */ |
|
117 | - protected function createRequest(string $method, string $url, array $headers, $body = null) : RequestInterface |
|
118 | - { |
|
119 | - $requestFactory = Psr17FactoryDiscovery::findRequestFactory(); |
|
120 | - $streamFactory = Psr17FactoryDiscovery::findStreamFactory(); |
|
121 | - $request = $requestFactory->createRequest($method, $url); |
|
122 | - // Body request |
|
123 | - if (!empty($body)) { |
|
124 | - if (!isset($headers['Content-Type'])) { |
|
125 | - throw new ContentTypeException(sprintf("The Content-Type is missing for %s %s", $method, $url)); |
|
126 | - } |
|
127 | - $content = \is_string($body) ? $body : $this->bodySerialize($body, $headers['Content-Type']); |
|
128 | - $request = $request->withBody($streamFactory->createStream($content)); |
|
129 | - } |
|
130 | - $headers = $this->buildCompatibilityHeaders($headers); |
|
131 | - // Headers |
|
132 | - foreach ($headers as $name => $value) { |
|
133 | - $request = $request->withHeader($name, $value); |
|
134 | - } |
|
135 | - return $request; |
|
136 | - } |
|
137 | - /** |
|
138 | - * Build the API compatibility headers |
|
139 | - * transfrom Content-Type and Accept adding vnd.elasticsearch+ and compatible-with |
|
140 | - * |
|
141 | - * @see https://github.com/elastic/elasticsearch-php/pull/1142 |
|
142 | - */ |
|
143 | - protected function buildCompatibilityHeaders(array $headers) : array |
|
144 | - { |
|
145 | - if (isset($headers['Content-Type'])) { |
|
146 | - if (\preg_match('/application\\/([^,]+)$/', $headers['Content-Type'], $matches)) { |
|
147 | - $headers['Content-Type'] = sprintf(Client::API_COMPATIBILITY_HEADER, 'application', $matches[1]); |
|
148 | - } |
|
149 | - } |
|
150 | - if (isset($headers['Accept'])) { |
|
151 | - $values = \explode(',', $headers['Accept']); |
|
152 | - foreach ($values as &$value) { |
|
153 | - if (\preg_match('/(application|text)\\/([^,]+)/', $value, $matches)) { |
|
154 | - $value = sprintf(Client::API_COMPATIBILITY_HEADER, $matches[1], $matches[2]); |
|
155 | - } |
|
156 | - } |
|
157 | - $headers['Accept'] = \implode(',', $values); |
|
158 | - } |
|
159 | - return $headers; |
|
160 | - } |
|
161 | - /** |
|
162 | - * Check if the $required parameters are present in $params |
|
163 | - * @throws MissingParameterException |
|
164 | - */ |
|
165 | - protected function checkRequiredParameters(array $required, array $params) : void |
|
166 | - { |
|
167 | - foreach ($required as $req) { |
|
168 | - if (!isset($params[$req])) { |
|
169 | - throw new MissingParameterException(sprintf('The parameter %s is required', $req)); |
|
170 | - } |
|
171 | - } |
|
172 | - } |
|
30 | + /** |
|
31 | + * Check if an array containts nested array |
|
32 | + */ |
|
33 | + private function isNestedArray(array $a) : bool |
|
34 | + { |
|
35 | + foreach ($a as $v) { |
|
36 | + if (\is_array($v)) { |
|
37 | + return \true; |
|
38 | + } |
|
39 | + } |
|
40 | + return \false; |
|
41 | + } |
|
42 | + /** |
|
43 | + * Check if an array is associative, i.e. has a string as key |
|
44 | + */ |
|
45 | + protected function isAssociativeArray(array $array) : bool |
|
46 | + { |
|
47 | + foreach ($array as $k => $v) { |
|
48 | + if (\is_string($k)) { |
|
49 | + return \true; |
|
50 | + } |
|
51 | + } |
|
52 | + return \false; |
|
53 | + } |
|
54 | + /** |
|
55 | + * Converts array to comma-separated list; |
|
56 | + * Converts boolean value to true', 'false' string |
|
57 | + * |
|
58 | + * @param mixed $value |
|
59 | + */ |
|
60 | + private function convertValue($value) : string |
|
61 | + { |
|
62 | + // Convert a boolean value in 'true' or 'false' string |
|
63 | + if (\is_bool($value)) { |
|
64 | + return $value ? 'true' : 'false'; |
|
65 | + // Convert to comma-separated list if array |
|
66 | + } elseif (\is_array($value) && $this->isNestedArray($value) === \false) { |
|
67 | + return \implode(',', $value); |
|
68 | + } |
|
69 | + return (string) $value; |
|
70 | + } |
|
71 | + /** |
|
72 | + * Encode a value for a valid URL |
|
73 | + * |
|
74 | + * @param mixed $value |
|
75 | + */ |
|
76 | + protected function encode($value) : string |
|
77 | + { |
|
78 | + return Utility::urlencode($this->convertValue($value)); |
|
79 | + } |
|
80 | + /** |
|
81 | + * Returns the URL with the query string from $params |
|
82 | + * extracting the array keys specified in $keys |
|
83 | + */ |
|
84 | + protected function addQueryString(string $url, array $params, array $keys) : string |
|
85 | + { |
|
86 | + $queryParams = []; |
|
87 | + foreach ($keys as $k) { |
|
88 | + if (isset($params[$k])) { |
|
89 | + $queryParams[$k] = $this->convertValue($params[$k]); |
|
90 | + } |
|
91 | + } |
|
92 | + if (empty($queryParams)) { |
|
93 | + return $url; |
|
94 | + } |
|
95 | + return $url . '?' . http_build_query($queryParams); |
|
96 | + } |
|
97 | + /** |
|
98 | + * Serialize the body using the Content-Type |
|
99 | + * |
|
100 | + * @param mixed $body |
|
101 | + */ |
|
102 | + protected function bodySerialize($body, string $contentType) : string |
|
103 | + { |
|
104 | + if (strpos($contentType, 'application/x-ndjson') !== \false || strpos($contentType, 'application/vnd.elasticsearch+x-ndjson') !== \false) { |
|
105 | + return NDJsonSerializer::serialize($body, ['remove_null' => \false]); |
|
106 | + } |
|
107 | + if (strpos($contentType, 'application/json') !== \false || strpos($contentType, 'application/vnd.elasticsearch+json') !== \false) { |
|
108 | + return JsonSerializer::serialize($body, ['remove_null' => \false]); |
|
109 | + } |
|
110 | + throw new ContentTypeException(sprintf("The Content-Type %s is not managed by Elasticsearch serializer", $contentType)); |
|
111 | + } |
|
112 | + /** |
|
113 | + * Create a PSR-7 request |
|
114 | + * |
|
115 | + * @param array|string $body |
|
116 | + */ |
|
117 | + protected function createRequest(string $method, string $url, array $headers, $body = null) : RequestInterface |
|
118 | + { |
|
119 | + $requestFactory = Psr17FactoryDiscovery::findRequestFactory(); |
|
120 | + $streamFactory = Psr17FactoryDiscovery::findStreamFactory(); |
|
121 | + $request = $requestFactory->createRequest($method, $url); |
|
122 | + // Body request |
|
123 | + if (!empty($body)) { |
|
124 | + if (!isset($headers['Content-Type'])) { |
|
125 | + throw new ContentTypeException(sprintf("The Content-Type is missing for %s %s", $method, $url)); |
|
126 | + } |
|
127 | + $content = \is_string($body) ? $body : $this->bodySerialize($body, $headers['Content-Type']); |
|
128 | + $request = $request->withBody($streamFactory->createStream($content)); |
|
129 | + } |
|
130 | + $headers = $this->buildCompatibilityHeaders($headers); |
|
131 | + // Headers |
|
132 | + foreach ($headers as $name => $value) { |
|
133 | + $request = $request->withHeader($name, $value); |
|
134 | + } |
|
135 | + return $request; |
|
136 | + } |
|
137 | + /** |
|
138 | + * Build the API compatibility headers |
|
139 | + * transfrom Content-Type and Accept adding vnd.elasticsearch+ and compatible-with |
|
140 | + * |
|
141 | + * @see https://github.com/elastic/elasticsearch-php/pull/1142 |
|
142 | + */ |
|
143 | + protected function buildCompatibilityHeaders(array $headers) : array |
|
144 | + { |
|
145 | + if (isset($headers['Content-Type'])) { |
|
146 | + if (\preg_match('/application\\/([^,]+)$/', $headers['Content-Type'], $matches)) { |
|
147 | + $headers['Content-Type'] = sprintf(Client::API_COMPATIBILITY_HEADER, 'application', $matches[1]); |
|
148 | + } |
|
149 | + } |
|
150 | + if (isset($headers['Accept'])) { |
|
151 | + $values = \explode(',', $headers['Accept']); |
|
152 | + foreach ($values as &$value) { |
|
153 | + if (\preg_match('/(application|text)\\/([^,]+)/', $value, $matches)) { |
|
154 | + $value = sprintf(Client::API_COMPATIBILITY_HEADER, $matches[1], $matches[2]); |
|
155 | + } |
|
156 | + } |
|
157 | + $headers['Accept'] = \implode(',', $values); |
|
158 | + } |
|
159 | + return $headers; |
|
160 | + } |
|
161 | + /** |
|
162 | + * Check if the $required parameters are present in $params |
|
163 | + * @throws MissingParameterException |
|
164 | + */ |
|
165 | + protected function checkRequiredParameters(array $required, array $params) : void |
|
166 | + { |
|
167 | + foreach ($required as $req) { |
|
168 | + if (!isset($params[$req])) { |
|
169 | + throw new MissingParameterException(sprintf('The parameter %s is required', $req)); |
|
170 | + } |
|
171 | + } |
|
172 | + } |
|
173 | 173 | } |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | * Elasticsearch B.V licenses this file to you under the MIT License. |
12 | 12 | * See the LICENSE file in the project root for more information. |
13 | 13 | */ |
14 | -declare (strict_types=1); |
|
14 | +declare(strict_types=1); |
|
15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Elasticsearch\Traits; |
16 | 16 | |
17 | 17 | use OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Elasticsearch\Client; |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | } elseif (\is_array($value) && $this->isNestedArray($value) === \false) { |
67 | 67 | return \implode(',', $value); |
68 | 68 | } |
69 | - return (string) $value; |
|
69 | + return (string)$value; |
|
70 | 70 | } |
71 | 71 | /** |
72 | 72 | * Encode a value for a valid URL |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | if (empty($queryParams)) { |
93 | 93 | return $url; |
94 | 94 | } |
95 | - return $url . '?' . http_build_query($queryParams); |
|
95 | + return $url.'?'.http_build_query($queryParams); |
|
96 | 96 | } |
97 | 97 | /** |
98 | 98 | * Serialize the body using the Content-Type |
@@ -25,8 +25,7 @@ |
||
25 | 25 | use function http_build_query; |
26 | 26 | use function strpos; |
27 | 27 | use function sprintf; |
28 | -trait EndpointTrait |
|
29 | -{ |
|
28 | +trait EndpointTrait { |
|
30 | 29 | /** |
31 | 30 | * Check if an array containts nested array |
32 | 31 | */ |
@@ -23,47 +23,47 @@ |
||
23 | 23 | use function strpos; |
24 | 24 | class NDJsonSerializer implements SerializerInterface |
25 | 25 | { |
26 | - /** |
|
27 | - * The available $options are: |
|
28 | - * 'remove_null' => (bool) enable/disable the removing of |
|
29 | - * null values (default is true) |
|
30 | - * |
|
31 | - * @param array $data |
|
32 | - */ |
|
33 | - public static function serialize($data, array $options = []) : string |
|
34 | - { |
|
35 | - $result = ''; |
|
36 | - foreach ($data as $row) { |
|
37 | - if (empty($row)) { |
|
38 | - $result .= "{}\n"; |
|
39 | - continue; |
|
40 | - } |
|
41 | - $result .= JsonSerializer::serialize($row, $options) . "\n"; |
|
42 | - } |
|
43 | - return $result; |
|
44 | - } |
|
45 | - /** |
|
46 | - * The available options are: |
|
47 | - * 'type' => (string) specify if the array result should contain object |
|
48 | - * or array (default is array) |
|
49 | - * |
|
50 | - * @inheritdoc |
|
51 | - */ |
|
52 | - public static function unserialize(string $data, array $options = []) |
|
53 | - { |
|
54 | - $array = explode(strpos($data, "\r\n") !== \false ? "\r\n" : "\n", $data); |
|
55 | - $result = []; |
|
56 | - foreach ($array as $json) { |
|
57 | - if (empty($json)) { |
|
58 | - continue; |
|
59 | - } |
|
60 | - try { |
|
61 | - $result[] = JsonSerializer::unserialize($json, $options); |
|
62 | - } catch (JsonException $e) { |
|
63 | - throw new InvalidJsonException(sprintf("Not a valid NDJson: %s", $e->getMessage())); |
|
64 | - } |
|
65 | - } |
|
66 | - $type = $options['type'] ?? 'array'; |
|
67 | - return $type === 'array' ? $result : new ArrayObject($result); |
|
68 | - } |
|
26 | + /** |
|
27 | + * The available $options are: |
|
28 | + * 'remove_null' => (bool) enable/disable the removing of |
|
29 | + * null values (default is true) |
|
30 | + * |
|
31 | + * @param array $data |
|
32 | + */ |
|
33 | + public static function serialize($data, array $options = []) : string |
|
34 | + { |
|
35 | + $result = ''; |
|
36 | + foreach ($data as $row) { |
|
37 | + if (empty($row)) { |
|
38 | + $result .= "{}\n"; |
|
39 | + continue; |
|
40 | + } |
|
41 | + $result .= JsonSerializer::serialize($row, $options) . "\n"; |
|
42 | + } |
|
43 | + return $result; |
|
44 | + } |
|
45 | + /** |
|
46 | + * The available options are: |
|
47 | + * 'type' => (string) specify if the array result should contain object |
|
48 | + * or array (default is array) |
|
49 | + * |
|
50 | + * @inheritdoc |
|
51 | + */ |
|
52 | + public static function unserialize(string $data, array $options = []) |
|
53 | + { |
|
54 | + $array = explode(strpos($data, "\r\n") !== \false ? "\r\n" : "\n", $data); |
|
55 | + $result = []; |
|
56 | + foreach ($array as $json) { |
|
57 | + if (empty($json)) { |
|
58 | + continue; |
|
59 | + } |
|
60 | + try { |
|
61 | + $result[] = JsonSerializer::unserialize($json, $options); |
|
62 | + } catch (JsonException $e) { |
|
63 | + throw new InvalidJsonException(sprintf("Not a valid NDJson: %s", $e->getMessage())); |
|
64 | + } |
|
65 | + } |
|
66 | + $type = $options['type'] ?? 'array'; |
|
67 | + return $type === 'array' ? $result : new ArrayObject($result); |
|
68 | + } |
|
69 | 69 | } |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | * Elasticsearch B.V licenses this file to you under the MIT License. |
12 | 12 | * See the LICENSE file in the project root for more information. |
13 | 13 | */ |
14 | -declare (strict_types=1); |
|
14 | +declare(strict_types=1); |
|
15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Serializer; |
16 | 16 | |
17 | 17 | use ArrayObject; |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | $result .= "{}\n"; |
39 | 39 | continue; |
40 | 40 | } |
41 | - $result .= JsonSerializer::serialize($row, $options) . "\n"; |
|
41 | + $result .= JsonSerializer::serialize($row, $options)."\n"; |
|
42 | 42 | } |
43 | 43 | return $result; |
44 | 44 | } |
@@ -21,8 +21,7 @@ |
||
21 | 21 | use function json_decode; |
22 | 22 | use function sprintf; |
23 | 23 | use function strpos; |
24 | -class NDJsonSerializer implements SerializerInterface |
|
25 | -{ |
|
24 | +class NDJsonSerializer implements SerializerInterface { |
|
26 | 25 | /** |
27 | 26 | * The available $options are: |
28 | 27 | * 'remove_null' => (bool) enable/disable the removing of |
@@ -21,30 +21,30 @@ |
||
21 | 21 | use function sprintf; |
22 | 22 | class Utility |
23 | 23 | { |
24 | - /** |
|
25 | - * Remove null values form array or object |
|
26 | - * |
|
27 | - * @param mixed $data |
|
28 | - * @return void |
|
29 | - */ |
|
30 | - public static function removeNullValue(&$data) : void |
|
31 | - { |
|
32 | - if (!is_object($data) && !is_array($data)) { |
|
33 | - throw new InvalidArgumentException(sprintf("The parameter %s must be an object or array", var_export($data, \true))); |
|
34 | - } |
|
35 | - /** @phpstan-ignore-next-line */ |
|
36 | - foreach ($data as $property => &$value) { |
|
37 | - if (is_object($value) || is_array($value)) { |
|
38 | - self::removeNullValue($value); |
|
39 | - } |
|
40 | - if (null === $value) { |
|
41 | - if (is_array($data)) { |
|
42 | - unset($data[$property]); |
|
43 | - } |
|
44 | - if (is_object($data)) { |
|
45 | - unset($data->{$property}); |
|
46 | - } |
|
47 | - } |
|
48 | - } |
|
49 | - } |
|
24 | + /** |
|
25 | + * Remove null values form array or object |
|
26 | + * |
|
27 | + * @param mixed $data |
|
28 | + * @return void |
|
29 | + */ |
|
30 | + public static function removeNullValue(&$data) : void |
|
31 | + { |
|
32 | + if (!is_object($data) && !is_array($data)) { |
|
33 | + throw new InvalidArgumentException(sprintf("The parameter %s must be an object or array", var_export($data, \true))); |
|
34 | + } |
|
35 | + /** @phpstan-ignore-next-line */ |
|
36 | + foreach ($data as $property => &$value) { |
|
37 | + if (is_object($value) || is_array($value)) { |
|
38 | + self::removeNullValue($value); |
|
39 | + } |
|
40 | + if (null === $value) { |
|
41 | + if (is_array($data)) { |
|
42 | + unset($data[$property]); |
|
43 | + } |
|
44 | + if (is_object($data)) { |
|
45 | + unset($data->{$property}); |
|
46 | + } |
|
47 | + } |
|
48 | + } |
|
49 | + } |
|
50 | 50 | } |
@@ -11,7 +11,7 @@ |
||
11 | 11 | * Elasticsearch B.V licenses this file to you under the MIT License. |
12 | 12 | * See the LICENSE file in the project root for more information. |
13 | 13 | */ |
14 | -declare (strict_types=1); |
|
14 | +declare(strict_types=1); |
|
15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Serializer; |
16 | 16 | |
17 | 17 | use OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Exception\InvalidArgumentException; |
@@ -19,8 +19,7 @@ |
||
19 | 19 | use function is_object; |
20 | 20 | use function var_export; |
21 | 21 | use function sprintf; |
22 | -class Utility |
|
23 | -{ |
|
22 | +class Utility { |
|
24 | 23 | /** |
25 | 24 | * Remove null values form array or object |
26 | 25 | * |
@@ -16,16 +16,16 @@ |
||
16 | 16 | |
17 | 17 | interface SerializerInterface |
18 | 18 | { |
19 | - /** |
|
20 | - * @param mixed $data |
|
21 | - * @param array $options |
|
22 | - * @return string |
|
23 | - */ |
|
24 | - public static function serialize($data, array $options = []) : string; |
|
25 | - /** |
|
26 | - * @param string $data |
|
27 | - * @param array $options |
|
28 | - * @return mixed |
|
29 | - */ |
|
30 | - public static function unserialize(string $data, array $options = []); |
|
19 | + /** |
|
20 | + * @param mixed $data |
|
21 | + * @param array $options |
|
22 | + * @return string |
|
23 | + */ |
|
24 | + public static function serialize($data, array $options = []) : string; |
|
25 | + /** |
|
26 | + * @param string $data |
|
27 | + * @param array $options |
|
28 | + * @return mixed |
|
29 | + */ |
|
30 | + public static function unserialize(string $data, array $options = []); |
|
31 | 31 | } |
@@ -11,7 +11,7 @@ |
||
11 | 11 | * Elasticsearch B.V licenses this file to you under the MIT License. |
12 | 12 | * See the LICENSE file in the project root for more information. |
13 | 13 | */ |
14 | -declare (strict_types=1); |
|
14 | +declare(strict_types=1); |
|
15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Serializer; |
16 | 16 | |
17 | 17 | interface SerializerInterface |
@@ -14,8 +14,7 @@ |
||
14 | 14 | declare (strict_types=1); |
15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Serializer; |
16 | 16 | |
17 | -interface SerializerInterface |
|
18 | -{ |
|
17 | +interface SerializerInterface { |
|
19 | 18 | /** |
20 | 19 | * @param mixed $data |
21 | 20 | * @param array $options |
@@ -22,36 +22,36 @@ |
||
22 | 22 | use function substr; |
23 | 23 | class CsvSerializer implements SerializerInterface |
24 | 24 | { |
25 | - /** |
|
26 | - * @inheritdoc |
|
27 | - * |
|
28 | - * @throws InvalidIterableException |
|
29 | - */ |
|
30 | - public static function serialize($data, array $options = []) : string |
|
31 | - { |
|
32 | - if (!is_iterable($data)) { |
|
33 | - throw new InvalidIterableException(sprintf("The parameter %s is not iterable", \serialize($data))); |
|
34 | - } |
|
35 | - $result = ''; |
|
36 | - foreach ($data as $row) { |
|
37 | - if (\is_array($row) || \is_object($row)) { |
|
38 | - $result .= \implode(',', (array) $row); |
|
39 | - } else { |
|
40 | - $result .= (string) $row; |
|
41 | - } |
|
42 | - $result .= "\n"; |
|
43 | - } |
|
44 | - return empty($result) ? $result : substr($result, 0, -1); |
|
45 | - } |
|
46 | - /** |
|
47 | - * @return array |
|
48 | - */ |
|
49 | - public static function unserialize(string $data, array $options = []) : array |
|
50 | - { |
|
51 | - $result = []; |
|
52 | - foreach (explode("\n", $data) as $row) { |
|
53 | - $result[] = str_getcsv($row); |
|
54 | - } |
|
55 | - return $result; |
|
56 | - } |
|
25 | + /** |
|
26 | + * @inheritdoc |
|
27 | + * |
|
28 | + * @throws InvalidIterableException |
|
29 | + */ |
|
30 | + public static function serialize($data, array $options = []) : string |
|
31 | + { |
|
32 | + if (!is_iterable($data)) { |
|
33 | + throw new InvalidIterableException(sprintf("The parameter %s is not iterable", \serialize($data))); |
|
34 | + } |
|
35 | + $result = ''; |
|
36 | + foreach ($data as $row) { |
|
37 | + if (\is_array($row) || \is_object($row)) { |
|
38 | + $result .= \implode(',', (array) $row); |
|
39 | + } else { |
|
40 | + $result .= (string) $row; |
|
41 | + } |
|
42 | + $result .= "\n"; |
|
43 | + } |
|
44 | + return empty($result) ? $result : substr($result, 0, -1); |
|
45 | + } |
|
46 | + /** |
|
47 | + * @return array |
|
48 | + */ |
|
49 | + public static function unserialize(string $data, array $options = []) : array |
|
50 | + { |
|
51 | + $result = []; |
|
52 | + foreach (explode("\n", $data) as $row) { |
|
53 | + $result[] = str_getcsv($row); |
|
54 | + } |
|
55 | + return $result; |
|
56 | + } |
|
57 | 57 | } |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | * Elasticsearch B.V licenses this file to you under the MIT License. |
12 | 12 | * See the LICENSE file in the project root for more information. |
13 | 13 | */ |
14 | -declare (strict_types=1); |
|
14 | +declare(strict_types=1); |
|
15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Serializer; |
16 | 16 | |
17 | 17 | use OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Exception\InvalidIterableException; |
@@ -35,9 +35,9 @@ discard block |
||
35 | 35 | $result = ''; |
36 | 36 | foreach ($data as $row) { |
37 | 37 | if (\is_array($row) || \is_object($row)) { |
38 | - $result .= \implode(',', (array) $row); |
|
38 | + $result .= \implode(',', (array)$row); |
|
39 | 39 | } else { |
40 | - $result .= (string) $row; |
|
40 | + $result .= (string)$row; |
|
41 | 41 | } |
42 | 42 | $result .= "\n"; |
43 | 43 | } |
@@ -20,8 +20,7 @@ |
||
20 | 20 | use function sprintf; |
21 | 21 | use function str_getcsv; |
22 | 22 | use function substr; |
23 | -class CsvSerializer implements SerializerInterface |
|
24 | -{ |
|
23 | +class CsvSerializer implements SerializerInterface { |
|
25 | 24 | /** |
26 | 25 | * @inheritdoc |
27 | 26 | * |
@@ -23,48 +23,48 @@ |
||
23 | 23 | use function sprintf; |
24 | 24 | class JsonSerializer implements SerializerInterface |
25 | 25 | { |
26 | - /** |
|
27 | - * The available $options are: |
|
28 | - * 'remove_null' => (bool) enable/disable the removing of |
|
29 | - * null values (default is true) |
|
30 | - * |
|
31 | - * @param mixed $data |
|
32 | - */ |
|
33 | - public static function serialize($data, array $options = []) : string |
|
34 | - { |
|
35 | - if (empty($data)) { |
|
36 | - return '{}'; |
|
37 | - } |
|
38 | - if (\is_string($data)) { |
|
39 | - return $data; |
|
40 | - } |
|
41 | - try { |
|
42 | - $removeNull = $options['remove_null'] ?? \true; |
|
43 | - if ($removeNull) { |
|
44 | - Utility::removeNullValue($data); |
|
45 | - } |
|
46 | - return json_encode($data, \JSON_PRESERVE_ZERO_FRACTION + \JSON_INVALID_UTF8_SUBSTITUTE + \JSON_THROW_ON_ERROR); |
|
47 | - } catch (JsonException $e) { |
|
48 | - throw new InvalidJsonException(sprintf("I cannot serialize to Json: %s", $e->getMessage())); |
|
49 | - } |
|
50 | - } |
|
51 | - /** |
|
52 | - * The available options are: |
|
53 | - * 'type' => (string) specify if the output should be an array |
|
54 | - * or an object (default is array) |
|
55 | - * |
|
56 | - * @inheritdoc |
|
57 | - */ |
|
58 | - public static function unserialize(string $data, array $options = []) |
|
59 | - { |
|
60 | - try { |
|
61 | - $type = $options['type'] ?? 'array'; |
|
62 | - if (!in_array($type, ['object', 'array'])) { |
|
63 | - throw new UndefinedPropertyException("The unserialize 'type' option must be object or array"); |
|
64 | - } |
|
65 | - return json_decode($data, $type === 'array', 512, \JSON_THROW_ON_ERROR); |
|
66 | - } catch (JsonException $e) { |
|
67 | - throw new InvalidJsonException(sprintf("Not a valid Json: %s", $e->getMessage())); |
|
68 | - } |
|
69 | - } |
|
26 | + /** |
|
27 | + * The available $options are: |
|
28 | + * 'remove_null' => (bool) enable/disable the removing of |
|
29 | + * null values (default is true) |
|
30 | + * |
|
31 | + * @param mixed $data |
|
32 | + */ |
|
33 | + public static function serialize($data, array $options = []) : string |
|
34 | + { |
|
35 | + if (empty($data)) { |
|
36 | + return '{}'; |
|
37 | + } |
|
38 | + if (\is_string($data)) { |
|
39 | + return $data; |
|
40 | + } |
|
41 | + try { |
|
42 | + $removeNull = $options['remove_null'] ?? \true; |
|
43 | + if ($removeNull) { |
|
44 | + Utility::removeNullValue($data); |
|
45 | + } |
|
46 | + return json_encode($data, \JSON_PRESERVE_ZERO_FRACTION + \JSON_INVALID_UTF8_SUBSTITUTE + \JSON_THROW_ON_ERROR); |
|
47 | + } catch (JsonException $e) { |
|
48 | + throw new InvalidJsonException(sprintf("I cannot serialize to Json: %s", $e->getMessage())); |
|
49 | + } |
|
50 | + } |
|
51 | + /** |
|
52 | + * The available options are: |
|
53 | + * 'type' => (string) specify if the output should be an array |
|
54 | + * or an object (default is array) |
|
55 | + * |
|
56 | + * @inheritdoc |
|
57 | + */ |
|
58 | + public static function unserialize(string $data, array $options = []) |
|
59 | + { |
|
60 | + try { |
|
61 | + $type = $options['type'] ?? 'array'; |
|
62 | + if (!in_array($type, ['object', 'array'])) { |
|
63 | + throw new UndefinedPropertyException("The unserialize 'type' option must be object or array"); |
|
64 | + } |
|
65 | + return json_decode($data, $type === 'array', 512, \JSON_THROW_ON_ERROR); |
|
66 | + } catch (JsonException $e) { |
|
67 | + throw new InvalidJsonException(sprintf("Not a valid Json: %s", $e->getMessage())); |
|
68 | + } |
|
69 | + } |
|
70 | 70 | } |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | * Elasticsearch B.V licenses this file to you under the MIT License. |
12 | 12 | * See the LICENSE file in the project root for more information. |
13 | 13 | */ |
14 | -declare (strict_types=1); |
|
14 | +declare(strict_types=1); |
|
15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Serializer; |
16 | 16 | |
17 | 17 | use OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Exception\InvalidJsonException; |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | if ($removeNull) { |
44 | 44 | Utility::removeNullValue($data); |
45 | 45 | } |
46 | - return json_encode($data, \JSON_PRESERVE_ZERO_FRACTION + \JSON_INVALID_UTF8_SUBSTITUTE + \JSON_THROW_ON_ERROR); |
|
46 | + return json_encode($data, \JSON_PRESERVE_ZERO_FRACTION +\JSON_INVALID_UTF8_SUBSTITUTE +\JSON_THROW_ON_ERROR); |
|
47 | 47 | } catch (JsonException $e) { |
48 | 48 | throw new InvalidJsonException(sprintf("I cannot serialize to Json: %s", $e->getMessage())); |
49 | 49 | } |
@@ -21,8 +21,7 @@ |
||
21 | 21 | use function json_decode; |
22 | 22 | use function json_encode; |
23 | 23 | use function sprintf; |
24 | -class JsonSerializer implements SerializerInterface |
|
25 | -{ |
|
24 | +class JsonSerializer implements SerializerInterface { |
|
26 | 25 | /** |
27 | 26 | * The available $options are: |
28 | 27 | * 'remove_null' => (bool) enable/disable the removing of |
@@ -18,21 +18,21 @@ |
||
18 | 18 | use function serialize; |
19 | 19 | class TextSerializer implements SerializerInterface |
20 | 20 | { |
21 | - /** |
|
22 | - * @throws SerializeException |
|
23 | - */ |
|
24 | - public static function serialize($data, array $options = []) : string |
|
25 | - { |
|
26 | - if (\is_string($data) || \is_numeric($data) || \is_object($data) && \method_exists($data, '__toString')) { |
|
27 | - return (string) $data; |
|
28 | - } |
|
29 | - throw new SerializeException(\sprintf("I cannot serialize %s in a text", serialize($data))); |
|
30 | - } |
|
31 | - /** |
|
32 | - * @return string |
|
33 | - */ |
|
34 | - public static function unserialize(string $data, array $options = []) : string |
|
35 | - { |
|
36 | - return $data; |
|
37 | - } |
|
21 | + /** |
|
22 | + * @throws SerializeException |
|
23 | + */ |
|
24 | + public static function serialize($data, array $options = []) : string |
|
25 | + { |
|
26 | + if (\is_string($data) || \is_numeric($data) || \is_object($data) && \method_exists($data, '__toString')) { |
|
27 | + return (string) $data; |
|
28 | + } |
|
29 | + throw new SerializeException(\sprintf("I cannot serialize %s in a text", serialize($data))); |
|
30 | + } |
|
31 | + /** |
|
32 | + * @return string |
|
33 | + */ |
|
34 | + public static function unserialize(string $data, array $options = []) : string |
|
35 | + { |
|
36 | + return $data; |
|
37 | + } |
|
38 | 38 | } |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | * Elasticsearch B.V licenses this file to you under the MIT License. |
12 | 12 | * See the LICENSE file in the project root for more information. |
13 | 13 | */ |
14 | -declare (strict_types=1); |
|
14 | +declare(strict_types=1); |
|
15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Serializer; |
16 | 16 | |
17 | 17 | use OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Exception\SerializeException; |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | public static function serialize($data, array $options = []) : string |
25 | 25 | { |
26 | 26 | if (\is_string($data) || \is_numeric($data) || \is_object($data) && \method_exists($data, '__toString')) { |
27 | - return (string) $data; |
|
27 | + return (string)$data; |
|
28 | 28 | } |
29 | 29 | throw new SerializeException(\sprintf("I cannot serialize %s in a text", serialize($data))); |
30 | 30 | } |
@@ -16,8 +16,7 @@ |
||
16 | 16 | |
17 | 17 | use OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Exception\SerializeException; |
18 | 18 | use function serialize; |
19 | -class TextSerializer implements SerializerInterface |
|
20 | -{ |
|
19 | +class TextSerializer implements SerializerInterface { |
|
21 | 20 | /** |
22 | 21 | * @throws SerializeException |
23 | 22 | */ |
@@ -23,25 +23,25 @@ |
||
23 | 23 | use function sprintf; |
24 | 24 | class XmlSerializer implements SerializerInterface |
25 | 25 | { |
26 | - public static function serialize($data, array $options = []) : string |
|
27 | - { |
|
28 | - if ($data instanceof SimpleXMLElement) { |
|
29 | - $xml = $data->asXML(); |
|
30 | - return \false === $xml ? '' : $xml; |
|
31 | - } |
|
32 | - throw new InvalidXmlException(sprintf("Not a valid SimpleXMLElement: %s", serialize($data))); |
|
33 | - } |
|
34 | - /** |
|
35 | - * @return SimpleXMLElement |
|
36 | - */ |
|
37 | - public static function unserialize(string $data, array $options = []) : SimpleXMLElement |
|
38 | - { |
|
39 | - $result = simplexml_load_string($data); |
|
40 | - if (\false === $result) { |
|
41 | - $errors = libxml_get_errors(); |
|
42 | - libxml_clear_errors(); |
|
43 | - throw new InvalidXmlException(sprintf("Not a valid XML: %s", serialize($errors))); |
|
44 | - } |
|
45 | - return $result; |
|
46 | - } |
|
26 | + public static function serialize($data, array $options = []) : string |
|
27 | + { |
|
28 | + if ($data instanceof SimpleXMLElement) { |
|
29 | + $xml = $data->asXML(); |
|
30 | + return \false === $xml ? '' : $xml; |
|
31 | + } |
|
32 | + throw new InvalidXmlException(sprintf("Not a valid SimpleXMLElement: %s", serialize($data))); |
|
33 | + } |
|
34 | + /** |
|
35 | + * @return SimpleXMLElement |
|
36 | + */ |
|
37 | + public static function unserialize(string $data, array $options = []) : SimpleXMLElement |
|
38 | + { |
|
39 | + $result = simplexml_load_string($data); |
|
40 | + if (\false === $result) { |
|
41 | + $errors = libxml_get_errors(); |
|
42 | + libxml_clear_errors(); |
|
43 | + throw new InvalidXmlException(sprintf("Not a valid XML: %s", serialize($errors))); |
|
44 | + } |
|
45 | + return $result; |
|
46 | + } |
|
47 | 47 | } |
@@ -11,7 +11,7 @@ |
||
11 | 11 | * Elasticsearch B.V licenses this file to you under the MIT License. |
12 | 12 | * See the LICENSE file in the project root for more information. |
13 | 13 | */ |
14 | -declare (strict_types=1); |
|
14 | +declare(strict_types=1); |
|
15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Serializer; |
16 | 16 | |
17 | 17 | use OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Exception\InvalidXmlException; |
@@ -21,8 +21,7 @@ |
||
21 | 21 | use function serialize; |
22 | 22 | use function simplexml_load_string; |
23 | 23 | use function sprintf; |
24 | -class XmlSerializer implements SerializerInterface |
|
25 | -{ |
|
24 | +class XmlSerializer implements SerializerInterface { |
|
26 | 25 | public static function serialize($data, array $options = []) : string |
27 | 26 | { |
28 | 27 | if ($data instanceof SimpleXMLElement) { |
@@ -11,7 +11,7 @@ |
||
11 | 11 | * Elasticsearch B.V licenses this file to you under the MIT License. |
12 | 12 | * See the LICENSE file in the project root for more information. |
13 | 13 | */ |
14 | -declare (strict_types=1); |
|
14 | +declare(strict_types=1); |
|
15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Exception; |
16 | 16 | |
17 | 17 | use RuntimeException; |
@@ -15,6 +15,5 @@ |
||
15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Exception; |
16 | 16 | |
17 | 17 | use RuntimeException; |
18 | -class InvalidArrayException extends RuntimeException implements TransportException |
|
19 | -{ |
|
18 | +class InvalidArrayException extends RuntimeException implements TransportException { |
|
20 | 19 | } |