• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Utils\Json类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中Nette\Utils\Json的典型用法代码示例。如果您正苦于以下问题:PHP Json类的具体用法?PHP Json怎么用?PHP Json使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: authenticate

 public function authenticate(array $credentials)
 {
     $mcrypt = mcrypt_module_open(MCRYPT_BLOWFISH, '', MCRYPT_MODE_CBC, '');
     $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($mcrypt), MCRYPT_DEV_RANDOM);
     mcrypt_generic_init($mcrypt, $this->cryptPassword, $iv);
     $url = $this->getUrl($credentials[self::USERNAME], $credentials[self::PASSWORD], $mcrypt, $iv);
     try {
         $res = $this->httpClient->get($url)->send();
     } catch (\Guzzle\Http\Exception\ClientErrorResponseException $e) {
         if ($e->getResponse()->getStatusCode() === 403) {
             throw new \Nette\Security\AuthenticationException("User '{$credentials[self::USERNAME]}' not found.", self::INVALID_CREDENTIAL);
         } elseif ($e->getResponse()->getStatusCode() === 404) {
             throw new \Nette\Security\AuthenticationException("Invalid password.", self::IDENTITY_NOT_FOUND);
         } else {
             throw $e;
         }
     }
     $responseBody = trim(mdecrypt_generic($mcrypt, $res->getBody(TRUE)));
     $apiData = Json::decode($responseBody);
     $user = $this->db->table('users')->where('id = ?', $apiData->id)->fetch();
     $registered = new \DateTimeImmutable($apiData->registered->date, new \DateTimeZone($apiData->registered->timezone));
     $userData = array('username' => $credentials[self::USERNAME], 'password' => $this->calculateAddonsPortalPasswordHash($credentials[self::PASSWORD]), 'email' => $apiData->email, 'realname' => $apiData->realname, 'url' => $apiData->url, 'signature' => $apiData->signature, 'language' => $apiData->language, 'num_posts' => $apiData->num_posts, 'apiToken' => $apiData->apiToken, 'registered' => $registered->getTimestamp());
     if (!$user) {
         $userData['id'] = $apiData->id;
         $userData['group_id'] = 4;
         $this->db->table('users')->insert($userData);
         $user = $this->db->table('users')->where('username = ?', $credentials[self::USERNAME])->fetch();
     } else {
         $user->update($userData);
     }
     return $this->createIdentity($user);
 }
开发者ID:newPOPE,项目名称:web-addons.nette.org,代码行数:32,代码来源:NetteOrgAuthenticator.php


示例2: parseResultResponse

 /**
  * Funkce pro naparsování odpovědi získané od scoreru
  * @param array|string $scorerResponseData
  */
 private function parseResultResponse($scorerResponseData)
 {
     if (is_string($scorerResponseData)) {
         $scorerResponseData = Json::decode($scorerResponseData);
     }
     #region score and rule
     if (!empty($scorerResponseData['score'])) {
         foreach ($scorerResponseData['score'] as $i => $rowResult) {
             if ($rowResult == null) {
                 $this->classificationResults[] = null;
                 $this->rules[] = null;
                 continue;
             }
             if ($this->classificationAttribute == "") {
                 foreach ($rowResult as $key => $value) {
                     $this->classificationAttribute = $key;
                     break;
                 }
             }
             $this->classificationResults[] = @$rowResult[$this->classificationAttribute];
             if (!empty($scorerResponseData['rule'][$i]) && !empty($scorerResponseData['rule'][$i]['id'])) {
                 $this->rules[] = $scorerResponseData['rule'][$i]['id'];
             } else {
                 $this->rules[] = null;
             }
         }
     }
     #endregion score and rule
     #region confusionMatrix
     $this->confusionMatrix = new ScoringConfusionMatrix($scorerResponseData['confusionMatrix']['labels'], $scorerResponseData['confusionMatrix']['matrix']);
     #endregion confusionMatrix
 }
