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


PHP Json::useBuiltinEncoderDecoder方法代码示例

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


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

示例1: onBootstrap

 public function onBootstrap(MvcEvent $event)
 {
     Json::$useBuiltinEncoderDecoder = true;
     $eventManager = $event->getApplication()->getEventManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
 }
开发者ID:aiolos,项目名称:haltes,代码行数:7,代码来源:Module.php

示例2: serviceAction

 public function serviceAction()
 {
     $serviceName = strtolower($this->params()->fromRoute('service'));
     $format = strtolower($this->params()->fromRoute('format'));
     $runChecks = $this->params()->fromQuery('run', true);
     if (in_array($format, array(self::XML, self::RICH))) {
         throw new Exception\UnexpectedValueException(sprintf('Format "%s" is currently not supported', $format));
     }
     try {
         $service = new Model\Service($serviceName);
     } catch (Model\Exception\BadModelCallException $e) {
         return $this->notFoundAction();
     }
     $this->_setNewRelic($service);
     $content = $this->_getContentView($service, $format, $runChecks);
     if ($format === self::JSON) {
         $data = $content->getVariables();
         unset($data->service);
         $view = new ViewModel\JsonModel($data);
         Json\Json::$useBuiltinEncoderDecoder = true;
     } else {
         $view = new ViewModel\ViewModel();
         $view->addChild($content, 'content');
         $view->service = $service;
         $view->format = $format;
     }
     return $view;
 }
开发者ID:sullenboom,项目名称:sla-healthcheck,代码行数:28,代码来源:RunnerController.php

示例3: nextGroupsAction

 /**
  * Get a list of groups that are nearest to the given coordinates.
  *
  * Coordinates are given via the parameters <var>lat</var and <var>lon</var>,
  * the maximum distance from the current location is given via <var>distance</var>
  * and the maximum number of entries is given via the parameter <var>max</var>
  *
  * This method will then return the maximum number of entries within the given
  * range. If less than the maximum number of entries is found within the distance
  * only that number of entries will be returned. When no distance is given or the
  * distance is given as "0" the maximum number of entries will be retrieved.
  *
  * @return mixed|\Zend\View\Model\ModelInterface
  * @throws \UnexpectedValueException
  */
 public function nextGroupsAction()
 {
     $adapter = $this->getAdapter();
     $response = $this->getResponse();
     $viewModel = $this->getViewModel();
     Json::$useBuiltinEncoderDecoder = true;
     // Get Latitude, Longitude, distance and/or number of groups to retrieve
     $latitude = $this->params()->fromQuery('latitude');
     $longitude = $this->params()->fromQuery('longitude');
     $distance = $this->params()->fromQuery('distance', null);
     $number = $this->params()->fromQuery('count', null);
     //$this->sorter = $this->getServiceManager('Phpug\Sorter\Usergroup\Distance');
     $groups = $this->findGroupsWithinRangeAndDistance($latitude, $longitude, $distance, $number);
     $return = array('currentLocation' => array('latitude' => $latitude, 'longitude' => $longitude), 'groups' => array());
     // $hydrator = $this->getServiceManager('Phpug\Hydrator\Usergroup');
     foreach ($groups as $group) {
         $grp = array('name' => $group[0]->getName(), 'latitude' => $group[0]->getLatitude(), 'longitude' => $group[0]->getLongitude(), 'shortname' => $group[0]->getShortname(), 'distance' => $group['distance'], 'icalendar_url' => $group[0]->getIcalendar_url(), 'url' => $group[0]->getUrl(), 'contacts' => array(), 'uri' => '');
         foreach ($group[0]->getContacts() as $contact) {
             $grp['contacts'][] = array('service' => $contact->getServiceName(), 'name' => $contact->getName(), 'uri' => $contact->getUrl());
         }
         $return['groups'][] = $grp;
     }
     $viewModel->setVariable('groups', $return);
     return $viewModel;
 }
