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


PHP SerializerBuilder::create方法代码示例

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


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

示例1: boot

 /**
  * @throws \Doctrine\ORM\ORMException
  */
 public function boot()
 {
     $this->serializer = SerializerBuilder::create()->setDebug($this->devMode)->build();
     $this->entityFolder->create();
     AnnotationRegistry::registerAutoloadNamespace('JMS\\Serializer\\Annotation', __DIR__ . '/../../../../vendor/jms/serializer/src');
     $proxyDoctrineFolder = new Folder(sys_get_temp_dir() . '/doctrine');
     $config = Setup::createAnnotationMetadataConfiguration([$this->entityFolder->absolute()], $this->isDevMode(), $proxyDoctrineFolder->absolute());
     if ($this->cache !== null) {
         $config->setQueryCacheImpl($this->getCache());
         $config->setResultCacheImpl($this->getCache());
     }
     $this->entityManager = $this->createEntityManager($config);
     $debugStack = new DebugStack();
     $this->entityManager->getConnection()->getConfiguration()->setSQLLogger($debugStack);
     if ($this->getFileCreation()->getContent() == 1) {
         return;
     }
     if ($proxyDoctrineFolder->isFolder()) {
         $proxyDoctrineFolder->removeFiles();
     }
     $tool = new SchemaTool($this->entityManager);
     $metadatas = $this->entityManager->getMetadataFactory()->getAllMetadata();
     $proxyDoctrineFolder->create();
     $this->entityManager->getProxyFactory()->generateProxyClasses($metadatas, $proxyDoctrineFolder->absolute());
     if ($this->cloudFoundryBoot->isInCloudFoundry()) {
         $tool->updateSchema($metadatas);
     } else {
         $tool->createSchema($metadatas);
     }
     $this->getFileCreation()->setContent(1);
 }
开发者ID:cloudfoundry-community,项目名称:php-cf-service-broker,代码行数:34,代码来源:DoctrineBoot.php

示例2: 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

示例3: 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

示例4: __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

示例5: __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

示例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: __construct

 /**
  * Constructor
  *
  * By Default if a JMS Serializer isn't provided, one will be created.
  * Providing a JMS Serializer instance allows for additional event handling,
  * caching and extensions to be loaded
  *
  * @param Serializer $serializer
  */
 public function __construct(Serializer $serializer = null)
 {
     if (is_null($serializer)) {
         $serializer = SerializerBuilder::create()->build();
     }
     $this->serializer = $serializer;
 }
开发者ID:parrotcage,项目名称:aves,代码行数:16,代码来源:JsonPlugin.php

示例8: testDeserialization

 public function testDeserialization()
 {
     $serializer = SerializerBuilder::create()->build();
     $serialized = file_get_contents(__DIR__ . '/../mock/SetHostsResponse.xml');
     $responseObj = $serializer->deserialize($serialized, 'SMH\\Enom\\Response\\BaseResponse', 'xml');
     $this->assertInstanceOf('SMH\\Enom\\Response\\SetHostsResponse', $responseObj);
 }
开发者ID:shaunhardy,项目名称:enom,代码行数:7,代码来源:SetHostsResponseTest.php

示例9: register

 public function register()
 {
     \Doctrine\Common\Annotations\AnnotationRegistry::registerLoader('class_exists');
     $this->app->singleton('serializer', function ($app) {
         return SerializerBuilder::create()->setObjectConstructor(new DoctrineObjectConstructor($app->make('registry'), new UnserializeObjectConstructor()))->build();
     });
 }
开发者ID:hoangnd25,项目名称:laravel-boilerplate,代码行数:7,代码来源:SerializerServiceProvider.php

示例10: register

 public function register(Application $app)
 {
     $app['serializer.cache-directory'] = $app->share(function () use($app) {
         return $app['cache.path'] . '/serializer/';
     });
     $app['serializer.metadata_dirs'] = $app->share(function () {
         return [];
     });
     $app['serializer.handlers'] = $app->share(function () {
         return [];
     });
     $app['serializer'] = $app->share(function (Application $app) {
         // Register JMS annotation into Doctrine's registry
         AnnotationRegistry::registerAutoloadNamespace('JMS\\Serializer\\Annotation', $app['root.path'] . '/vendor/jms/serializer/src/');
         $builder = SerializerBuilder::create()->setCacheDir($app['serializer.cache-directory'])->setDebug($app['debug']);
         if (!empty($app['serializer.metadata_dirs'])) {
             $builder->addMetadataDirs($app['serializer.metadata_dirs']);
         }
         if (!empty($app['serializer.handlers'])) {
             $builder->configureHandlers(function (HandlerRegistryInterface $registry) use($app) {
                 foreach ($app['serializer.handlers'] as $handler) {
                     $registry->registerSubscribingHandler($handler);
                 }
             });
         }
         return $builder->build();
     });
 }
开发者ID:luisbrito,项目名称:Phraseanet,代码行数:28,代码来源:JMSSerializerServiceProvider.php

示例11: 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

示例12: setUp

 public function setUp()
 {
     AnnotationRegistry::registerLoader('class_exists');
     $this->serializer = SerializerBuilder::create()->configureHandlers(function (HandlerRegistry $registry) {
         $registry->registerSubscribingHandler(new RamseyUuidHandler());
     })->build();
 }
开发者ID:pauci,项目名称:cqrs,代码行数:7,代码来源:RamseyUuidHandlerTest.php

示例13: testIfDataIsDecodedFromJsonToArray

 public function testIfDataIsDecodedFromJsonToArray()
 {
     $transformer = $this->getTransformerMock();
     $transformer->expects($this->once())->method('transformHydrateData')->with($this->testData);
     $service = new HydratorService(SerializerBuilder::create()->build(), $transformer);
     $service->hydrateEntity(json_encode($this->testData), 'MJanssen\\Assets\\Entity\\Test');
 }
开发者ID:nikonm,项目名称:silex-rest-service-providers,代码行数:7,代码来源:HydratorServiceTest.php

示例14: registerSerializers

 protected function registerSerializers()
 {
     /*
      * Main serializer
      */
     $this->app->bind('bernard.serializer', function (Container $app) {
         $serializerName = config('bernard.default_serializer');
         return $app->make('bernard.serializer.' . $serializerName);
     });
     /*
      * Simple
      */
     $this->app->bind('bernard.serializer.simple', function (Container $app) {
         return new \Bernard\Serializer\SimpleSerializer();
     });
     /*
      * Symfony
      */
     $this->app->bind('bernard.serializer.symfony', function (Container $app) {
         $symfonySerializer = new \Symfony\Component\Serializer\Serializer([new \Bernard\Symfony\EnvelopeNormalizer()], [new \Symfony\Component\Serializer\Encoder\JsonEncoder()]);
         return new \Bernard\Serializer\SymfonySerializer($symfonySerializer);
     });
     /*
      * JMS Serializer
      */
     $this->app->bind('bernard.serializer.jms', function (Container $app) {
         $jmsSerializer = \JMS\Serializer\SerializerBuilder::create()->configureHandlers(function ($registry) {
             $registry->registerSubscribingHandler(new \Bernard\JMSSerializer\EnvelopeHandler());
         })->build();
         return new \Bernard\Serializer\JMSSerializer($jmsSerializer);
     });
 }
开发者ID:trihtm,项目名称:annie-framework,代码行数:32,代码来源:BernardServiceProvider.php

示例15: getFinalResultByJMSGroup

 /**
  * Exclusion strategy by JMS group name
  *
  * @author Huong Le <tonyle.microsoft@gmail.com>
  *
  * @param  Entity|Collection $data     Entity or array collection of entity
  * @param  string            $JMSGroup Name of JMS group
  *
  * @return array                       Array after the exclusion was done
  */
 public function getFinalResultByJMSGroup($data, $JMSGroup)
 {
     $serializer = SerializerBuilder::create()->build();
     $json = $serializer->serialize($data, 'json', SerializationContext::create()->setGroups([$JMSGroup])->setSerializeNull(true)->enableMaxDepthChecks());
     $arr = json_decode($json, true);
     return $arr;
 }
开发者ID:CarlPham,项目名称:Account,代码行数:17,代码来源:DTAccountRepository.php


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