开发者ID:kizi,项目名称:easyminer-easyminercenter,代码行数:36,代码来源:EasyMinerScoringResult.php


示例3: actionCreateOrder

 public function actionCreateOrder()
 {
     $post = $this->getHttpRequest()->getPost();
     $data = Json::decode($post['data'], 1);
     $this->orderManager->createOrder($data['language'], $data['products'], $data['customer']);
     $this->terminate();
 }
开发者ID:pogodi,项目名称:OCApi,代码行数:7,代码来源:OrderPresenter.php


示例4: getPanel

 /**
  * @return string
  */
 public function getPanel()
 {
     if (!$this->queries) {
         return NULL;
     }
     ob_start();
     $esc = callback('Nette\\Templating\\Helpers::escapeHtml');
     $click = class_exists('\\Tracy\\Dumper') ? function ($o, $c = FALSE, $d = 4) {
         return \Tracy\Dumper::toHtml($o, array('collapse' => $c, 'depth' => $d));
     } : callback('\\Tracy\\Helpers::clickableDump');
     $totalTime = $this->totalTime ? sprintf('%0.3f', $this->totalTime * 1000) . ' ms' : 'none';
     $extractData = function ($object) {
         if ($object instanceof Elastica\Request) {
             $data = $object->getData();
         } elseif ($object instanceof Elastica\Response) {
             $data = $object->getData();
         } else {
             return array();
         }
         try {
             return !is_array($data) ? Json::decode($data, Json::FORCE_ARRAY) : $data;
         } catch (Nette\Utils\JsonException $e) {
             try {
                 return array_map(function ($row) {
                     return Json::decode($row, Json::FORCE_ARRAY);
                 }, explode("\n", trim($data)));
             } catch (Nette\Utils\JsonException $e) {
                 return $data;
             }
         }
     };
     $processedQueries = array();
     $allQueries = $this->queries;
     foreach ($allQueries as $authority => $requests) {
         /** @var Elastica\Request[] $item */
         foreach ($requests as $i => $item) {
             $processedQueries[$authority][$i] = $item;
             if (isset($item[3])) {
                 continue;
                 // exception, do not re-execute
             }
             if (stripos($item[0]->getPath(), '_search') === FALSE || $item[0]->getMethod() !== 'GET') {
                 continue;
                 // explain only search queries
             }
             if (!is_array($data = $extractData($item[0]))) {
                 continue;
             }
             try {
                 $response = $this->client->request($item[0]->getPath(), $item[0]->getMethod(), $item[0]->getData(), array('explain' => 1) + $item[0]->getQuery());
                 // replace the search response with the explained response
                 $processedQueries[$authority][$i][1] = $response;
             } catch (\Exception $e) {
                 // ignore
             }
         }
     }
     require __DIR__ . '/panel.phtml';
     return ob_get_clean();
 }
开发者ID:rattuscz,项目名称:ElasticSearch,代码行数:63,代码来源:Panel.php


示例5: createFromRequest

 /**
  * @param Request $request
  * @return Notification
  */
 public static function createFromRequest(Request $request)
 {
     $notification = new Notification();
     $parsed = Json::decode($request->getRawBody());
     $notification->setLive($parsed->live === 'true');
     $items = array();
     foreach ($parsed->notificationItems as $rawItem) {
         $item = new NotificationRequestItem($notification);
         $item->setAdditionalData(self::getNotificationRequestItemValue($rawItem, 'additionalData'));
         $item->setAmountValue(self::getNotificationRequestItemValue($rawItem, 'amount.value'));
         $item->setAmountCurrency(self::getNotificationRequestItemValue($rawItem, 'amount.currency'));
         $item->setPspReference(self::getNotificationRequestItemValue($rawItem, 'pspReference'));
         $item->setEventCode(self::getNotificationRequestItemValue($rawItem, 'eventCode'));
         $date = new DateTime(self::getNotificationRequestItemValue($rawItem, 'eventDate'));
         $item->setEventDate($date);
         $item->setMerchantAccountCode(self::getNotificationRequestItemValue($rawItem, 'merchantAccountCode'));
         $item->setOperations(self::getNotificationRequestItemValue($rawItem, 'operations'));
         $item->setMerchantReference(self::getNotificationRequestItemValue($rawItem, 'merchantReference'));
         $item->setOriginalReference(self::getNotificationRequestItemValue($rawItem, 'originalReference'));
         $item->setPaymentMethod(self::getNotificationRequestItemValue($rawItem, 'paymentMethod'));
         $item->setReason(self::getNotificationRequestItemValue($rawItem, 'reason'));
         $item->setSuccess(self::getNotificationRequestItemValue($rawItem, 'success') === 'true');
         $items[] = $item;
     }
     $notification->setNotificationItems($items);
     return $notification;
 }
