PluginProbe ʕ •ᴥ•ʔ
WooCommerce Square / 2.2.5
WooCommerce Square v2.2.5
5.5.0 5.4.3 5.4.2 5.4.1 5.4.0 trunk 1.0.25 1.0.26 1.0.27 1.0.28 1.0.29 1.0.30 1.0.31 1.0.32 1.0.33 1.0.34 1.0.35 1.0.36 1.0.37 1.0.38 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.7.0 2.8.0 2.9.0 2.9.1 3.0.0 3.0.1 3.0.2 3.0.3 3.1.0 3.2.0 3.3.0 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.6.1 3.7.0 3.7.1 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 4.0.0 4.1.0 4.2.0 4.2.1 4.2.2 4.2.3 4.3.0 4.3.1 4.3.2 4.4.0 4.4.1 4.4.2 4.5.0 4.5.1 4.5.2 4.6.0 4.6.1 4.6.2 4.6.3 4.6.4 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.8.0 4.8.1 4.8.2 4.8.3 4.8.4 4.8.5 4.8.6 4.8.7 4.8.8 4.9.0 4.9.1 4.9.2 4.9.3 4.9.4 4.9.5 4.9.6 4.9.7 4.9.8 4.9.9 5.0.0 5.0.1 5.1.0 5.1.1 5.1.2 5.2.0 5.3.0 5.3.1 5.3.2 5.3.3
woocommerce-square / vendor / square / connect / lib / ObjectSerializer.php
woocommerce-square / vendor / square / connect / lib Last commit date
Api 7 years ago Model 7 years ago ApiClient.php 7 years ago ApiException.php 7 years ago Configuration.php 7 years ago ObjectSerializer.php 7 years ago
ObjectSerializer.php
256 lines
1 <?php
2 /**
3 * NOTE: This class is auto generated by the swagger code generator program.
4 * https://github.com/swagger-api/swagger-codegen
5 * Do not edit the class manually.
6 */
7
8 namespace SquareConnect;
9
10 /**
11 * ObjectSerializer Class Doc Comment
12 *
13 * @category Class
14 * @package SquareConnect
15 * @author Square Inc.
16 * @license http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2
17 * @link https://squareup.com/developers
18 */
19 class ObjectSerializer
20 {
21
22 /**
23 * Serialize data
24 *
25 * @param mixed $data the data to serialize
26 *
27 * @return string serialized form of $data
28 */
29 public static function sanitizeForSerialization($data)
30 {
31 if (is_scalar($data) || null === $data) {
32 $sanitized = $data;
33 } elseif ($data instanceof \DateTime) {
34 $sanitized = $data->format(\DateTime::ISO8601);
35 } elseif (is_array($data)) {
36 foreach ($data as $property => $value) {
37 $data[$property] = self::sanitizeForSerialization($value);
38 }
39 $sanitized = $data;
40 } elseif (is_object($data)) {
41 $values = array();
42 foreach (array_keys($data::$swaggerTypes) as $property) {
43 $getter = $data::$getters[$property];
44 if ($data->$getter() !== null) {
45 $values[$data::$attributeMap[$property]] = self::sanitizeForSerialization($data->$getter());
46 }
47 }
48 $sanitized = (object)$values;
49 } else {
50 $sanitized = (string)$data;
51 }
52
53 return $sanitized;
54 }
55
56 /**
57 * Sanitize filename by removing path.
58 * e.g. ../../sun.gif becomes sun.gif
59 *
60 * @param string $filename filename to be sanitized
61 *
62 * @return string the sanitized filename
63 */
64 public function sanitizeFilename($filename)
65 {
66 if (preg_match("/.*[\/\\\\](.*)$/", $filename, $match)) {
67 return $match[1];
68 } else {
69 return $filename;
70 }
71 }
72
73 /**
74 * Take value and turn it into a string suitable for inclusion in
75 * the path, by url-encoding.
76 *
77 * @param string $value a string which will be part of the path
78 *
79 * @return string the serialized object
80 */
81 public function toPathValue($value)
82 {
83 return rawurlencode($this->toString($value));
84 }
85
86 /**
87 * Take value and turn it into a string suitable for inclusion in
88 * the query, by imploding comma-separated if it's an object.
89 * If it's a string, pass through unchanged. It will be url-encoded
90 * later.
91 *
92 * @param object $object an object to be serialized to a string
93 *
94 * @return string the serialized object
95 */
96 public function toQueryValue($object)
97 {
98 if (is_array($object)) {
99 return implode(',', $object);
100 } else {
101 return $this->toString($object);
102 }
103 }
104
105 /**
106 * Take value and turn it into a string suitable for inclusion in
107 * the header. If it's a string, pass through unchanged
108 * If it's a datetime object, format it in ISO8601
109 *
110 * @param string $value a string which will be part of the header
111 *
112 * @return string the header string
113 */
114 public function toHeaderValue($value)
115 {
116 return $this->toString($value);
117 }
118
119 /**
120 * Take value and turn it into a string suitable for inclusion in
121 * the http body (form parameter). If it's a string, pass through unchanged
122 * If it's a datetime object, format it in ISO8601
123 *
124 * @param string $value the value of the form parameter
125 *
126 * @return string the form string
127 */
128 public function toFormValue($value)
129 {
130 if ($value instanceof \SplFileObject) {
131 return $value->getRealPath();
132 } else {
133 return $this->toString($value);
134 }
135 }
136
137 /**
138 * Take value and turn it into a string suitable for inclusion in
139 * the parameter. If it's a string, pass through unchanged
140 * If it's a datetime object, format it in ISO8601
141 *
142 * @param string $value the value of the parameter
143 *
144 * @return string the header string
145 */
146 public function toString($value)
147 {
148 if ($value instanceof \DateTime) { // datetime in ISO8601 format
149 return $value->format(\DateTime::ISO8601);
150 } else {
151 return $value;
152 }
153 }
154
155 /**
156 * Serialize an array to a string.
157 *
158 * @param array $collection collection to serialize to a string
159 * @param string $collectionFormat the format use for serialization (csv,
160 * ssv, tsv, pipes, multi)
161 *
162 * @return string
163 */
164 public function serializeCollection(array $collection, $collectionFormat, $allowCollectionFormatMulti=false)
165 {
166 if ($allowCollectionFormatMulti && ('multi' === $collectionFormat)) {
167 // http_build_query() almost does the job for us. We just
168 // need to fix the result of multidimensional arrays.
169 return preg_replace('/%5B[0-9]+%5D=/', '=', http_build_query($collection, '', '&'));
170 }
171 switch ($collectionFormat) {
172 case 'pipes':
173 return implode('|', $collection);
174
175 case 'tsv':
176 return implode("\t", $collection);
177
178 case 'ssv':
179 return implode(' ', $collection);
180
181 case 'csv':
182 // Deliberate fall through. CSV is default format.
183 default:
184 return implode(',', $collection);
185 }
186 }
187
188 /**
189 * Deserialize a JSON string into an object
190 *
191 * @param mixed $data object or primitive to be deserialized
192 * @param string $class class name is passed as a string
193 * @param string $httpHeaders HTTP headers
194 *
195 * @return object an instance of $class
196 */
197 public static function deserialize($data, $class, $httpHeaders=null)
198 {
199 if (null === $data) {
200 $deserialized = null;
201 } elseif (substr($class, 0, 4) === 'map[') { // for associative array e.g. map[string,int]
202 $inner = substr($class, 4, -1);
203 $deserialized = array();
204 if (strrpos($inner, ",") !== false) {
205 $subClass_array = explode(',', $inner, 2);
206 $subClass = $subClass_array[1];
207 foreach ($data as $key => $value) {
208 $deserialized[$key] = self::deserialize($value, $subClass);
209 }
210 }
211 } elseif (strcasecmp(substr($class, -2), '[]') == 0) {
212 $subClass = substr($class, 0, -2);
213 $values = array();
214 foreach ($data as $key => $value) {
215 $values[] = self::deserialize($value, $subClass);
216 }
217 $deserialized = $values;
218 } elseif ($class === 'ByteArray') { // byte array
219 $deserialized = unpack('C*', (string)$data);
220 } elseif ($class === '\DateTime') {
221 $deserialized = new \DateTime($data);
222 } elseif (in_array($class, array('DateTime', 'bool', 'boolean', 'byte', 'double', 'float', 'int', 'integer', 'mixed', 'number', 'object', 'string', 'void'))) {
223 settype($data, $class);
224 $deserialized = $data;
225 } elseif ($class === '\SplFileObject') {
226 // determine file name
227 if (array_key_exists('Content-Disposition', $httpHeaders) && preg_match('/inline; filename=[\'"]?([^\'"\s]+)[\'"]?$/i', $httpHeaders['Content-Disposition'], $match)) {
228 $filename = Configuration::getDefaultConfiguration()->getTempFolderPath() . sanitizeFilename($match[1]);
229 } else {
230 $filename = tempnam(Configuration::getDefaultConfiguration()->getTempFolderPath(), '');
231 }
232 $deserialized = new \SplFileObject($filename, "w");
233 $byte_written = $deserialized->fwrite($data);
234 error_log("[INFO] Written $byte_written byte to $filename. Please move the file to a proper folder or delete the temp file after processing.\n", 3, Configuration::getDefaultConfiguration()->getDebugFile());
235
236 } else {
237 $instance = new $class();
238 foreach ($instance::$swaggerTypes as $property => $type) {
239 $propertySetter = $instance::$setters[$property];
240
241 if (!isset($propertySetter) || !isset($data->{$instance::$attributeMap[$property]})) {
242 continue;
243 }
244
245 $propertyValue = $data->{$instance::$attributeMap[$property]};
246 if (isset($propertyValue)) {
247 $instance->$propertySetter(self::deserialize($propertyValue, $type));
248 }
249 }
250 $deserialized = $instance;
251 }
252
253 return $deserialized;
254 }
255 }
256