本文整理汇总了PHP中Symfony\Component\Serializer\Serializer::deserialize方法的典型用法代码示例。如果您正苦于以下问题:PHP Serializer::deserialize方法的具体用法?PHP Serializer::deserialize怎么用?PHP Serializer::deserialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Serializer\Serializer
的用法示例。
在下文中一共展示了Serializer::deserialize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: deserialize
public function deserialize($data, $type, $format, array $context = array())
{
if (!$type) {
$temp = $this->serializer->decode($data, $format, $context);
$type = isset($this->map[$temp['type']]) ? $this->map[$temp['type']] : 'Bangpound\\oEmbed\\Response\\Response';
}
return $this->serializer->deserialize($data, $type, $format, $context);
}
示例2: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln("CONECTANDO A WEBSERVICE VIA SOAP");
try {
$normalizer = new GetSetMethodNormalizer();
$encoder = new JsonEncoder();
$serializer = new Serializer(array($normalizer), array($encoder));
//retrieve WSDL
$this->client = new \nusoap_client("http://crm.cam-la.com/service/v4/soap.php?wsdl", 'true');
$this->executeLogin($input, $output);
//Obtengo todos los archivos que hay en la carpeta:
$path = $this->getApplication()->getKernel()->getContainer()->get('kernel')->getRootDir() . '/Resources/data/';
$files = scandir($path);
foreach ($files as $file) {
if (is_readable($path . $file) == false) {
continue;
}
if (is_file($path . $file) == false) {
continue;
}
$output->writeln("EJECUTANDO DATA " . $file);
$content = file_get_contents($path . $file);
$data = json_decode(json_encode($content), true);
$obj = $serializer->deserialize($data, 'BcTic\\Bundle\\AtencionCrmCamBundle\\Entity\\CustomerCase', 'json');
$this->uploadToDataBase($obj, $input, $output);
//Ahora debo eliminar el archivo, pues con otro comando los obtengo y los voy actualizando para consulta cada 5 minutos.
unlink($path . $file);
}
} catch (Exception $e) {
$output->writeln("ERROR: " . $e->getMessage());
}
$output->writeln("EJECUCION FINALIZADA. Good Bye!");
}
示例3: mapJsonToConnection
/**
* @param $json
* @return Connection
*/
private function mapJsonToConnection($json)
{
/* @var ConnectionDto $dto */
$dto = $this->serializer->deserialize($json, ConnectionDto::CLASS_NAME, 'json');
$connection = $this->assembler->assemble($dto);
return $connection;
}
示例4: deserialize
/**
* Deserializes a Json into readable datas
* @param string $string
*
* @return RZ\Roadiz\Core\Entities\Group
*/
public function deserialize($string)
{
if ($string == "") {
throw new \Exception('File is empty.');
}
$encoder = new JsonEncoder();
$nameConverter = new CamelCaseToSnakeCaseNameConverter(['name']);
$normalizer = new GetSetMethodNormalizer(null, $nameConverter);
$serializer = new Serializer([$normalizer], [$encoder]);
$group = $serializer->deserialize($string, 'RZ\\Roadiz\\Core\\Entities\\Group', 'json');
/*
* Importing Roles.
*
* We need to extract roles from group and to re-encode them
* to pass to RoleJsonSerializer.
*/
$tempArray = json_decode($string, true);
$data = [];
if (!empty($tempArray['roles'])) {
foreach ($tempArray['roles'] as $roleAssoc) {
$role = $this->roleSerializer->deserialize(json_encode($roleAssoc));
$role = $this->em->getRepository('RZ\\Roadiz\\Core\\Entities\\Role')->findOneByName($role->getName());
$group->addRole($role);
}
$data[] = $group;
}
return $data;
}
示例5: deserialize
/**
* Deserializes a json file into a readable array of datas.
*
* @param string $jsonString
*
* @return RZ\Roadiz\Core\Entities\NodeTypeField
*/
public static function deserialize($jsonString)
{
$encoder = new JsonEncoder();
$nameConverter = new CamelCaseToSnakeCaseNameConverter(['name', 'label', 'description', 'visible', 'type', 'indexed', 'virtual', 'default_values']);
$normalizer = new GetSetMethodNormalizer(null, $nameConverter);
$serializer = new Serializer([$normalizer], [$encoder]);
return $serializer->deserialize($jsonString, 'RZ\\Roadiz\\Core\\Entities\\NodeTypeField', 'json');
}
示例6: deserialize
private function deserialize($json, $entityName)
{
$encoders = array(new XmlEncoder(), new JsonEncoder());
$normalizers = array(new ObjectNormalizer());
$serializer = new Serializer($normalizers, $encoders);
$object = $serializer->deserialize($json, $entityName, 'json');
return $object;
}
示例7: send
/**
* Sends the passed Request and returns the response or a hydrated object.
*
* @param RequestInterface $request The Request to send.
* @param string $entityClass Optional entity class to hydrate.
* @return mixed The response or a hydrated object.
*/
protected function send(RequestInterface $request, $entityClass = null)
{
$response = $this->client->send($request);
$retVal = $response->getBody();
if ($entityClass !== null) {
$retVal = $this->serializer->deserialize($retVal, $entityClass, 'json');
}
return $retVal;
}
示例8: getAction
public function getAction()
{
$normalizer = new ObjectNormalizer(new ClassMetadataFactory(new YamlFileLoader(CONFIG_PATH . 'test_entity.yml')), new CamelCaseToSnakeCaseNameConverter());
$serializer = new Serializer([$normalizer], [new JsonEncoder(), new XmlEncoder()]);
$test = new TestEntity();
$test->setMessage('Test');
$test = $serializer->deserialize('<test><id>1</id></test>', 'DG\\SymfonyCert\\Entity\\TestEntity', 'xml', ['object_to_populate' => $test]);
return new Response($serializer->serialize($test, 'xml', ['groups' => ['group2']]), 200, ['Content-Type' => 'text/xml']);
}
示例9: synchronise
/**
* @override \ComponentRegistry\PackageRepository\PackageRepository
*/
public function synchronise($task)
{
$client = new Client();
// TODO: this is really shit
$data = $client->get(static::PLUGIN_LIST_URL)->getBody()->getContents();
// TODO: this is even shitter
$data = preg_replace(['/^{"timestamp":[0-9]+,"plugins":/', '/}$/'], '', $data);
$serialiser = new Serializer([new ArrayDenormalizer(), new GetSetMethodNormalizer(), new ObjectNormalizer()], [new JsonEncoder()]);
$components = $serialiser->deserialize($data, 'ComponentRegistry\\Entity\\Component[]', 'json');
}
示例10: deserialize
/**
* Deserializes a json file into a readable array of datas.
*
* @param string $jsonString
*
* @return RZ\Roadiz\Core\Entities\Role
*/
public function deserialize($jsonString)
{
if ($jsonString == "") {
throw new \Exception('File is empty.');
}
$encoder = new JsonEncoder();
$nameConverter = new CamelCaseToSnakeCaseNameConverter(['name']);
$normalizer = new GetSetMethodNormalizer(null, $nameConverter);
$serializer = new Serializer([$normalizer], [$encoder]);
return $serializer->deserialize($jsonString, 'RZ\\Roadiz\\Core\\Entities\\Role', 'json');
}
示例11: factory
/**
* @param HttpRequest $httpRequest
* @param Serializer $serializer
* @param array $context
*
* @return Request
*/
public static function factory(HttpRequest $httpRequest, Serializer $serializer, array $context = [])
{
$attributes = $httpRequest->attributes;
$content = $httpRequest->getContent();
$method = $attributes->get('method');
$params = $serializer->deserialize($content, ParamsDenormalizer::TYPE, 'rest', $context);
$id = $attributes->get('id');
$request = new static();
$request->setMethod($method);
$request->setParams($params);
$request->setId($id);
}
示例12: mapJsonToHost
/**
* @param $response
* @return Host
*/
private function mapJsonToHost($json)
{
/** @var Host $host */
$host = $this->serializer->deserialize($json, Host::CLASS_NAME, 'json');
if (empty($host->endpoints)) {
$host->endpoints = array();
return $host;
}
$endpointDtos = array();
foreach ($host->endpoints as $endpoint) {
$endpointDto = new Endpoint();
foreach ($endpoint as $key => $value) {
$endpointDto->{$key} = $value;
}
$endpointDtos[] = $endpointDto;
}
$host->endpoints = $endpointDtos;
return $host;
}
示例13: mapJsonToConnectionDescriptors
/**
* @param $json
* @return array
*/
private function mapJsonToConnectionDescriptors($json)
{
$decoded_connections = json_decode($json, true);
if (!$decoded_connections) {
$this->logger->error('Mapping received invalid JSON', array('json' => $json));
throw new \RuntimeException('Mapping received invalid JSON');
}
if (!is_array($decoded_connections['connections'])) {
$this->logger->error('JSON does not contain connection', array('json' => $json));
throw new RuntimeException('Connections is not an array!');
}
$connections = array();
foreach ($decoded_connections['connections'] as $decoded_connection) {
/* @var ConnectionDto $dto */
$dto = $this->serializer->deserialize(json_encode($decoded_connection), ConnectionDescriptorDto::CLASS_NAME, 'json');
$connections[] = $this->assembler->assemble($dto);
}
return $connections;
}
示例14: deserialize
/**
* Deserializes a Json into readable datas.
*
* @param string $string
*
* @return RZ\Roadiz\Core\Entities\NodeType
*/
public static function deserialize($string)
{
$encoder = new JsonEncoder();
$nameConverter = new CamelCaseToSnakeCaseNameConverter(['name', 'displayName', 'display_name', 'description', 'visible', 'newsletterType', 'hidingNodes']);
$normalizer = new GetSetMethodNormalizer(null, $nameConverter);
$serializer = new Serializer([$normalizer], [$encoder]);
$nodeType = $serializer->deserialize($string, 'RZ\\Roadiz\\Core\\Entities\\NodeType', 'json');
/*
* Importing Fields.
*
* We need to extract fields from node-type and to re-encode them
* to pass to NodeTypeFieldJsonSerializer.
*/
$tempArray = json_decode($string, true);
foreach ($tempArray['fields'] as $fieldAssoc) {
$ntField = NodeTypeFieldJsonSerializer::deserialize(json_encode($fieldAssoc));
$nodeType->addField($ntField);
}
return $nodeType;
}
示例15: __construct
public function __construct($ezpage, $container, $blockMapper)
{
$this->xml = $ezpage['data_text'];
$this->blockMapper = $blockMapper;
$this->container = $container;
$serializer = new Serializer([new ObjectNormalizer()], [new XmlEncoder()]);
try {
$page = new PageValue();
if ($this->xml) {
$page = $serializer->deserialize($this->xml, 'EzSystems\\EzFlowMigrationToolkit\\HelperObject\\PageValue', 'xml');
}
} catch (InvalidArgumentException $e) {
// Not valid or empty page
$page = new PageValue();
}
$this->layout = $page->zone_layout;
if (is_array($page->zone)) {
foreach ($page->zone as $legacyZone) {
$zone = new Zone($legacyZone, $blockMapper);
$this->zones[] = $zone;
}
}
}