本文整理汇总了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);
}
示例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);
}
}
示例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();
}
示例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 !');
}
}
示例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();
}
示例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: setUp
protected function setUp()
{
parent::setUp();
$this->serializer = SerializerBuilder::create()->build();
$this->validator = Validation::createValidator();
$this->action->setSerializer($this->serializer)->setValidator($this->validator);
}
示例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;
}
示例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);
}
示例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));
}
示例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();
}
示例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);
}
示例13: getSerializer
/**
* @return mixed
*/
public static function getSerializer()
{
if (!self::$serializer) {
self::$serializer = SerializerBuilder::create()->build();
}
return self::$serializer;
}
示例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;
}
示例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();
}