本文整理汇总了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);
}
示例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);
}
示例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;
}
示例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();
}
示例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));
}
示例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;
}
示例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;
}
示例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);
}
示例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();
});
}
示例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();
});
}
示例11: setUp
protected function setUp()
{
parent::setUp();
$this->serializer = SerializerBuilder::create()->build();
$this->validator = Validation::createValidator();
$this->action->setSerializer($this->serializer)->setValidator($this->validator);
}
示例12: setUp
public function setUp()
{
AnnotationRegistry::registerLoader('class_exists');
$this->serializer = SerializerBuilder::create()->configureHandlers(function (HandlerRegistry $registry) {
$registry->registerSubscribingHandler(new RamseyUuidHandler());
})->build();
}
示例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');
}
示例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);
});
}
示例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;
}