开发者ID:metisfw,项目名称:adyen,代码行数:31,代码来源:Notification.php


示例6: getPlugins

 /**
  * Get plugins
  *
  * @param array $pluginsDirs Plugins directories
  *
  * @return array
  */
 private function getPlugins(array $pluginsDirs)
 {
     $plugins = array();
     foreach (Finder::findFiles("plugin.json")->from($pluginsDirs) as $plugin) {
         $config = Json::decode(file_get_contents($plugin->getRealPath()), 1);
         if (!isset($config["class"]) || !class_exists($config["class"])) {
             continue;
         }
         // Get types
         foreach (class_implements($config["class"]) as $interface) {
             if (isset($this->pluginTypes[$interface])) {
                 $config["types"][$this->pluginTypes[$interface]] = true;
             }
         }
         // Skip if unknown plugin type
         if (empty($config["types"])) {
             continue;
         }
         // Get plugin dir path
         $config["path"] = dirname($plugin->getPathName());
         // Get unique plugin name from class
         $config["name"] = strtolower(stripslashes($config["class"]));
         $plugins[$config["name"]] = $config;
     }
     return $plugins;
 }
开发者ID:ixtrum,项目名称:file-manager,代码行数:33,代码来源:Configurator.php


示例7: process

 protected function process()
 {
     $v = $this->getValues();
     /** @var Rme\Subject $subject */
     $subject = $this->presenter->subject;
     $subject->title = $v->title;
     $subject->description = $v->description;
     /** @var self|EditorSelector[] $this */
     if ($this['editors']->isEditable()) {
         $subject->editors = $v->editors;
     }
     $schemas = Json::decode($v['positions']);
     foreach ($subject->schemas as $schema) {
         $schema->position = NULL;
         $schema->subject = NULL;
     }
     $position = 0;
     foreach ($schemas as $schemaId) {
         /** @var Rme\Schema $schema */
         $schema = $this->orm->schemas->getById($schemaId);
         $schema->position = $position;
         $schema->subject = $subject;
         $position++;
     }
     $this->orm->flush();
     $this->presenter->flashSuccess('editor.edited.schema');
     $this->presenter->purgeCacheTag('header');
     $this->presenter->redirect('this');
 }
开发者ID:VasekPurchart,项目名称:khanovaskola-v3,代码行数:29,代码来源:Subject.php


示例8: loadConfiguration

 public function loadConfiguration()
 {
     $builder = $this->getContainerBuilder();
     $config = $this->getConfig($this->defaults);
     $builder->addDefinition($this->prefix('helperSet'))->setClass('Symfony\\Component\\Console\\Helper\\HelperSet', array(array(new Nette\DI\Statement('Symfony\\Component\\Console\\Helper\\DialogHelper'), new Nette\DI\Statement('Symfony\\Component\\Console\\Helper\\FormatterHelper'), new Nette\DI\Statement('Symfony\\Component\\Console\\Helper\\ProgressHelper'), new Nette\DI\Statement('Kdyby\\Console\\Helpers\\PresenterHelper'))))->setInject(FALSE);
     $builder->addDefinition($this->prefix('application'))->setClass('Kdyby\\Console\\Application', array($config['name'], $config['version']))->addSetup('setHelperSet', array($this->prefix('@helperSet')))->setInject(FALSE);
     $builder->addDefinition($this->prefix('router'))->setClass('Kdyby\\Console\\CliRouter')->setAutowired(FALSE)->setInject(FALSE);
     $builder->getDefinition('router')->addSetup('Kdyby\\Console\\CliRouter::prependTo($service, ?)', array($this->prefix('@router')));
     $builder->getDefinition('nette.presenterFactory')->addSetup('if (method_exists($service, ?)) { $service->setMapping(array(? => ?)); } ' . 'elseif (property_exists($service, ?)) { $service->mapping[?] = ?; }', array('setMapping', 'Kdyby', 'KdybyModule\\*\\*Presenter', 'mapping', 'Kdyby', 'KdybyModule\\*\\*Presenter'));
     if (!empty($config['url'])) {
         if (!preg_match('~^https?://[^/]+\\.[a-z]+(/.*)?$~', $config['url'])) {
             throw new Nette\Utils\AssertionException("The url '{$config['url']}' is not valid, please use this format: 'http://domain.tld/path'.");
         }
         $builder->getDefinition('nette.httpRequestFactory')->setClass('Kdyby\\Console\\HttpRequestFactory')->addSetup('setFakeRequestUrl', array($config['url']));
     }
     $builder->addDefinition($this->prefix('dicHelper'))->setClass('Kdyby\\Console\\ContainerHelper')->addTag(self::HELPER_TAG, 'dic');
     Nette\Utils\Validators::assert($config, 'array');
     foreach ($config['commands'] as $command) {
         $def = $builder->addDefinition($this->prefix('command.' . md5(Nette\Utils\Json::encode($command))));
         list($def->factory) = Nette\DI\Compiler::filterArguments(array(is_string($command) ? new Nette\DI\Statement($command) : $command));
         if (class_exists($def->factory->entity)) {
             $def->class = $def->factory->entity;
         }
         $def->setAutowired(FALSE);
         $def->setInject(FALSE);
         $def->addTag(self::COMMAND_TAG);
     }
 }
开发者ID:pixuin,项目名称:console,代码行数:28,代码来源:ConsoleExtension.php


示例9: handleDelete

 /**
  * @secured
  * @param $usersID
  */
 public function handleDelete($usersID)
 {
     if (is_string($usersID)) {
         try {
             $usersID = (array) Json::decode($usersID);
             $usersID = array_values($usersID);
         } catch (JsonException $e) {
             $this['notification']->addError($e->getMessage());
             if ($this->isAjax()) {
                 $this['notification']->redrawControl('error');
             }
         }
     }
     $result = $this->userRepository->deactivate($usersID);
     if ($result === TRUE) {
         $this['notification']->addSuccess("Úspěšně deaktivováno...");
     } else {
         if (strpos("Integrity constraint violation", $result) != -1) {
             $this['notification']->addError("Uživatele se nepovedlo deaktivovat.");
         } else {
             $this['notification']->addError($result);
         }
     }
     if ($this->isAjax()) {
         $this['notification']->redrawControl('error');
         $this['notification']->redrawControl('success');
         $this['grid']->redrawControl();
     }
 }
开发者ID:vipercz,项目名称:sandbox,代码行数:33,代码来源:UserPresenter.php


示例10: send

 /**
  * {inheritDoc}
  */
 public function send(Nette\Http\IRequest $httpRequest, Nette\Http\IResponse $httpResponse)
 {
     $httpResponse->setContentType($this->getContentType(), 'utf-8');
     $httpResponse->setExpiration(FALSE);
     $httpResponse->setCode($this->code);
     echo Nette\Utils\Json::encode($this->getPayload(), Nette\Utils\Json::PRETTY);
 }
