1: <?php
2: /**
3: * Category
4: *
5: * PHP version 7.4
6: *
7: * @category Class
8: * @package Ally\PetStore
9: * @author OpenAPI Generator team
10: * @link https://openapi-generator.tech
11: */
12:
13: /**
14: * OpenAPI Petstore
15: *
16: * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
17: *
18: * The version of the OpenAPI document: 1.0.0
19: * Generated by: https://openapi-generator.tech
20: * OpenAPI Generator version: 6.1.0-SNAPSHOT
21: */
22:
23: /**
24: * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
25: * https://openapi-generator.tech
26: * Do not edit the class manually.
27: */
28:
29: namespace Ally\PetStore\Schema;
30:
31: use \ArrayAccess;
32: use \Ally\PetStore\ObjectSerializer;
33:
34: /**
35: * Category Class Doc Comment
36: *
37: * @category Class
38: * @description A category for a pet
39: * @package Ally\PetStore
40: * @author OpenAPI Generator team
41: * @link https://openapi-generator.tech
42: * @implements \ArrayAccess<string, mixed>
43: */
44: class Category implements ModelInterface, ArrayAccess, \JsonSerializable
45: {
46: public const DISCRIMINATOR = null;
47:
48: /**
49: * The original name of the model.
50: *
51: * @var string
52: */
53: protected static $openAPIModelName = 'Category';
54:
55: /**
56: * Array of property to type mappings. Used for (de)serialization
57: *
58: * @var string[]
59: */
60: protected static $openAPITypes = [
61: 'id' => 'int',
62: 'name' => 'string'
63: ];
64:
65: /**
66: * Array of property to format mappings. Used for (de)serialization
67: *
68: * @var string[]
69: * @phpstan-var array<string, string|null>
70: * @psalm-var array<string, string|null>
71: */
72: protected static $openAPIFormats = [
73: 'id' => 'int64',
74: 'name' => null
75: ];
76:
77: /**
78: * Array of nullable properties. Used for (de)serialization
79: *
80: * @var boolean[]
81: */
82: protected static array $openAPINullables = [
83: 'id' => false,
84: 'name' => false
85: ];
86:
87: /**
88: * If a nullable field gets set to null, insert it here
89: *
90: * @var boolean[]
91: */
92: protected array $openAPINullablesSetToNull = [];
93:
94: /**
95: * Array of property to type mappings. Used for (de)serialization
96: *
97: * @return array
98: */
99: public static function openAPITypes()
100: {
101: return self::$openAPITypes;
102: }
103:
104: /**
105: * Array of property to format mappings. Used for (de)serialization
106: *
107: * @return array
108: */
109: public static function openAPIFormats()
110: {
111: return self::$openAPIFormats;
112: }
113:
114: /**
115: * Array of nullable properties
116: *
117: * @return array
118: */
119: protected static function openAPINullables(): array
120: {
121: return self::$openAPINullables;
122: }
123:
124: /**
125: * Array of nullable field names deliberately set to null
126: *
127: * @return boolean[]
128: */
129: private function getOpenAPINullablesSetToNull(): array
130: {
131: return $this->openAPINullablesSetToNull;
132: }
133:
134: /**
135: * Checks if a property is nullable
136: *
137: * @param string $property
138: * @return bool
139: */
140: public static function isNullable(string $property): bool
141: {
142: return self::openAPINullables()[$property] ?? false;
143: }
144:
145: /**
146: * Checks if a nullable property is set to null.
147: *
148: * @param string $property
149: * @return bool
150: */
151: public function isNullableSetToNull(string $property): bool
152: {
153: return in_array($property, $this->getOpenAPINullablesSetToNull(), true);
154: }
155:
156: /**
157: * Array of attributes where the key is the local name,
158: * and the value is the original name
159: *
160: * @var string[]
161: */
162: protected static $attributeMap = [
163: 'id' => 'id',
164: 'name' => 'name'
165: ];
166:
167: /**
168: * Array of attributes to setter functions (for deserialization of responses)
169: *
170: * @var string[]
171: */
172: protected static $setters = [
173: 'id' => 'setId',
174: 'name' => 'setName'
175: ];
176:
177: /**
178: * Array of attributes to getter functions (for serialization of requests)
179: *
180: * @var string[]
181: */
182: protected static $getters = [
183: 'id' => 'getId',
184: 'name' => 'getName'
185: ];
186:
187: /**
188: * Array of attributes where the key is the local name,
189: * and the value is the original name
190: *
191: * @return array
192: */
193: public static function attributeMap()
194: {
195: return self::$attributeMap;
196: }
197:
198: /**
199: * Array of attributes to setter functions (for deserialization of responses)
200: *
201: * @return array
202: */
203: public static function setters()
204: {
205: return self::$setters;
206: }
207:
208: /**
209: * Array of attributes to getter functions (for serialization of requests)
210: *
211: * @return array
212: */
213: public static function getters()
214: {
215: return self::$getters;
216: }
217:
218: /**
219: * The original name of the model.
220: *
221: * @return string
222: */
223: public function getModelName()
224: {
225: return self::$openAPIModelName;
226: }
227:
228:
229: /**
230: * Associative array for storing property values
231: *
232: * @var mixed[]
233: */
234: protected $container = [];
235:
236: /**
237: * Constructor
238: *
239: * @param mixed[] $data Associated array of property values
240: * initializing the model
241: */
242: public function __construct(array $data = null)
243: {
244: $this->setIfExists('id', $data ?? [], null);
245: $this->setIfExists('name', $data ?? [], null);
246: }
247:
248: /**
249: * Sets $this->container[$variableName] to the given data or to the given default Value; if $variableName
250: * is nullable and its value is set to null in the $fields array, then mark it as "set to null" in the
251: * $this->openAPINullablesSetToNull array
252: *
253: * @param string $variableName
254: * @param array $fields
255: * @param mixed $defaultValue
256: */
257: private function setIfExists(string $variableName, array $fields, $defaultValue): void
258: {
259: if (self::isNullable($variableName) && array_key_exists($variableName, $fields) && is_null($fields[$variableName])) {
260: $this->openAPINullablesSetToNull[] = $variableName;
261: }
262:
263: $this->container[$variableName] = $fields[$variableName] ?? $defaultValue;
264: }
265:
266: /**
267: * Show all the invalid properties with reasons.
268: *
269: * @return array invalid properties with reasons
270: */
271: public function listInvalidProperties()
272: {
273: $invalidProperties = [];
274:
275: if (!is_null($this->container['name']) && !preg_match("/^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$/", $this->container['name'])) {
276: $invalidProperties[] = "invalid value for 'name', must be conform to the pattern /^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$/.";
277: }
278:
279: return $invalidProperties;
280: }
281:
282: /**
283: * Validate all the properties in the model
284: * return true if all passed
285: *
286: * @return bool True if all properties are valid
287: */
288: public function valid()
289: {
290: return count($this->listInvalidProperties()) === 0;
291: }
292:
293:
294: /**
295: * Gets id
296: *
297: * @return int|null
298: */
299: public function getId()
300: {
301: return $this->container['id'];
302: }
303:
304: /**
305: * Sets id
306: *
307: * @param int|null $id id
308: *
309: * @return self
310: */
311: public function setId($id)
312: {
313:
314: if (is_null($id)) {
315: throw new \InvalidArgumentException('non-nullable id cannot be null');
316: }
317:
318: $this->container['id'] = $id;
319:
320: return $this;
321: }
322:
323: /**
324: * Gets name
325: *
326: * @return string|null
327: */
328: public function getName()
329: {
330: return $this->container['name'];
331: }
332:
333: /**
334: * Sets name
335: *
336: * @param string|null $name name
337: *
338: * @return self
339: */
340: public function setName($name)
341: {
342:
343: if (!is_null($name) && (!preg_match("/^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$/", $name))) {
344: throw new \InvalidArgumentException("invalid value for \$name when calling Category., must conform to the pattern /^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$/.");
345: }
346:
347:
348: if (is_null($name)) {
349: throw new \InvalidArgumentException('non-nullable name cannot be null');
350: }
351:
352: $this->container['name'] = $name;
353:
354: return $this;
355: }
356: /**
357: * Returns true if offset exists. False otherwise.
358: *
359: * @param integer $offset Offset
360: *
361: * @return boolean
362: */
363: public function offsetExists($offset): bool
364: {
365: return isset($this->container[$offset]);
366: }
367:
368: /**
369: * Gets offset.
370: *
371: * @param integer $offset Offset
372: *
373: * @return mixed|null
374: */
375: #[\ReturnTypeWillChange]
376: public function offsetGet($offset)
377: {
378: return $this->container[$offset] ?? null;
379: }
380:
381: /**
382: * Sets value based on offset.
383: *
384: * @param int|null $offset Offset
385: * @param mixed $value Value to be set
386: *
387: * @return void
388: */
389: public function offsetSet($offset, $value): void
390: {
391: if (is_null($offset)) {
392: $this->container[] = $value;
393: } else {
394: $this->container[$offset] = $value;
395: }
396: }
397:
398: /**
399: * Unsets offset.
400: *
401: * @param integer $offset Offset
402: *
403: * @return void
404: */
405: public function offsetUnset($offset): void
406: {
407: unset($this->container[$offset]);
408: }
409:
410: /**
411: * Serializes the object to a value that can be serialized natively by json_encode().
412: * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php
413: *
414: * @return mixed Returns data which can be serialized by json_encode(), which is a value
415: * of any type other than a resource.
416: */
417: #[\ReturnTypeWillChange]
418: public function jsonSerialize()
419: {
420: return ObjectSerializer::sanitizeForSerialization($this);
421: }
422:
423: /**
424: * Gets the string presentation of the object
425: *
426: * @return string
427: */
428: public function __toString()
429: {
430: return json_encode(
431: ObjectSerializer::sanitizeForSerialization($this),
432: JSON_PRETTY_PRINT
433: );
434: }
435:
436: /**
437: * Gets a header-safe presentation of the object
438: *
439: * @return string
440: */
441: public function toHeaderValue()
442: {
443: return json_encode(ObjectSerializer::sanitizeForSerialization($this));
444: }
445: }
446:
447:
448: