当前位置: 首页>>代码示例>>PHP>>正文


PHP Serializer::normalize方法代码示例

本文整理汇总了PHP中Symfony\Component\Serializer\Serializer::normalize方法的典型用法代码示例。如果您正苦于以下问题:PHP Serializer::normalize方法的具体用法?PHP Serializer::normalize怎么用?PHP Serializer::normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Serializer\Serializer的用法示例。


在下文中一共展示了Serializer::normalize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testCustomNormalizerCanNormalizeCollectionsAndScalar

 public function testCustomNormalizerCanNormalizeCollectionsAndScalar()
 {
     $serializer = new Serializer(array(new TestNormalizer()), array());
     $this->assertNull($serializer->normalize(array('a', 'b')));
     $this->assertNull($serializer->normalize(new \ArrayObject(array('c', 'd'))));
     $this->assertNull($serializer->normalize(array()));
     $this->assertNull($serializer->normalize('test'));
 }
开发者ID:ABaldwinHunter,项目名称:symfony-clone,代码行数:8,代码来源:SerializerTest.php

示例2: itShouldCollect

 /**
  * @test
  */
 public function itShouldCollect()
 {
     $this->serializer->normalize(Argument::any())->shouldBeCalled()->willReturn([]);
     $this->logger->pushHandler(Argument::any())->shouldBeCalled()->willReturn(true);
     $this->logger->info(Argument::type('string'), Argument::type('array'))->shouldBeCalled();
     $this->collector->collect($this->requestObject, ['logFile' => 'test.log']);
 }
开发者ID:deuzu,项目名称:request-collector-bundle,代码行数:10,代码来源:LoggerCollectorTest.php

示例3: save

 public function save(Article $article)
 {
     $metadata = $this->entityManager->getClassMetadata(get_class($article));
     $type = "app." . $metadata->getTableName();
     $this->fluentLogger->post($type, array_filter($this->serializer->normalize($article), function ($idx) {
         return $idx != 'id';
     }, ARRAY_FILTER_USE_KEY));
 }
开发者ID:polidog,项目名称:symfony3-sample-fluent-mysqlrecord,代码行数:8,代码来源:FluentOutputService.php

示例4: normalize

 /**
  * {@inheritdoc}
  */
 public function normalize($elements, $format = null, array $context = [])
 {
     $normalizedElements = [];
     foreach ($elements as $key => $element) {
         $normalizedElements[$key] = $this->serializer->normalize($element, $format, $context);
     }
     return $normalizedElements;
 }
开发者ID:alexisfroger,项目名称:pim-community-dev,代码行数:11,代码来源:CollectionNormalizer.php

示例5: diff

 /**
  * Compares given value object with value object data structure
  *
  * Returns set of value object attribute names. E.g.:
  *
  * [
  *      // Items that are missing in value object
  *      'add'    => ['field1', 'field2', ...]
  *      // Items that shuld not be present in value object
  *      'remove' => ['field3', 'field4', ...]
  * ]
  *
  * @param object $object
  * @param array $comparedData
  * @param string $propertyIdentifier
  * @return array
  */
 public function diff($object, $comparedData, $propertyIdentifier)
 {
     $objectData = $this->serilaizer->normalize($object);
     $comparingColumn = $this->getAttributesOfValueObjects($comparedData, $propertyIdentifier);
     $toAdd = array_diff($comparingColumn, array_column($objectData, $propertyIdentifier));
     $toRemove = array_diff(array_column($objectData, $propertyIdentifier), $comparingColumn);
     // @todo: add items to be updated
     return ['add' => $toAdd, 'remove' => $toRemove];
 }
开发者ID:silversolutions,项目名称:content-loader-bundle,代码行数:26,代码来源:Diff.php

示例6: process

 /**
  * {@inheritdoc}
  */
 public function process($product)
 {
     $data['media'] = [];
     $mediaValues = $this->getMediaProductValues($product);
     foreach ($mediaValues as $mediaValue) {
         $data['media'][] = $this->serializer->normalize($mediaValue->getMedia(), 'flat', ['field_name' => 'media', 'prepare_copy' => true, 'value' => $mediaValue]);
     }
     $data['product'] = $this->serializer->normalize($product, 'flat', $this->getNormalizerContext());
     return $data;
 }
开发者ID:noglitchyo,项目名称:pim-community-dev,代码行数:13,代码来源:ProductToFlatArrayProcessor.php

示例7: getFormExportCode

  /**
   * @param $fillpdf_form
   * @return string
   */
  public function getFormExportCode(FillPdfFormInterface $fillpdf_form) {
    $fields = $this->entityHelper->getFormFields($fillpdf_form);

    $form_config = [
      'form' => $this->serializer->normalize($fillpdf_form),
      'fields' => $this->serializer->normalize($fields),
    ];

    $code = $this->serializer->serialize($form_config, 'json');
    return $code;
  }
