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


PHP Serializer::encode方法代码示例

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


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

示例1: loginRequest

 /**
  * Executes a login HTTP request.
  *
  * @param string $name
  *   The username.
  * @param string $pass
  *   The user password.
  * @param string $format
  *   The format to use to make the request.
  *
  * @return \Psr\Http\Message\ResponseInterface The HTTP response.
  *   The HTTP response.
  */
 protected function loginRequest($name, $pass, $format = 'json')
 {
     $user_login_url = Url::fromRoute('user.login.http')->setRouteParameter('_format', $format)->setAbsolute();
     $request_body = [];
     if (isset($name)) {
         $request_body['name'] = $name;
     }
     if (isset($pass)) {
         $request_body['pass'] = $pass;
     }
     $result = \Drupal::httpClient()->post($user_login_url->toString(), ['body' => $this->serializer->encode($request_body, $format), 'headers' => ['Accept' => "application/{$format}"], 'http_errors' => FALSE, 'cookies' => $this->cookies]);
     return $result;
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:26,代码来源:UserLoginHttpTest.php

示例2: format

 /**
  * @param $request
  * @param array $data
  * @param int $status
  * @param null $message
  * @return Response
  */
 public function format($request, $data = array(), $status = 200, $message = null)
 {
     $data = ['http' => ['status' => $status, 'message' => $message ? $message : Response::$statusTexts[$status]], 'response' => $data];
     $format = 'json';
     if ($request->query->has('format')) {
         $format = $request->query->get('format');
     } else {
         if ($request->headers->has('format')) {
             $format = $request->headers->get('format');
         }
     }
     if (!in_array($format, ['xml', 'json'])) {
         $format = 'json';
     }
     $response = new Response($this->serializer->encode($data, $format), $status);
     $response->headers->set('Content-Type', 'text/' . $format);
     return $response;
 }
开发者ID:ChrisdAutume,项目名称:EtuUTT,代码行数:25,代码来源:DataFormatter.php

示例3: encode

 /**
  * @param object $object
  * @param string $format
  * @param array  $context
  *
  * @return array
  */
 public function encode($object, $format, array $context = [])
 {
     if ($object instanceof Request or $object instanceof Request) {
         $context['xml_root_node_name'] = 'methodCall';
     } elseif ($object instanceof Response) {
         $context['xml_root_node_name'] = 'methodResponse';
     }
     $array = $this->serializer->normalize($object, $format);
     $array = $this->encodeValue($array);
     return $this->serializer->encode($array, $context['encoding'], $context);
 }
开发者ID:mihai-stancu,项目名称:rpc-bundle,代码行数:18,代码来源:XmlRpcEncoder.php

示例4: login

 /**
  * Logs in a user.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The request.
  *
  * @return \Symfony\Component\HttpFoundation\Response
  *   A response which contains the ID and CSRF token.
  */
 public function login(Request $request)
 {
     $format = $this->getRequestFormat($request);
     $content = $request->getContent();
     $credentials = $this->serializer->decode($content, $format);
     if (!isset($credentials['name']) && !isset($credentials['pass'])) {
         throw new BadRequestHttpException('Missing credentials.');
     }
     if (!isset($credentials['name'])) {
         throw new BadRequestHttpException('Missing credentials.name.');
     }
     if (!isset($credentials['pass'])) {
         throw new BadRequestHttpException('Missing credentials.pass.');
     }
     $this->floodControl($request, $credentials['name']);
     if ($this->userIsBlocked($credentials['name'])) {
         throw new BadRequestHttpException('The user has not been activated or is blocked.');
     }
     if ($uid = $this->userAuth->authenticate($credentials['name'], $credentials['pass'])) {
         $this->flood->clear('user.http_login', $this->getLoginFloodIdentifier($request, $credentials['name']));
         /** @var \Drupal\user\UserInterface $user */
         $user = $this->userStorage->load($uid);
         $this->userLoginFinalize($user);
         // Send basic metadata about the logged in user.
         $response_data = [];
         if ($user->get('uid')->access('view', $user)) {
             $response_data['current_user']['uid'] = $user->id();
         }
         if ($user->get('roles')->access('view', $user)) {
             $response_data['current_user']['roles'] = $user->getRoles();
         }
         if ($user->get('name')->access('view', $user)) {
             $response_data['current_user']['name'] = $user->getAccountName();
         }
         $response_data['csrf_token'] = $this->csrfToken->get('rest');
         $logout_route = $this->routeProvider->getRouteByName('user.logout.http');
         // Trim '/' off path to match \Drupal\Core\Access\CsrfAccessCheck.
         $logout_path = ltrim($logout_route->getPath(), '/');
         $response_data['logout_token'] = $this->csrfToken->get($logout_path);
         $encoded_response_data = $this->serializer->encode($response_data, $format);
         return new Response($encoded_response_data);
     }
     $flood_config = $this->config('user.flood');
     if ($identifier = $this->getLoginFloodIdentifier($request, $credentials['name'])) {
         $this->flood->register('user.http_login', $flood_config->get('user_window'), $identifier);
     }
     // Always register an IP-based failed login event.
     $this->flood->register('user.failed_login_ip', $flood_config->get('ip_window'));
     throw new BadRequestHttpException('Sorry, unrecognized username or password.');
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:59,代码来源:UserAuthenticationController.php

示例5: export

 /**
  * Outputs serialized entities
  *
  * @param Request $request
  */
 protected function export(Request $request)
 {
     $iterator = $this->queryGenerator->createQueryBuilder($request, $this->configuration->getName())->getQuery()->iterate();
     $headersSent = false;
     $manager = $this->doctrine->getManagerForClass($this->configuration->getEntityClass());
     foreach ($iterator as $index => $item) {
         if (!count($item[0])) {
             continue;
         }
         $norm = $this->serializer->normalize($item[0], $this->options['serializer_format'], $this->options['serializer_context']);
         if (!$headersSent) {
             echo $this->serializer->encode(array_keys($norm), $this->options['serializer_format'], $this->options['serializer_context']);
             $headersSent = true;
         }
         echo $this->serializer->encode($norm, $this->options['serializer_format'], $this->options['serializer_context']);
         flush();
         if (0 === ($index + 100) % $this->options['batch_size']) {
             $manager->clear();
         }
     }
 }
开发者ID:antoineguigan,项目名称:CustomEntityBundle,代码行数:26,代码来源:QuickExportAction.php

示例6: testEncode

 public function testEncode()
 {
     $serializer = new Serializer(array(), array('json' => new JsonEncoder()));
     $data = array('foo', array(5, 3));
     $result = $serializer->encode($data, 'json');
     $this->assertEquals(json_encode($data), $result);
 }
开发者ID:ayoah,项目名称:symfony,代码行数:7,代码来源:SerializerTest.php

示例7: encode

 /**
  * @param object $object
  * @param string $format
  * @param array  $context
  *
  * @return array
  */
 public function encode($object, $format, array $context = [])
 {
     $context['xml_root_node_name'] = 'soap:Envelope';
     $array = $this->serializer->normalize($object, $format);
     return $this->serializer->encode($array, $context['encoding'], $context);
 }
开发者ID:mihai-stancu,项目名称:rpc-bundle,代码行数:13,代码来源:SoapEncoder.php

示例8: serialize

 /**
  * PHP to JSON Serialization.
  *
  * This method, when supplied with an array, will do its best
  * to convert the array into friendly JSON format.
  *
  * @param string|array|object $phpFormat  The PHP formatted data input (string|array|object) to serialize.
  *
  * @return string The JSON string representing the original PHP string, array (or object).
  *
  * @api
  */
 public function serialize($phpFormat) : string
 {
     return $this->serializer->encode($phpFormat, static::FORMAT);
 }
开发者ID:ucsdmath,项目名称:Serialization,代码行数:16,代码来源:AbstractJsonAdapter.php

示例9: encode

 /**
  * @param object $object
  * @param string $format
  * @param array  $context
  *
  * @return array
  */
 public function encode($object, $format = null, array $context = array())
 {
     $array = $this->serializer->normalize($object, $format);
     return $this->serializer->encode($array, $context['encoding'], $context);
 }
开发者ID:mihai-stancu,项目名称:rpc-bundle,代码行数:12,代码来源:RpcEncoder.php


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