public function guardarAction() { $values = \Zend\Json\Json::decode($this->getRequest()->getContent()); $content = array(); foreach ($values as $key) { $content[] = $key; } $nombre = $content[0]; $session = $content[1]; $messaggio = $content[2]; $color = 'yellow'; $xposition = rand(2, 1000); $yposition = rand(3, 650); $zposition = rand(1, 100); $posiciones = $xposition . 'x' . $yposition . 'x' . $zposition; $posterlab = $this->getSessioniDao()->tuttiPerId($session)->getPosterlab(); $tipo = 1; $patron = 'Y-m-d H:i'; $fecha = new DateTime(); $fechactual = $fecha->format($patron); $stato = 1; $productos = array('nome' => $nombre, 'messaggio' => $messaggio, 'color' => $color, 'xyz' => $posiciones, 'posterlab_id' => $posterlab, 'tipo' => $tipo, 'sessione' => $session, 'data' => $fechactual, 'stato' => $stato); $producto = new Interattivo(); $producto->exchangeArray($productos); $nuevoid = $this->getInterattivoDao()->salvare($producto); //$salvado = $this->getInterattivoDao()->salvare($producto); if (!$nuevoid) { $json = new JsonModel(array('data' => 'error')); return $json; } else { $json = new JsonModel(array('data' => 'success', 'messaggio' => $messaggio)); return $json; } }
/** * @return array */ public function getResults($offset, $itemCountPerPage) { $query = $this->createSearchQuery($offset, $itemCountPerPage); $adapter = new Http\Client\Adapter\Curl(); $adapter->setOptions(array('curloptions' => array(CURLOPT_SSL_VERIFYPEER => false))); $client = new Http\Client(); $client->setAdapter($adapter); $client->setMethod('GET'); $client->setUri($this->getOptions()->getSearchEndpoint() . $query); $response = $client->send(); if (!$response->isSuccess()) { throw new Exception\RuntimeException("Invalid response received from CloudSearch.\n" . $response->getContent()); } $results = Json::decode($response->getContent(), Json::TYPE_ARRAY); $this->count = $results['hits']['found']; if (0 == $this->count) { return array(); } if ($this->getOptions()->getReturnIdResults()) { $results = $this->extractResultsToIdArray($results); } foreach ($this->getConverters() as $converter) { $results = $converter->convert($results); } return $results; }
/** * Returns data from string * * @param string $string * @return array */ public function fromString($string) { if (empty($string)) { return array(); } return \Zend\Json\Json::decode($string, \Zend\Json\Json::TYPE_ARRAY); }
private function getPoolMedia($pool) { $director = $this->getServiceLocator()->get('director'); $result = $director->send_command("llist media pool=" . $pool, 2, null); $media = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); return $media['result']['volumes']; }
/** * Get a list of apprentices and mentors * * @return JsonModel */ public function getlistAction() { $config = $this->getServiceLocator()->get('config'); $file = $config['php.ug.mentoringapp']['file']; $content = Json::decode(file_get_contents($file), Json::TYPE_ARRAY); return new JsonModel($content); }
private function getVolume($volume) { $director = $this->getServiceLocator()->get('director'); $result = $director->send_command('llist volume="' . $volume . '"', 2, null); $pools = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); return $pools['result']['volume']; }
protected function getContactsFromResponse() { if (!$this->response) { return false; } $data = $this->response->getBody(); if (!$data) { return false; } $data = Json::decode($data, 1); if (!isset($data['feed']['entry'])) { return false; } $users = $data['feed']['entry']; foreach ($users as $key => $user) { if (!isset($user['gd$email'])) { continue; } $email = null; foreach ($user['gd$email'] as $address) { if ($email) { continue; } $email = $address['address']; } if (!$email) { continue; } $contacts[] = array('name' => isset($user['title']['$t']) ? $user['title']['$t'] : null, 'email' => $email); } return $contacts; }
protected function _parseParameters(HTTPResponse $response) { $params = array(); $body = $response->getBody(); if (empty($body)) { return; } $tokenFormat = $this->getTokenFormat(); switch ($tokenFormat) { case 'json': $params = \Zend\Json\Json::decode($body); break; case 'jsonp': break; case 'pair': $parts = explode('&', $body); foreach ($parts as $kvpair) { $pair = explode('=', $kvpair); $params[rawurldecode($pair[0])] = rawurldecode($pair[1]); } break; default: throw new Exception\InvalidArgumentException(sprintf('Unable to handle access token response by undefined format %', $tokenFormat)); } return (array) $params; }
public function deleteAction() { foreach (Json::decode($this->getRequest()->getContent(), Json::TYPE_ARRAY) as $item) { $this->service->deleteRow($item); } return new JsonModel([]); }
public static function getLatLng($address) { $latLng = []; try { $url = sprintf('http://maps.google.com/maps/api/geocode/json?address=%s&sensor=false', $address); $client = new Client($url); $client->setAdapter(new Curl()); $client->setMethod('GET'); $client->setOptions(['curloptions' => [CURLOPT_HEADER => false]]); $response = $client->send(); $body = $response->getBody(); $result = Json\Json::decode($body, 1); $latLng = ['lat' => $result['results'][0]['geometry']['location']['lat'], 'lng' => $result['results'][0]['geometry']['location']['lng']]; $isException = false; } catch (\Zend\Http\Exception\RuntimeException $e) { $isException = true; } catch (\Zend\Http\Client\Adapter\Exception\RuntimeException $e) { $isException = true; } catch (Json\Exception\RuntimeException $e) { $isException = true; } catch (Json\Exception\RecursionException $e2) { $isException = true; } catch (Json\Exception\InvalidArgumentException $e3) { $isException = true; } catch (Json\Exception\BadMethodCallException $e4) { $isException = true; } if ($isException === true) { //código em caso de problemas no decode } return $latLng; }
/** * Loads currencies specs */ private static function loadSpecifications() { if (!self::$specifications) { $content = file_get_contents(__DIR__ . '/../data/currencies.json'); self::$specifications = Json::decode($content, Json::TYPE_ARRAY); } }
public function listOrdersAction() { $params = Json::decode($this->getRequest()->getContent(), Json::TYPE_ARRAY); $order = $this->getServiceLocator()->get('TocatCore\\Model\\OrderTableGateway'); if (empty($params)) { return new ViewModel(iterator_to_array($order->select())); } if (isset($params['ticket_id'])) { $rowset = $order->select(function (Select $select) use($params) { $select->join('order_ticket', 'order_ticket.order_uid = order.uid', array()); $select->join('ticket', 'order_ticket.ticket_uid = ticket.uid', array()); $select->where(array('ticket.ticket_id' => $params['ticket_id'])); $select->quantifier('DISTINCT'); }); return new ViewModel(iterator_to_array($rowset)); } if (isset($params['project_id'])) { $rowset = $order->select(function (Select $select) use($params) { $select->join('order_project', 'order_project.order_uid = order.uid', array()); $select->join('project', 'order_project.project_uid = project.uid'); $select->where(array('project.project_id' => $params['project_id'])); $select->quantifier('DISTINCT'); }); return new ViewModel(iterator_to_array($rowset)); } }
private function getFilesets() { $director = $this->getServiceLocator()->get('director'); $result = $director->send_command("list filesets", 2, null); $filesets = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); return $filesets['result']['filesets']; }
public function getList() { $config = $this->getServiceLocator()->get('config'); $file = $config['php.ug.event']['cachefile']; $content = Json::decode(file_get_contents($file), Json::TYPE_ARRAY); return new JsonModel($content); }
public function setBudgetAction() { $params = Json::decode($this->getRequest()->getContent(), Json::TYPE_ARRAY); switch ($params['type']) { case 'project': return new ApiProblemResponse(new ApiProblem(406, 'Not Implemented')); break; case 'ticket': default: $ticket = $this->getServiceLocator()->get('TocatCore\\Model\\TicketTableGateway'); $rowset = $ticket->select(array('ticket_id' => $params['id'])); if (count($rowset) < 1) { return new ApiProblemResponse(new ApiProblem(404, 'Not Found')); } $order = $this->getServiceLocator()->get('TocatCore\\Model\\OrderTableGateway'); $orderList = $order->select(function (Select $select) use($rowset) { $select->columns(array('totalBudget' => new Expression('SUM(order.budget)'))); $select->join('order_ticket', 'order_ticket.order_uid = order.uid', array()); $select->where(array('order_ticket.uid' => $rowset->current()->uid)); $select->group('order_ticket.uid'); }); if ($params['budget'] > $orderList->current()->totalBudget) { return new ApiProblemResponse(new ApiProblem(406, 'Budget value bigger then total budget')); } $ticket->update(array('budget' => $params['budget']), array('uid' => $rowset->current()->uid)); $rowset = $ticket->select(array('ticket_id' => $params['id'])); return new ViewModel((array) $rowset->current() + (array) $orderList->current()); break; } }
/** * {@inheritdoc} */ public function decode(Response $response) { $headers = $response->getHeaders(); if (!$headers->has('Content-Type')) { $exception = new Exception\InvalidResponseException('Content-Type missing'); $exception->setResponse($response); throw $exception; } /* @var $contentType \Zend\Http\Header\ContentType */ $contentType = $headers->get('Content-Type'); switch (true) { case $contentType->match('*/json'): $payload = Json::decode($response->getBody(), Json::TYPE_ARRAY); break; //TODO: xml // case $contentType->match('*/xml'): // $xml = Security::scan($response->getBody()); // $payload = Json::decode(Json::encode((array) $xml), Json::TYPE_ARRAY); // break; //TODO: xml // case $contentType->match('*/xml'): // $xml = Security::scan($response->getBody()); // $payload = Json::decode(Json::encode((array) $xml), Json::TYPE_ARRAY); // break; default: throw new Exception\InvalidFormatException(sprintf('The "%s" media type is invalid or not supported', $contentType->getMediaType())); break; } $this->lastPayload = $payload; if ($contentType->match('*/hal+*')) { return $this->extractResourceFromHal($payload, $this->getPromoteTopCollection()); } //else return (array) $payload; }
/** * @todo whats wrong with SSL? * @return array */ public function doRequest() { $url = 'https://www.mvg.de/.rest/betriebsaenderungen/api/interruptions'; $client = new Client($url, array('adapter' => 'Zend\\Http\\Client\\Adapter\\Curl', 'curloptions' => array(CURLOPT_FOLLOWLOCATION => TRUE, CURLOPT_SSL_VERIFYPEER => FALSE))); $client->setMethod(\Zend\Http\Request::METHOD_GET); return ZendJson::decode($client->send()->getBody()); }
/** * Update action * * @return JsonModel */ public function updateAction() { $postPayload = Json::decode($this->getRequest()->getContent(), Json::TYPE_ARRAY); $errorMessage = ''; if (isset($postPayload[self::KEY_POST_PACKAGES]) && is_array($postPayload[self::KEY_POST_PACKAGES]) && isset($postPayload[self::KEY_POST_JOB_TYPE])) { $errorMessage .= $this->validatePayload($postPayload); if (empty($errorMessage)) { $packages = $postPayload[self::KEY_POST_PACKAGES]; $jobType = $postPayload[self::KEY_POST_JOB_TYPE]; $this->createTypeFlag($jobType, $postPayload[self::KEY_POST_HEADER_TITLE]); $additionalOptions = []; $cronTaskType = ''; $this->getCronTaskConfigInfo($jobType, $postPayload, $additionalOptions, $cronTaskType); $errorMessage .= $this->updater->createUpdaterTask($packages, $cronTaskType, $additionalOptions); // for module enable job types, we need to follow up with 'setup:upgrade' task to // make sure enabled modules are properly registered if ($jobType == 'enable') { $errorMessage .= $this->updater->createUpdaterTask([], \Magento\Setup\Model\Cron\JobFactory::JOB_UPGRADE, []); } } } else { $errorMessage .= 'Invalid request'; } $success = empty($errorMessage) ? true : false; return new JsonModel(['success' => $success, 'message' => $errorMessage]); }
private function getStorages() { $director = $this->getServiceLocator()->get('director'); $result = $director->send_command("list storages", 2, null); $storages = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); return $storages['result']['storages']; }
/** * Fetches the version of the latest stable release. * * By Default, this uses the GitHub API (v3) and only returns refs that begin with * 'tags/release-'. Because GitHub returns the refs in alphabetical order, * we need to reduce the array to a single value, comparing the version * numbers with version_compare(). * * If $service is set to VERSION_SERVICE_ZEND this will fall back to calling the * classic style of version retreival. * * * @see http://developer.github.com/v3/git/refs/#get-all-references * @link https://api.github.com/repos/zendframework/zf2/git/refs/tags/release- * @link http://framework.zend.com/api/zf-version?v=2 * @param string $service Version Service with which to retrieve the version * @return string */ public static function getLatest($service = self::VERSION_SERVICE_ZEND) { if (null === static::$latestVersion) { static::$latestVersion = 'not available'; if ($service == self::VERSION_SERVICE_GITHUB) { $url = 'https://api.github.com/repos/zendframework/zf2/git/refs/tags/release-'; $apiResponse = Json::decode(file_get_contents($url), Json::TYPE_ARRAY); // Simplify the API response into a simple array of version numbers $tags = array_map(function ($tag) { return substr($tag['ref'], 18); // Reliable because we're filtering on 'refs/tags/release-' }, $apiResponse); // Fetch the latest version number from the array static::$latestVersion = array_reduce($tags, function ($a, $b) { return version_compare($a, $b, '>') ? $a : $b; }); } elseif ($service == self::VERSION_SERVICE_ZEND) { $handle = fopen('http://framework.zend.com/api/zf-version?v=2', 'r'); if (false !== $handle) { static::$latestVersion = stream_get_contents($handle); fclose($handle); } } } return static::$latestVersion; }
/** * @return array */ public function getParams() { if (!$this->params) { $this->params = $this->_params ? \Zend\Json\Json::decode($this->_params) : array(); } return $this->params; }
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; } }
protected function getConfigDisplay() { $select = $this->sqlObj->select(); $select->from('config')->where('id = 1'); $result = \ZendVN\Db\Sql\Result::toArray($select, $this->adapter); $result = $result[0]; return \Zend\Json\Json::decode($result['display']); }
/** * Set response state based on JSON * * @param string $json * @return void * @throws Exception\RuntimeException */ public function loadJson($json) { $options = Json::decode($json, Json::TYPE_ARRAY); if (!is_array($options)) { throw new Exception\RuntimeException('json is not a valid response; array expected'); } $this->setOptions($options); }
public function getValue($raw = false) { $value = parent::getValue(); if (!$raw) { $value = \Zend\Json\Json::decode($value); } return $value; }
/** * Decodes a JSON string into an array. * * @param string $jsonString * @throws Exception\DecodeException * @return array */ public function decode($jsonString) { try { return Json::decode($jsonString, Json::TYPE_ARRAY); } catch (\Exception $e) { throw new Exception\DecodeException(sprintf("JSON decode exception: [%s] %s", get_class($e), $e->getMessage()), null, $e); } }
/** * Checks if module has uninstall class * * @return JsonModel */ public function hasUninstallAction() { $params = Json::decode($this->getRequest()->getContent(), Json::TYPE_ARRAY); if (isset($params['moduleName'])) { $uninstallClasses = $this->uninstallCollector->collectUninstall([$params['moduleName']]); } return new JsonModel(['hasUninstall' => isset($uninstallClasses) && sizeof($uninstallClasses) > 0]); }
/** * Returns the balance for a given Bitcoin Address * @param $address * @return string */ public function getWalletBalance($address) { $this->client->setUri($this->url . '/address_balance'); $this->client->setParameterGet(array('password' => $this->blockchain_password, 'address' => $address, 'confirmations' => '0')); $json = $this->process(); $array = Json\Json::decode($json); return number_format($array->balance / 100000000, 10); }
public function saveTreeAction() { $tree = Json::decode($this->getRequest()->getContent(), Json::TYPE_ARRAY); $this->service->saveTree($tree); // todo: report bug to zfcAdmin module //return $this->forward('OpsWay\TocatUser\Controller\Admin\Role',array('action' => 'list')); return new JsonModel($this->service->getList()); }
public function getTestConfig() { $driverOptions = array(); if (defined('TESTS_ZEND_QUEUE_DB')) { $driverOptions = \Zend\Json\Json::decode(TESTS_ZEND_QUEUE_DB); } return array('options' => array(Select::FOR_UPDATE => true), 'driverOptions' => $driverOptions); }