开发者ID:ublaboo,项目名称:responses,代码行数:10,代码来源:JsonPrettyResponse.php


示例11: sendJsonResponse

 /**
  * Funkce pro odeslání JSON odpovědi
  * @param array|object|string $data
  */
 protected function sendJsonResponse($data, $code = IResponse::S200_OK)
 {
     $httpResponse = $this->getHttpResponse();
     $httpResponse->setContentType('application/json', 'UTF-8');
     $httpResponse->setCode($code);
     $this->sendResponse(new TextResponse(is_string($data) ? $data : Json::encode($data)));
 }
开发者ID:kizi,项目名称:easyminer-easyminercenter,代码行数:11,代码来源:ResponsesTrait.php


示例12: login

 /**
  * funkce obstaravajici prihlaseni uzivatele
  */
 private function login()
 {
     $this->database = $this->context->getService("database.default.context");
     $data = Nette\Utils\Json::decode($this->request->getParameters()["data"]);
     $authenticator = new LoginAuthenticator($this->database);
     $user = $this->getUser();
     $user->setAuthenticator($authenticator);
     try {
         $user->login($data->username, $data->password);
     } catch (Nette\Security\AuthenticationException $e) {
         $error["err"] = true;
         $error["message"] = $e->getMessage();
         return $error;
     }
     $userIdent = (array) $user->getIdentity()->getData();
     $tokenId = base64_encode(mcrypt_create_iv(32));
     $issuedAt = time();
     $notBefore = $issuedAt;
     $expire = $notBefore + 60 * 60;
     $serverName = "lolnotepad";
     $token = ['iat' => $issuedAt, 'jti' => $tokenId, 'iss' => $serverName, 'nbf' => $notBefore, 'exp' => $expire, 'data' => $userIdent];
     $key = base64_decode(KEY);
     $jwt = JWT::encode($token, $key, 'HS256');
     return $jwt;
 }
开发者ID:havlicekdom,项目名称:league-notepadv2-angular,代码行数:28,代码来源:UserPresenter.php


示例13: call

 /**
  * @param string $method
  * @param string $endpoint
  * @param array $parameters
  * @return mixed
  * @throws MailChimpException
  */
 public function call($method = 'GET', $endpoint = '', array $parameters = [])
 {
     $uri = $this->config['apiUrl'] . (strlen($endpoint) && $endpoint[0] == '/' ? substr($endpoint, 1) : $endpoint);
     $headers = ['Authorization' => 'apikey ' . $this->config['apiKey']];
     try {
         $body = $parameters ? Json::encode($parameters) : null;
     } catch (JsonException $e) {
         throw new MailChimpException('MailChimp request - invalid json', 667, $e);
     }
     $client = new Client();
     $request = new Request($method, $uri, $headers, $body);
     $resource = new Resource($request);
     try {
         /** @var \GuzzleHttp\Psr7\Response $response */
         $response = $client->send($request);
         $resource->setSuccessResponse($response);
     } catch (GuzzleException $e) {
         $resource->setErrorResponse($e);
     }
     $this->onResponse($resource);
     if ($resource->getException()) {
         throw new MailChimpException('MailChimp response - error', 666, $resource->getException());
     } else {
         return $resource->getResult();
     }
 }
开发者ID:FreezyBee,项目名称:MailChimp,代码行数:33,代码来源:Api.php