开发者ID:krsreenatha,项目名称:php.ug,代码行数:40,代码来源:LocationController.php

示例4: indexAction

 public function indexAction()
 {
     // 获取到请求的JSON字符串
     $content = $this->request->getContent();
     $this->writeConfig();
     $this->errorService = $this->getServiceLocator()->get("error_service");
     $this->_log = $this->getServiceLocator()->get('DhErrorLogging\\Logger');
     if (empty($content)) {
         // 判断请求数据是否为空,直接返回给客户端,不做进一步的处理
         $this->_log->err('接收到的指令为空!');
         $returnMsg = $this->_processEmptyMsg();
         $this->response->setContent($returnMsg);
         return $this->response;
     }
     try {
         Json::$useBuiltinEncoderDecoder = true;
         $ac = Json::decode($content, Json::TYPE_ARRAY);
         $this->_log->debug('action is: ' . var_export($ac, true));
     } catch (\Exception $e) {
         $this->_log->err('Json解码失败!');
         $codeMsg = $this->_errorCodeMeg('00000003');
         $returnMsg = urldecode(Json::encode($codeMsg));
         $this->response->setContent($returnMsg);
         return $this->response;
     }
     // 接口指令处理
     if (array_key_exists($ac['action'], $this->_actionToService)) {
         $service = $this->getServiceLocator()->get($this->_actionToService[$ac['action']]);
         // 获取可用的openstack节点组
         $osGroup = $this->getOSGroup();
         // 对调用具体指令时捕获异常
         try {
             $checkAuth = $service->checkSignature(json_decode($content, true));
             if (!$checkAuth) {
                 echo json_encode(array("code" => -1, "msg" => "authentication failed"));
                 exit;
             }
             $service->setReader();
             $service->getToken();
             $result = $service->{$ac}['action']($ac['data']);
             $returnData = urldecode($result);
             $this->_log->debug($this->_actionToService[$ac['action']] . ' :' . $returnData . PHP_EOL);
             $this->response->setContent($returnData);
             return $this->response;
         } catch (\Exception $e) {
             file_put_contents('error_index.log', $e->getMessage() . $e->getCode() . PHP_EOL, FILE_APPEND);
             $this->_log->err('调用服务出错:' . $e->getMessage() . $e->getCode() . PHP_EOL);
             $codeMsg = $this->_errorCodeMeg('00000004');
             $returnMsg = urldecode(Json::encode($codeMsg));
             $this->response->setContent($returnMsg);
             return $this->response;
         }
     } else {
         $codeMsg = $this->_errorCodeMeg('00000002');
         $returnMsg = urldecode(Json::encode($codeMsg));
         $this->response->setContent($returnMsg);
         return $this->response;
     }
 }
开发者ID:brighten01,项目名称:zf2-openstack-api,代码行数:59,代码来源:IndexController.php

