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


PHP Serializer\SerializerBuilder类代码示例

本文整理汇总了PHP中JMS\Serializer\SerializerBuilder的典型用法代码示例。如果您正苦于以下问题:PHP SerializerBuilder类的具体用法?PHP SerializerBuilder怎么用?PHP SerializerBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: build

 public function build()
 {
     $this->setObjectManager($this->createEntityManager());
     $this->serializerBuilder = BreezeSerializerBuilder::create($this->getObjectManager());
     $this->validatorBuilder = new ValidatorBuilder();
     if ($this->annotationsEnabled) {
         $this->validatorBuilder->enableAnnotationMapping();
     }
     foreach ($this->mappings as $mapping) {
         if (isset($mapping['serializer'])) {
             $this->serializerBuilder->addMetadataDir($mapping['serializer']);
         }
         if (isset($mapping['validation'])) {
             if ($mapping['type'] == 'xml') {
                 $this->validatorBuilder->addXmlMapping($mapping['validation']);
             } else {
                 if ($mapping['type'] == 'yaml') {
                     $this->validatorBuilder->addYamlMapping($mapping['validation']);
                 }
             }
             //                else if ($mapping['type'] == 'annotation') {
             //                    $this->validatorBuilder->enableAnnotationMapping();
             //                }
         }
     }
     $serializer = $this->serializerBuilder->build();
     $this->setSerializer($serializer);
     $validator = $this->validatorBuilder->getValidator();
     $this->setValidator($validator);
 }
开发者ID:s001dxp,项目名称:breeze.server.php,代码行数:30,代码来源:StandaloneApplication.php

示例2: setDeserializationVisitors

 /**
  * Override default deserialization visitors
  *
  * @param Container $app
  * @param SerializerBuilder $serializerBuilder
  */
 protected function setDeserializationVisitors(Container $app, SerializerBuilder $serializerBuilder)
 {
     $serializerBuilder->addDefaultDeserializationVisitors();
     foreach ($app["serializer.deserializationVisitors"] as $format => $visitor) {
         $serializerBuilder->setDeserializationVisitor($format, $visitor);
     }
 }
开发者ID:jdesrosiers,项目名称:silex-jms-serializer-provider,代码行数:13,代码来源:BuilderService.php

示例3: createSerializer

 /**
  * Create a serializer instance.
  *
  * @return Serializer
  */
 protected function createSerializer()
 {
     $builder = new SerializerBuilder();
     $builder->addDefaultHandlers();
     $builder->addDefaultDeserializationVisitors();
     $builder->addDefaultSerializationVisitors();
     $this->configureBuilder($builder);
     return $builder->build();
 }
开发者ID:hellofresh,项目名称:engine,代码行数:14,代码来源:JMSSerializerHandlerTestCase.php

示例4: getTpeFromClientAction

 /**
  * @param Request $request
  * @param $clientId
  *
  * @Route("/get/tpe/from/client/{clientId}", name="getTpeFromClient", options={"expose"=true})
  * @return \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
  */
 public function getTpeFromClientAction(Request $request, $clientId)
 {
     if ($request->isXmlHttpRequest() && $request->isMethod('POST')) {
         $em = $this->getDoctrine()->getManager();
         $serializer = new SerializerBuilder();
         $clientRepository = $em->getRepository('CibLicenseBundle:Client');
         $client = $clientRepository->find($clientId);
         return new Response($serializer->create()->build()->serialize($client->getTpe(), 'json'), 200);
     } else {
         return $this->createNotFoundException('DANS TON CUL !');
     }
 }
开发者ID:wangshipeng,项目名称:LicenseManager,代码行数:19,代码来源:LicenseController.php