示例14: create

 public function create()
 {
     $form = new Form();
     $form->addText('workStart', 'Začátek', 3, 5)->setRequired('Vyplňte pole "Začátek prac. doby".')->setDefaultValue($this->defaultItemTime['workStart'])->setHtmlId('workStart')->setAttribute('class', 'input-time')->addRule(Form::PATTERN, 'Do pole "Začátek prac. doby" lze zadat pouze
                  čas v 24 hodinovém formátu po půlhodinách.', '([01]?[0-9]|2[0-3]):(0|3)0');
     $form->addText('workEnd', 'Konec', 3, 5)->setRequired('Vyplňte pole "Konec prac. doby".')->setDefaultValue($this->defaultItemTime['workEnd'])->setHtmlId('workEnd')->setAttribute('class', 'input-time')->addRule(Form::PATTERN, 'Do pole "Konec prac. doby" lze zadat pouze
                  čas v 24 hodinovém formátu po půlhodinách.', '([01]?[0-9]|2[0-3]):(0|3)0');
     $form->addText('lunch', 'Oběd', 3, 5)->setRequired('Vyplňte pole "Oběd".')->setDefaultValue($this->defaultItemTime['lunch'])->setHtmlId('lunch')->setAttribute('class', 'input-time')->addRule(Form::PATTERN, 'Do pole "Oběd" lze zadat pouze
                  čas v ve formátu s čárkou. (např. 1 nebo 1,5)', '^(0|[1-9]|1[0-9]|2[0-3])(,(0|5))?$');
     $form->addText('otherHours', 'Ostatní hod.')->setDefaultValue($this->defaultItemTime['otherHours'])->setHtmlId('otherHours')->setAttribute('class', 'input-time')->addCondition(Form::FILLED)->addRule(Form::PATTERN, 'Do pole "Ostaní hodiny" lze zadat pouze
                  čas ve formátu s čárkou.(např. 6 nebo 6,5)', '^(0|[1-9]|1[0-9]|2[0-3])(,(0|5))?$');
     $form->addText('locality', 'Místo pracoviště', 28, 40)->setRequired('Vyplňte pole "Místo pracoviště".')->setHtmlId('locality')->getControlPrototype()->class = 'item-text-input';
     $form->addText('description', 'Popis práce', 28, 30)->getControlPrototype()->class = 'item-text-input';
     $form->addText('descOtherHours', 'Komentář k ostat. hod. (např. svátek)', 28, 30)->addConditionOn($form['otherHours'], Form::FILLED)->addCondition(Form::FILLED)->addRule(function ($item, $arg) {
         return \InvoiceTime::processTime($arg) == '00:00:00' ? false : true;
     }, self::OTHER_HOURS_ZERO_TIME_ERROR_MSG, $form['otherHours']);
     $form['descOtherHours']->getControlPrototype()->class = 'item-text-input';
     // time control buttons
     $form->addButton('workStartAdd', '+')->setAttribute('class', self::BTN_TIME_ADD_CLASS)->setAttribute('data-time', Json::encode(['inputID' => $form['workStart']->control->attrs['id'], 'slider' => 'slider_range', 'pos' => 0, 'val' => -30]));
     $form->addButton('workStartSub', '-')->setAttribute('class', self::BTN_TIME_SUB_CLASS)->setAttribute('data-time', Json::encode(['inputID' => $form['workStart']->control->attrs['id'], 'slider' => 'slider_range', 'pos' => 0, 'val' => 30]));
     $form->addButton('workEndAdd', '+')->setAttribute('class', self::BTN_TIME_ADD_CLASS)->setAttribute('data-time', Json::encode(['inputID' => $form['workEnd']->control->attrs['id'], 'slider' => 'slider_range', 'pos' => 1, 'val' => 30]));
     $form->addButton('workEndSub', '-')->setAttribute('class', self::BTN_TIME_SUB_CLASS)->setAttribute('data-time', Json::encode(['inputID' => $form['workEnd']->control->attrs['id'], 'slider' => 'slider_range', 'pos' => 1, 'val' => -30]));
     $form->addButton('lunchAdd', '+')->setAttribute('class', self::BTN_TIME_ADD_CLASS)->setAttribute('data-time', Json::encode(['inputID' => $form['lunch']->control->attrs['id'], 'slider' => 'slider_lunch', 'val' => -30]));
     $form->addButton('lunchSub', '-')->setAttribute('class', self::BTN_TIME_SUB_CLASS)->setAttribute('data-time', Json::encode(['inputID' => $form['lunch']->control->attrs['id'], 'slider' => 'slider_lunch', 'val' => 30]));
     $form->addButton('otherHoursAdd', '+')->setAttribute('class', self::BTN_TIME_ADD_CLASS)->setAttribute('data-time', Json::encode(['inputID' => $form['otherHours']->control->attrs['id'], 'slider' => 'slider_time_other', 'val' => 0]));
     $form->addButton('otherHoursSub', '-')->setAttribute('class', self::BTN_TIME_SUB_CLASS)->setAttribute('data-time', Json::encode(['inputID' => $form['otherHours']->control->attrs['id'], 'slider' => 'slider_time_other', 'val' => 0]));
     $form->addSubmit('save', 'Uložit řádek');
     $form->getElementPrototype()->id = 'update-form';
     return $form;
 }
开发者ID:blitzik,项目名称:vycetky,代码行数:30,代码来源:ItemUpdateFormFactory.php


示例15: send

 public function send(RequestInterface $request)
 {
     try {
         return parent::send($request);
     } catch (\GuzzleHttp\Exception\ServerException $e) {
         $response = $e->getResponse();
         $body = $response->getBody()->getContents();
         $message = $e->getMessage();
         try {
             $data = Json::decode($body);
             $message = implode(', ', $data->errors);
         } catch (JsonException $e) {
             //ignore
         }
         $ex = new ServerException($message, $e->getCode(), $e);
         $ex->setBody($body);
         throw $ex;
     } catch (\GuzzleHttp\Exception\ClientException $e) {
         $response = $e->getResponse();
         $body = $response->getBody()->getContents();
         $message = $e->getMessage();
         try {
             $data = Json::decode($body);
             $message = implode(', ', $data->errors);
         } catch (JsonException $e) {
             //ignore
         }
         $ex = new ClientException($message, $e->getCode(), $e);
         $ex->setBody($body);
         throw $ex;
     }
 }
开发者ID:billduapp,项目名称:opencart-plugin,代码行数:32,代码来源:WrappedClient.php


示例16: request

 private function request($req, $args = [])
 {
     $args = $args + ['api_key' => $this->apiKey, 'api_username' => $this->apiUsername];
     $url = self::DOMAIN . "{$req}?" . http_build_query($args);
     $raw = file_get_contents($url);
     return Json::decode($raw, Json::FORCE_ARRAY);
 }
开发者ID:VasekPurchart,项目名称:khanovaskola-v3,代码行数:7,代码来源:Discourse.php


示例17: updateAddon

 private function updateAddon(ActiveRow $addon)
 {
     $this->writeln('Updating: ' . $addon->name);
     $github = $this->normalizeGithubUrl($addon->repository);
     if ($github) {
         $guzzle = new \Guzzle\Http\Client();
         try {
             $guzzle->get($github)->send();
             $this->db->table('addons_resources')->insert(array('addonId' => $addon->id, 'type' => 'github', 'resource' => $github));
         } catch (\Guzzle\Http\Exception\RequestException $e) {
             $this->writeln((string) $e);
         }
     }
     if ($addon->type === 'composer') {
         $version = $addon->related('versions')->order('id', 'DESC')->fetch();
         $composerData = Json::decode($version->composerJson);
         $packagist = $this->generatePackagistUrl($composerData->name);
         $guzzle = new \Guzzle\Http\Client();
         try {
             $guzzle->get($packagist . '.json')->send();
             $this->db->table('addons_resources')->insert(array('addonId' => $addon->id, 'type' => 'packagist', 'resource' => $packagist));
         } catch (\Guzzle\Http\Exception\RequestException $e) {
             $this->writeln((string) $e);
         }
     }
     if ($addon->demo) {
         $guzzle = new \Guzzle\Http\Client();
         try {
             $guzzle->get($addon->demo)->send();
             $this->db->table('addons_resources')->insert(array('addonId' => $addon->id, 'type' => 'demo', 'resource' => $addon->demo));
         } catch (\Guzzle\Http\Exception\RequestException $e) {
             $this->writeln((string) $e);
         }
     }
 }
开发者ID:newPOPE,项目名称:web-addons.nette.org,代码行数:35,代码来源:ResourcesPresenter.php


示例18: call

 /**
  * @param string $method
  * @param string $endpoint
  * @param array $data
  *
  * @return \Kdyby\Curl\Response|NULL
  */
 private function call($method, $endpoint, $data = [])
 {
     $request = $this->createRequest($endpoint);
     $data = Json::encode($data);
     try {
         if ($method === Request::GET) {
             $response = $request->get($data);
         } else {
             $request->post = $data;
             $request->setMethod($method);
             $response = $request->send();
         }
     } catch (CurlException $e) {
         if ($e instanceof BadStatusException) {
             $response = $e->getResponse();
             if ($response->getCode() !== 404) {
                 Debugger::log($e);
                 return NULL;
             }
         } else {
             throw $e;
         }
     }
     return $response;
 }
开发者ID:jedenweb,项目名称:mailchimp,代码行数:32,代码来源:Mailchimp.php


示例19: onUpload

 public function onUpload(Form $form)
 {
     /** @var UploadControl[] $form */
     /** @var FileUpload $json */
     /** @var FileUpload $audio */
     $json = $form['json']->getValue();
     $audio = $form['audio']->getValue();
     $data = Json::decode($json->getContents(), Json::FORCE_ARRAY);
     $blackboard = new Rme\Blackboard();
     $this->orm->contents->attach($blackboard);
     $blackboard->title = 'Nová nahrávka';
     $blackboard->description = ' ';
     $blackboard->hidden = TRUE;
     $blackboard->duration = $data['duration'];
     $blackboard->preview = 'https://placehold.it/480x320&text=...';
     $blackboard->author = $this->userEntity;
     $this->orm->flush();
     $base = $this->paths->getBlackboards() . "/{$blackboard->id}";
     $json->move("{$base}.json");
     $audio->move("{$base}.wav");
     $producer = $this->queue->getProducer('blackboardPreview');
     $producer->publish(serialize(['blackboard' => new EntityPointer($blackboard)]));
     $link = $this->link('BlackboardEditor:default', ['blackboardId' => $blackboard->id]);
     $this->sendJson(['redirect' => $link]);
 }
开发者ID:VasekPurchart,项目名称:khanovaskola-v3,代码行数:25,代码来源:BlackboardEditor.php


示例20: __construct

 public function __construct($domain, $apiKey = NULL, $apiSecret = NULL)
 {
     $this->domain = $domain;
     $this->apiKey = $apiKey;
     $this->apiSecret = $apiSecret;
     $config = ['base_url' => $domain];
     $curl = new Client($config);
     $curl->onBeforeRequest[] = function (Curl\Request $request) {
         $data = $request->getData();
         $timestamp = time();
         $toSign = $data;
         $toSign['timestamp'] = (int) $timestamp;
         $toSign['apiKey'] = $this->apiKey;
         ksort($toSign);
         $json = \Nette\Utils\Json::encode($toSign);
         $signature = base64_encode(hash_hmac('sha512', $json, $this->apiSecret, $raw = TRUE));
         $request->setQuery('apiKey', $this->apiKey);
         $request->setQuery('timestamp', $timestamp);
         $request->setQuery('signature', $signature);
     };
     $curl->onBeforeResponse[] = function ($response) {
         return ResponseParser::parse($response);
     };
     $this->clients = new Clients($curl);
     $this->products = new Products($curl);
     $this->orders = new Orders($curl);
     $this->invoices = new Invoices($curl);
 }
开发者ID:billduapp,项目名称:opencart-plugin,代码行数:28,代码来源:ApiClient.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Utils\LimitedScope类代码示例发布时间:2022-05-23
下一篇:
PHP Utils\Html类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap