Submit
Path:
~
/
/
proc
/
thread-self
/
root
/
opt
/
psa
/
admin
/
plib
/
modules
/
rest-api
/
vendor
/
jms
/
serializer
/
src
/
File Content:
JsonDeserializationVisitor.php
<?php declare (strict_types=1); namespace PleskRestApi\JMS\Serializer; use PleskRestApi\JMS\Serializer\Exception\LogicException; use PleskRestApi\JMS\Serializer\Exception\NotAcceptableException; use PleskRestApi\JMS\Serializer\Exception\RuntimeException; use PleskRestApi\JMS\Serializer\Metadata\ClassMetadata; use PleskRestApi\JMS\Serializer\Metadata\PropertyMetadata; use PleskRestApi\JMS\Serializer\Visitor\DeserializationVisitorInterface; final class JsonDeserializationVisitor extends AbstractVisitor implements DeserializationVisitorInterface { /** * @var int */ private $options; /** * @var int */ private $depth; /** * @var \SplStack */ private $objectStack; /** * @var object|null */ private $currentObject; public function __construct(int $options = 0, int $depth = 512) { $this->objectStack = new \SplStack(); $this->options = $options; $this->depth = $depth; } /** * {@inheritdoc} */ public function visitNull($data, array $type) { return null; } /** * {@inheritdoc} */ public function visitString($data, array $type) : string { $this->assertValueCanBeCastToString($data); return (string) $data; } /** * {@inheritdoc} */ public function visitBoolean($data, array $type) : bool { return (bool) $data; } /** * {@inheritdoc} */ public function visitInteger($data, array $type) : int { $this->assertValueCanBeCastToInt($data); return (int) $data; } /** * {@inheritdoc} */ public function visitDouble($data, array $type) : float { $this->assertValueCanCastToFloat($data); return (float) $data; } /** * {@inheritdoc} */ public function visitArray($data, array $type) : array { if (!\is_array($data)) { throw new RuntimeException(\sprintf('Expected array, but got %s: %s', \gettype($data), \json_encode($data))); } // If no further parameters were given, keys/values are just passed as is. if (!$type['params']) { return $data; } switch (\count($type['params'])) { case 1: // Array is a list. $listType = $type['params'][0]; $result = []; foreach ($data as $v) { $result[] = $this->navigator->accept($v, $listType); } return $result; case 2: // Array is a map. [$keyType, $entryType] = $type['params']; $result = []; foreach ($data as $k => $v) { $result[$this->navigator->accept($k, $keyType)] = $this->navigator->accept($v, $entryType); } return $result; default: throw new RuntimeException(\sprintf('Array type cannot have more than 2 parameters, but got %s.', \json_encode($type['params']))); } } /** * {@inheritdoc} */ public function visitDiscriminatorMapProperty($data, ClassMetadata $metadata) : string { if (isset($data[$metadata->discriminatorFieldName])) { return (string) $data[$metadata->discriminatorFieldName]; } throw new LogicException(\sprintf('The discriminator field name "%s" for base-class "%s" was not found in input data.', $metadata->discriminatorFieldName, $metadata->name)); } /** * {@inheritdoc} */ public function startVisitingObject(ClassMetadata $metadata, object $object, array $type) : void { $this->setCurrentObject($object); } /** * {@inheritdoc} */ public function visitProperty(PropertyMetadata $metadata, $data) { $name = $metadata->serializedName; if (null === $data) { return; } if (!\is_array($data)) { throw new RuntimeException(\sprintf('Invalid data %s (%s), expected "%s".', \json_encode($data), $metadata->type['name'], $metadata->class)); } if (\true === $metadata->inline) { if (!$metadata->type) { throw RuntimeException::noMetadataForProperty($metadata->class, $metadata->name); } return $this->navigator->accept($data, $metadata->type); } if (!\array_key_exists($name, $data)) { throw new NotAcceptableException(); } if (!$metadata->type) { throw RuntimeException::noMetadataForProperty($metadata->class, $metadata->name); } return null !== $data[$name] ? $this->navigator->accept($data[$name], $metadata->type) : null; } /** * {@inheritdoc} */ public function endVisitingObject(ClassMetadata $metadata, $data, array $type) : object { $obj = $this->currentObject; $this->revertCurrentObject(); return $obj; } /** * {@inheritdoc} */ public function getResult($data) { unset($this->navigator); return $data; } public function setCurrentObject(object $object) : void { $this->objectStack->push($this->currentObject); $this->currentObject = $object; } public function getCurrentObject() : ?object { return $this->currentObject; } public function revertCurrentObject() : ?object { return $this->currentObject = $this->objectStack->pop(); } /** * {@inheritdoc} */ public function prepare($str) { $decoded = \json_decode($str, \true, $this->depth, $this->options); switch (\json_last_error()) { case \JSON_ERROR_NONE: return $decoded; case \JSON_ERROR_DEPTH: throw new RuntimeException('Could not decode JSON, maximum stack depth exceeded.'); case \JSON_ERROR_STATE_MISMATCH: throw new RuntimeException('Could not decode JSON, underflow or the nodes mismatch.'); case \JSON_ERROR_CTRL_CHAR: throw new RuntimeException('Could not decode JSON, unexpected control character found.'); case \JSON_ERROR_SYNTAX: throw new RuntimeException('Could not decode JSON, syntax error - malformed JSON.'); case \JSON_ERROR_UTF8: throw new RuntimeException('Could not decode JSON, malformed UTF-8 characters (incorrectly encoded?)'); default: throw new RuntimeException('Could not decode JSON.'); } } }
Edit
Rename
Chmod
Delete
FILE
FOLDER
INFO
Name
Size
Permission
Action
Accessor
---
0755
Annotation
---
0755
Builder
---
0755
Construction
---
0755
ContextFactory
---
0755
EventDispatcher
---
0755
Exception
---
0755
Exclusion
---
0755
Expression
---
0755
GraphNavigator
---
0755
Handler
---
0755
Metadata
---
0755
Naming
---
0755
Ordering
---
0755
Twig
---
0755
Type
---
0755
Visitor
---
0755
AbstractVisitor.php
3109 bytes
0644
ArrayTransformerInterface.php
930 bytes
0644
Context.php
6343 bytes
0644
DeserializationContext.php
799 bytes
0644
Functions.php
428 bytes
0644
GraphNavigator.php
1101 bytes
0644
GraphNavigatorInterface.php
1042 bytes
0644
JsonDeserializationStrictVisitor.php
4126 bytes
0644
JsonDeserializationVisitor.php
6654 bytes
0644
JsonSerializationVisitor.php
5223 bytes
0644
NullAwareVisitorInterface.php
360 bytes
0644
SerializationContext.php
3502 bytes
0644
Serializer.php
8806 bytes
0644
SerializerBuilder.php
21683 bytes
0644
SerializerInterface.php
793 bytes
0644
VisitorInterface.php
950 bytes
0644
XmlDeserializationVisitor.php
16239 bytes
0644
XmlSerializationVisitor.php
16831 bytes
0644
N4ST4R_ID | Naxtarrr