示例5: nextEventAction

 public function nextEventAction()
 {
     $adapter = $this->getAdapter();
     $response = $this->getResponse();
     $viewModel = $this->getViewModel();
     Json::$useBuiltinEncoderDecoder = true;
     $id = $this->getEvent()->getRouteMatch()->getParam('id');
     if (!$id) {
         return $response->setContent($adapter->serialize(null));
     }
     $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     $result = $em->getRepository('Phpug\\Entity\\Usergroup')->findBy(array('shortname' => $id));
     if (!$result) {
         throw new \UnexpectedValueException(sprintf('Fehler!!'));
     }
     if (1 < count($result)) {
         throw new \UnexpectedValueException(sprintf('Fehler!!'));
     }
     $uri = $result[0]->icalendar_url;
     $data = @file_get_contents($uri);
     if (!$data) {
         throw new \UnexpectedValueException(sprintf('Could not read data'));
     }
     $now = new \DateTime();
     $then = (new \DateTime())->add(new \DateInterval('P1Y'));
     $ical = VObject\Reader::read($data);
     $ical->expand($now, $then);
     $nextEvent = null;
     if (!isset($ical->VEVENT)) {
         throw new \UnexpectedValueException(sprintf('No Event available'));
     }
     foreach ($ical->VEVENT as $event) {
         if (null === $nextEvent || $nextEvent->DTSTART->getDateTime() > $event->DTSTART->getDateTime()) {
             $nextEvent = $event;
         }
     }
     if (!$nextEvent) {
         throw new \UnexpectedValueException(sprintf('No Event defined'));
     }
     $content = array('start' => $nextEvent->DTSTART->getDateTime()->format(\DateTime::RFC2822), 'end' => $nextEvent->DTEND->getDateTime()->format(\DateTime::RFC2822), 'location' => '', 'summary' => 'Next event', 'url' => '', 'description' => '');
     if (isset($nextEvent->LOCATION)) {
         $content['location'] = $nextEvent->LOCATION->getValue();
     }
     if (isset($nextEvent->SUMMARY)) {
         $content['summary'] = $nextEvent->SUMMARY->getValue();
     }
     if (isset($nextEvent->URL)) {
         $content['url'] = $nextEvent->URL->getValue();
     }
     if (isset($nextEvent->DESCRIPTION)) {
         $content['description'] = $nextEvent->DESCRIPTION->getValue();
     }
     return $viewModel->setVariables($content);
 }
开发者ID:krsreenatha,项目名称:php.ug,代码行数:54,代码来源:UsergroupController.php

示例6: testBuiltinJSONEncoderWillProperlyEncodeSolidusInStringValues

 /**
  * @group ZF-8663
  */
 public function testBuiltinJSONEncoderWillProperlyEncodeSolidusInStringValues()
 {
     $source = "</foo><foo>bar</foo>";
     $target = '"<\\/foo><foo>bar<\\/foo>"';
     // first test ext/json
     Json\Json::$useBuiltinEncoderDecoder = true;
     $this->assertEquals($target, Json\Json::encode($source));
 }
开发者ID:heiglandreas,项目名称:zf2,代码行数:11,代码来源:JSONTest.php

示例7: __construct

 /**
  * Client constructor.
  *
  * @param $username
  * @param $apiKey
  */
 private function __construct($username, $apiKey)
 {
     Json::$useBuiltinEncoderDecoder = true;
     $this->defaultOptions = ['auth' => [$username, $apiKey], 'headers' => ['Accepts' => 'application/json']];
 }
开发者ID:allansun,项目名称:docker-cloud-php-api,代码行数:11,代码来源:Client.php

示例8: testWillDecodeStructureWithEmptyKeyToObjectProperly

 /**
  * @group ZF-7586
  */
 public function testWillDecodeStructureWithEmptyKeyToObjectProperly()
 {
     Json\Json::$useBuiltinEncoderDecoder = true;
     $json = '{"":"test"}';
     $object = Json\Json::decode($json, Json\Json::TYPE_OBJECT);
     $this->assertTrue(isset($object->_empty_));
     $this->assertEquals('test', $object->_empty_);
 }
开发者ID:rajanlamic,项目名称:IntTest,代码行数:11,代码来源:JsonTest.php

示例9: testWillEncodeArrayOfObjectsEachWithToJsonMethod

 /**
  * @group ZF-9521
  */
 public function testWillEncodeArrayOfObjectsEachWithToJsonMethod()
 {
     $array = array('one' => new ToJsonClass());
     $expected = '{"one":{"__className":"ZendTest\\\\Json\\\\ToJSONClass","firstName":"John","lastName":"Doe","email":"john@doe.com"}}';
     Json\Json::$useBuiltinEncoderDecoder = true;
     $json = Json\Encoder::encode($array);
     $this->assertEquals($expected, $json);
 }
开发者ID:alab1001101,项目名称:zf2,代码行数:11,代码来源:JsonTest.php


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