示例5: __construct

 /**
  * Constructor.
  *
  * @param \net\authorize\api\contract\v1\AnetApiRequestType $request ApiRequest to send
  * @param string $responseType response type expected
  * @throws InvalidArgumentException if invalid request
  */
 public function __construct(\net\authorize\api\contract\v1\AnetApiRequestType $request, $responseType)
 {
     date_default_timezone_set('UTC');
     $this->logger = LogFactory::getLog(get_class($this));
     if (null == $request) {
         throw new InvalidArgumentException("request cannot be null");
     }
     if (null == $responseType || '' == $responseType) {
         throw new InvalidArgumentException("responseType cannot be null or empty");
     }
     if (null != $this->apiResponse) {
         throw new InvalidArgumentException("response has to be null");
     }
     $this->apiRequest = $request;
     $this->validate();
     $this->apiResponseType = $responseType;
     $this->httpClient = new HttpClient();
     $serializerBuilder = SerializerBuilder::create();
     $serializerBuilder->addMetadataDir(__DIR__ . '/../../yml/v1', 'net\\authorize\\api\\contract\\v1');
     //..\..\yml\v1\ //'/../lib/net/authorize/api/yml/v1'
     $serializerBuilder->configureHandlers(function (HandlerRegistryInterface $h) use($serializerBuilder) {
         $serializerBuilder->addDefaultHandlers();
         $h->registerSubscribingHandler(new BaseTypesHandler());
         // XMLSchema List handling
         $h->registerSubscribingHandler(new XmlSchemaDateHandler());
         // XMLSchema date handling
     });
     $this->serializer = $serializerBuilder->build();
 }
开发者ID:GeniusReferrals,项目名称:sdk-php,代码行数:36,代码来源:ApiOperationBase.php

示例6: rpcAction

 /**
  *  RPC url action
  *
  * @param $bundle
  * @param $service
  * @param $method
  * @param Request $request
  *
  * @Route("/{bundle}/{service}/{method}" , defaults={"_format": "json"})
  * @Method("POST")
  *
  * @return Response
  */
 public function rpcAction($bundle, $service, $method, Request $request)
 {
     $response = new Response();
     $translator = $this->get('translator');
     try {
         $prefix = 'Hazu.Service';
         $serviceObject = $this->get("{$prefix}.{$bundle}.{$service}");
         if (true === method_exists($serviceObject, $method)) {
             $params = json_decode($request->getContent(), true);
             if (null === $params) {
                 throw new \Exception('$params não é um JSON valido');
             }
             $rService = $serviceObject->{$method}($params);
         } else {
             throw new \Exception($translator->trans('Metodo não encontrado'));
         }
     } catch (ServiceNotFoundException $e) {
         $rService = new HazuException($e->getMessage());
         $response->setStatusCode(500);
     } catch (\Exception $e) {
         $rService = new HazuException($e->getMessage());
         $response->setStatusCode(500);
     } finally {
         $serializer = SerializerBuilder::create()->build();
         $rJson = $serializer->serialize($rService, 'json', SerializationContext::create()->enableMaxDepthChecks());
         $response->headers->set('x-hazu-type', gettype($rService));
         if (gettype($rService) == 'object') {
             $response->headers->set('x-hazu-class', get_class($rService));
         }
         $response->setContent($rJson);
     }
     return $response;
 }
开发者ID:cristianocorrea,项目名称:hazu,代码行数:46,代码来源:KernelController.php

示例7: setUp

 protected function setUp()
 {
     parent::setUp();
     $this->serializer = SerializerBuilder::create()->build();
     $this->validator = Validation::createValidator();
     $this->action->setSerializer($this->serializer)->setValidator($this->validator);
 }
开发者ID:amstaffix,项目名称:rest-crud-actions,代码行数:7,代码来源:PostActionTest.php

示例8: serializer

 /**
  * @return \JMS\Serializer\Serializer
  */
 private function serializer()
 {
     if (null === $this->serializer) {
         $this->serializer = SerializerBuilder::create()->addMetadataDir(__DIR__ . '/../../Infrastructure/Application/Serialization/JMS/Config')->setCacheDir(__DIR__ . '/../../../var/cache/jms-serializer')->build();
     }
     return $this->serializer;
 }
开发者ID:carlosbuenosvinos,项目名称:ddd,代码行数:10,代码来源:NotificationService.php

示例9: testHydrateEntity

 /**
  * Test hydrate single entity
  */
 public function testHydrateEntity()
 {
     $serializer = SerializerBuilder::create()->build();
     $service = new HydratorService($serializer, $this->getTransformer());
     $result = $service->hydrateEntity(json_encode($this->testData), 'MJanssen\\Assets\\Entity\\Test');
     $this->assertEquals($this->createEntity($this->testData), $result);
 }
开发者ID:drinky78,项目名称:silex-rest-service-providers,代码行数:10,代码来源:HydratorServiceTest.php

示例10: __construct

 /**
  * @param string $username
  * @param string $apiKey
  */
 public function __construct($username, $apiKey)
 {
     $this->username = $username;
     $this->apiKey = $apiKey;
     $this->serializer = SerializerBuilder::create()->setCacheDir(__DIR__ . '/../../../cache')->setDebug(true)->build();
     $this->client = new Client(new SerializerWrapper($this->serializer));
 }
开发者ID:dvelopment,项目名称:fastbill,代码行数:11,代码来源:Api.php

示例11: __construct

 /**
  * Instantiate a SerpPageSerializer
  * @param string $cacheDir
  */
 public function __construct($cacheDir = self::DEFAULT_SERIALIZER_CACHE_DIR)
 {
     if (!SerpPageSerializerHelper::validateDir($cacheDir)) {
         throw new \Franzip\SerpPageSerializer\Exceptions\InvalidArgumentException('Invalid SerpPageSerializer $cacheDir: please supply a valid non-empty string.');
     }
     $this->serializer = SerializerBuilder::create()->setCacheDir($cacheDir)->build();
 }
开发者ID:franzip,项目名称:serp-page-serializer,代码行数:11,代码来源:SerpPageSerializer.php

示例12: editAction

 public function editAction(Request $request, $id)
 {
     $serializer = SerializerBuilder::create()->build();
     $data = array('success' => false, 'error' => 'Ошибка обновления книги');
     if ($request->getMethod() == 'POST') {
         $requestData = $request->request->all();
         if (empty($requestData['apiKey']) || !$this->checkApiKey($requestData['apiKey'])) {
             $data['error'] = 'Неверный ключ';
             $jsonContent = $serializer->serialize($data, 'json');
             return new Response($jsonContent);
         }
         $book = $this->getDoctrine()->getManager()->getRepository('IntaroBookStoreBundle:Book')->find($id);
         if (!$book) {
             $data['error'] = 'Книга не найдена';
             $jsonContent = $serializer->serialize($data, 'json');
             return new Response($jsonContent);
         }
         if (!empty($requestData['name']) && !empty($requestData['author']) && !empty($requestData['readingDate']) && isset($requestData['download'])) {
             $book->setName($requestData['name']);
             $book->setAuthor($requestData['author']);
             $book->setReadingDate(new \DateTime($requestData['readingDate']));
             $book->setDownload($requestData['download']);
         } else {
             $data['error'] = 'Заданы не все необходимые поля';
             $jsonContent = $serializer->serialize($data, 'json');
             return new Response($jsonContent);
         }
         $em = $this->getDoctrine()->getManager();
         $em->persist($book);
         $em->flush();
         $data = array('success' => true, 'message' => 'Книга успешно обновлена');
     }
     $jsonContent = $serializer->serialize($data, 'json');
     return new Response($jsonContent);
 }
开发者ID:bamper,项目名称:book_store,代码行数:35,代码来源:ApiController.php

示例13: getSerializer

 /**
  * @return mixed
  */
 public static function getSerializer()
 {
     if (!self::$serializer) {
         self::$serializer = SerializerBuilder::create()->build();
     }
     return self::$serializer;
 }
开发者ID:6by6,项目名称:freeagent-php,代码行数:10,代码来源:AbstractEntity.php

示例14: getSerializer

 private function getSerializer()
 {
     if (is_null($this->serializer)) {
         $this->serializer = SerializerBuilder::create()->addMetadataDir(dirname(__DIR__) . '/V1_1_1/Metadata/Cdm', 'CdmFr\\Model\\V1_1_1\\Cdm')->addMetadataDir(dirname(__DIR__) . '/V1_1_1/Metadata/CdmFr', 'CdmFr\\Model\\V1_1_1\\CdmFr')->addMetadataDir(dirname(__DIR__) . '/V1_1_1/Metadata/Lheo', 'CdmFr\\Model\\V1_1_1\\Lheo')->build();
     }
     return $this->serializer;
 }
开发者ID:dsi-agpt,项目名称:cdmfr,代码行数:7,代码来源:CdmFrDeserializer.php

示例15: setUp

 /**
  * Set up all the mocks and the serializer class
  *
  * @return void
  */
 public function setUp()
 {
     $this->serializer = SerializerBuilder::create()->build();
     $this->setupPheanstalkConnectionMock();
     $this->generateFakeParams();
     $this->setupEntityManagerMock();
 }
开发者ID:webdevvie,项目名称:pheanstalk-task-queue-bundle,代码行数:12,代码来源:TaskQueueServiceTest.php


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