开发者ID:AshishNaik021,项目名称:iimisac-d8,代码行数:15,代码来源:Serializer.php

示例8: __invoke

 /**
  * Retrieves a collection of resources.
  *
  * @param Request $request
  *
  * @throws RuntimeException|RootNodeNotFoundException
  *
  * @return array|\Dunglas\ApiBundle\Model\PaginatorInterface|\Traversable
  */
 public function __invoke(Request $request)
 {
     $user = $this->userService->getUser();
     $preferences = $this->userPreferenceService->getPreferences($user);
     list($resourceType) = $this->extractAttributes($request);
     /*
      * @var ResourceInterface $resourceType
      */
     $serializedData = $this->serializer->normalize($preferences, 'json', $resourceType->getNormalizationContext());
     return new JsonResponse($serializedData);
 }
开发者ID:partkeepr,项目名称:PartKeepr,代码行数:20,代码来源:GetPreferencesAction.php

示例9: process

 /**
  * {@inheritdoc}
  */
 public function process($product)
 {
     $contextChannel = $this->channelManager->getChannelByCode($this->channel);
     $this->productBuilder->addMissingProductValues($product, [$contextChannel], $contextChannel->getLocales()->toArray());
     $data['media'] = [];
     $mediaValues = $this->getMediaProductValues($product);
     foreach ($mediaValues as $mediaValue) {
         $data['media'][] = $this->serializer->normalize($mediaValue->getMedia(), 'flat', ['field_name' => 'media', 'prepare_copy' => true, 'value' => $mediaValue]);
     }
     $data['product'] = $this->serializer->normalize($product, 'flat', $this->getNormalizerContext());
     return $data;
 }
开发者ID:abdeldayem,项目名称:pim-community-dev,代码行数:15,代码来源:ProductToFlatArrayProcessor.php

示例10: process

 /**
  * {@inheritdoc}
  */
 public function process($product)
 {
     $data['media'] = [];
     $productMedias = $this->getProductMedias($product);
     if (count($productMedias) > 0) {
         try {
             $data['media'] = $this->serializer->normalize($productMedias, 'flat', ['field_name' => 'media', 'prepare_copy' => true]);
         } catch (FileNotFoundException $e) {
             throw new InvalidItemException($e->getMessage(), ['item' => $product->getIdentifier()->getData(), 'uploadDirectory' => $this->uploadDirectory]);
         }
     }
     $data['product'] = $this->serializer->normalize($product, 'flat', $this->getNormalizerContext());
     return $data;
 }
开发者ID:jacko972,项目名称:pim-community-dev,代码行数:17,代码来源:ProductToFlatArrayProcessor.php

示例11: __invoke

 /**
  * Retrieves a collection of resources.
  *
  * @param Request $request
  *
  * @throws \Exception                                 If the format is invalid
  * @throws RuntimeException|RootNodeNotFoundException
  *
  * @return JsonResponse
  */
 public function __invoke(Request $request)
 {
     $data = json_decode($request->getContent());
     if (property_exists($data, 'preferenceKey') && property_exists($data, 'preferenceValue')) {
         $preference = $this->systemPreferenceService->setSystemPreference($data->preferenceKey, $data->preferenceValue);
     } else {
         throw new \Exception('Invalid format');
     }
     /**
      * @var ResourceInterface $resourceType
      */
     list($resourceType) = $this->extractAttributes($request);
     $serializedData = $this->serializer->normalize($preference, 'json', $resourceType->getNormalizationContext());
     return new JsonResponse($serializedData);
 }
开发者ID:partkeepr,项目名称:PartKeepr,代码行数:25,代码来源:SetPreferenceAction.php

示例12: syncAction

 /**
  * @return JsonResponse
  *
  * @Route("/sync")
  */
 public function syncAction()
 {
     $youtube = new Youtube(['key' => $this->getParameter('youtube_api_key')]);
     $videos = $youtube->getPlaylistItemsByPlaylistId($this->getParameter('youtube_playlist_id'));
     $em = $this->getDoctrine()->getManager();
     foreach ($videos as $video) {
         $name = $video->snippet->title;
         $youtubeId = $video->snippet->resourceId->videoId;
         $description = $video->snippet->description;
         if (property_exists($video->snippet->thumbnails, 'maxres')) {
             $thumbnail = $video->snippet->thumbnails->maxres->url;
         } elseif (property_exists($video->snippet->thumbnails, 'high')) {
             $thumbnail = $video->snippet->thumbnails->high->url;
         } elseif (property_exists($video->snippet->thumbnails, 'medium')) {
             $thumbnail = $video->snippet->thumbnails->medium->url;
         } else {
             $thumbnail = $video->snippet->thumbnails->default->url;
         }
         $video = $em->getRepository('TGVideoBundle:Video')->findOneByYoutubeId($youtubeId);
         if ($video === null) {
             $video = new Video();
             $video->setYoutubeId($youtubeId);
             $em->persist($video);
         }
         $video->setName($name);
         $video->setDescription($description);
         $video->setThumbnail($thumbnail);
         $video->setUrl('https://www.youtube.com/embed/' . $youtubeId);
     }
     $em->flush();
     $videos = $this->getDoctrine()->getRepository('TGVideoBundle:Video')->findAll([], ['createdAt' => 'DESC']);
     $serializer = new Serializer([$this->get('tg_video.normalizer')]);
     return new JsonResponse(['videos' => $serializer->normalize($videos)]);
 }
开发者ID:tweedegolf,项目名称:video-bundle,代码行数:39,代码来源:DefaultController.php

示例13: testNormalizeWithSupportOnData

 public function testNormalizeWithSupportOnData()
 {
     $normalizer1 = $this->getMock('Symfony\\Component\\Serializer\\Normalizer\\NormalizerInterface');
     $normalizer1->method('supportsNormalization')->willReturnCallback(function ($data, $format) {
         return isset($data->test);
     });
     $normalizer1->method('normalize')->willReturn('test1');
     $normalizer2 = $this->getMock('Symfony\\Component\\Serializer\\Normalizer\\NormalizerInterface');
     $normalizer2->method('supportsNormalization')->willReturn(true);
     $normalizer2->method('normalize')->willReturn('test2');
     $serializer = new Serializer(array($normalizer1, $normalizer2));
     $data = new \stdClass();
     $data->test = true;
     $this->assertEquals('test1', $serializer->normalize($data));
     $this->assertEquals('test2', $serializer->normalize(new \stdClass()));
 }
开发者ID:mkemiche,项目名称:Annuaire,代码行数:16,代码来源:SerializerTest.php

示例14: __invoke

 /**
  * Retrieves a collection of resources.
  *
  * @param Request $request
  *
  * @return array|\Dunglas\ApiBundle\Model\PaginatorInterface|\Traversable
  * @throws \Exception If the format is invalid
  *
  * @throws RuntimeException|RootNodeNotFoundException
  */
 public function __invoke(Request $request)
 {
     $user = $this->userService->getUser();
     $data = json_decode($request->getContent());
     if (property_exists($data, "preferenceKey") && property_exists($data, "preferenceValue")) {
         $preference = $this->userPreferenceService->setPreference($user, $data->preferenceKey, $data->preferenceValue);
     } else {
         throw new \Exception("Invalid format");
     }
     list($resourceType) = $this->extractAttributes($request);
     /**
      * @var ResourceInterface $resourceType
      */
     $serializedData = $this->serializer->normalize($preference, 'json', $resourceType->getNormalizationContext());
     return new JsonResponse($serializedData);
 }
开发者ID:fulcrum3d,项目名称:PartKeepr,代码行数:26,代码来源:SetPreferenceAction.php

示例15: ajaxGetAction

 /**
  * @Route("/player/ajax/get", name="team_player_ajax_get")
  */
 public function ajaxGetAction(Request $request)
 {
     if ($request->isXmlHttpRequest()) {
         try {
             $user = $this->getUser();
             $em = $this->getDoctrine()->getManager();
             $player = $em->getRepository('TeamBundle:Player')->findOneBy(array('id' => $request->get('id')));
             if ($user->getTeam() == $player->getTeam()) {
                 $normalizer = new ObjectNormalizer();
                 $normalizer->setCircularReferenceHandler(function ($object) {
                     return $object->getId();
                 });
                 $serializer = new Serializer(array($normalizer));
                 $player = $serializer->normalize($player);
                 $response = new Response(json_encode(array('status' => 'ok', 'player' => $player)));
             } else {
                 $response = new Response(json_encode(array('status' => 'ko', 'message' => 'Vous n\'avez pas la permission d\'éditer ce joueur', 'debug' => 'Utilisateur connecté != manager de l\'équipe du joueur')));
             }
         } catch (\Exception $e) {
             $response = new Response(json_encode(array('status' => 'ko', 'message' => 'Une erreur inconnue s\'est produite', 'debug' => $e->getMessage())));
         }
         $response->headers->set('Content-Type', 'application/json');
         return $response;
     }
     $response = new Response(json_encode(array('status' => 'ko', 'message' => 'Accès non autorisé', 'debug' => 'Bad request')));
     $response->headers->set('Content-Type', 'application/json');
     return $response;
 }
开发者ID:Jujuwar,项目名称:bruminator2.0,代码行数:31,代码来源:PlayerController.php


注:本文中的Symfony\Component\Serializer\Serializer::normalize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。