• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Serializer\SerializerBuilder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: __construct

 public function __construct(array $config)
 {
     $config = array_replace($defaults = ['subscribers' => [], 'listeners' => [], 'extraHandlers' => []], $config);
     $serializerBuilder = SerializerBuilder::create();
     if (isset($config['cacheDir'])) {
         $serializerBuilder->setCacheDir($config['cacheDir']);
     }
     if (isset($config['propertyNamingStrategy'])) {
         $serializerBuilder->setPropertyNamingStrategy($config['propertyNamingStrategy']);
     }
     if (isset($config['objectConstructor'])) {
         $serializerBuilder->setObjectConstructor($config['objectConstructor']);
     }
     if (isset($config['debug'])) {
         $serializerBuilder->setDebug((bool) $config['objectConstructor']);
     }
     $serializerBuilder->addDefaultHandlers();
     $extraHandlers = $config['extraHandlers'];
     $serializerBuilder->configureHandlers(function (HandlerRegistry $handlerRegistry) use($extraHandlers) {
         array_walk($extraHandlers, [$handlerRegistry, 'registerSubscribingHandler']);
     });
     $subscribers = $config['subscribers'];
     $listeners = $config['listeners'];
     $serializerBuilder->configureListeners(function (EventDispatcher $dispatcher) use($subscribers, $listeners) {
         array_walk($subscribers, [$dispatcher, 'addSubscriber']);
         foreach ($listeners as $event => $callables) {
             foreach ($callables as $cb) {
                 $dispatcher->addListener($event, $cb);
             }
         }
     });
     $this->serializer = $serializerBuilder->build();
 }
开发者ID:Kipperlenny,项目名称:ZendRestModule,代码行数:33,代码来源:Serializer.php


示例17: store

 /**
  * @param string $key
  * @param mixed $value
  */
 public function store($key, $value)
 {
     $serializer = SerializerBuilder::create()->build();
     $jsonContent = $serializer->serialize($value, 'json');
     apc_store($this->getCacheKey() . $key, $jsonContent);
     $this->cacheDriver->store($this->getCacheKey() . $key, $jsonContent);
 }
开发者ID:sinergi,项目名称:browsersession,代码行数:11,代码来源:AbstractCacheable.php


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


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


示例20: toXml

 protected function toXml($oObject)
 {
     $oSerializer = SerializerBuilder::create()->build();
     $sXml = $oSerializer->serialize($oObject, 'xml');
     $this->_sXml = $sXml;
     return $this;
 }
开发者ID:lstaszak,项目名称:zf2main,代码行数:7,代码来源:App.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Serializer\SerializerInterface类代码示例发布时间:2022-05-23
下一篇:
PHP Serializer\Serializer类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap