本文整理汇总了PHP中Nette\Utils\Json::encode方法的典型用法代码示例。如果您正苦于以下问题:PHP Json::encode方法的具体用法?PHP Json::encode怎么用?PHP Json::encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Utils\Json
的用法示例。
在下文中一共展示了Json::encode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: __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);
}
示例3: 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;
}
示例4: encode
/**
* Returns the JSON representation of a value.
* @param mixed
* @return string
*/
public static function encode($value, $pretty = self::FORMAT_COMPACT)
{
if ($pretty === self::FORMAT_COMPACT) {
return Nette\Utils\Json::encode($value);
}
return self::prettify(Nette\Utils\Json::encode($value), $value);
}
示例5: getControl
/**
* Generates control's HTML element
*
* @return Html
*/
public function getControl()
{
$control = parent::getControl()->addClass('pswdinput');
$this->data['fid'] = $this->getForm()->getElementPrototype()->id;
$control->data('lohini-pswd', \Nette\Utils\Json::encode(array_filter($this->data)));
return Html::el('span', ['style' => 'position: relative; float: left;'])->add($control);
}
示例6: 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)));
}
示例7: __construct
public function __construct(OAuth\Consumer $consumer, Http\Url $url, $method = self::GET, array $post = [], array $headers = [], OAuth\Token $token = NULL)
{
$this->consumer = $consumer;
$this->token = $token;
$this->url = $url;
$this->method = strtoupper($method);
$this->headers = $headers;
if (is_array($post) && !empty($post)) {
$this->post = array_map(function ($value) {
if ($value instanceof Http\UrlScript) {
return (string) $value;
} elseif ($value instanceof \CURLFile) {
return $value;
}
return !is_string($value) ? Utils\Json::encode($value) : $value;
}, $post);
}
$parameters = $this->getParameters();
$defaults = ['oauth_version' => OAuth\DI\OAuthExtension::VERSION, 'oauth_nonce' => $this->generateNonce(), 'oauth_timestamp' => $this->generateTimestamp(), 'oauth_consumer_key' => $this->consumer->getKey()];
if ($token && $token->getToken()) {
$defaults['oauth_token'] = $this->token->getToken();
}
// Update query parameters
$this->url->setQuery(array_merge($defaults, $parameters));
}
示例8: loadConfiguration
public function loadConfiguration()
{
$builder = $this->getContainerBuilder();
$config = $this->getConfig($this->defaults);
$helperClasses = array('Symfony\\Component\\Console\\Helper\\FormatterHelper', 'Symfony\\Component\\Console\\Helper\\QuestionHelper', 'Kdyby\\Console\\Helpers\\PresenterHelper');
$helperClasses = array_map(function ($class) {
return new Nette\DI\Statement($class);
}, $helperClasses);
if (class_exists('Symfony\\Component\\Console\\Helper\\ProgressHelper')) {
$helperClasses[] = new Nette\DI\Statement('Symfony\\Component\\Console\\Helper\\ProgressHelper', array(false));
}
if (class_exists('Symfony\\Component\\Console\\Helper\\DialogHelper')) {
$helperClasses[] = new Nette\DI\Statement('Symfony\\Component\\Console\\Helper\\DialogHelper', array(false));
}
$builder->addDefinition($this->prefix('helperSet'))->setClass('Symfony\\Component\\Console\\Helper\\HelperSet', array($helperClasses))->setInject(FALSE);
$builder->addDefinition($this->prefix('application'))->setClass('Kdyby\\Console\\Application', array($config['name'], $config['version']))->addSetup('setHelperSet', array($this->prefix('@helperSet')))->addSetup('injectServiceLocator')->setInject(FALSE);
$builder->addDefinition($this->prefix('dicHelper'))->setClass('Kdyby\\Console\\ContainerHelper')->addTag(self::TAG_HELPER, 'dic');
if ($config['disabled']) {
return;
}
$builder->addDefinition($this->prefix('router'))->setClass('Kdyby\\Console\\CliRouter')->setAutowired(FALSE)->setInject(FALSE);
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::TAG_COMMAND);
}
}
示例9: 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);
}
}
示例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);
}
示例11: 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();
}
}
示例12: stringify
/**
* Convert array or Traversable input to string output response
* @param array|\Traversable $data
* @param bool $prettyPrint
* @return mixed
*
* @throws MappingException
*/
public function stringify($data, $prettyPrint = TRUE)
{
try {
return Json::encode($data, $prettyPrint && defined('Nette\\Utils\\Json::PRETTY') ? Json::PRETTY : 0);
} catch (JsonException $e) {
throw new MappingException('Error in parsing response: ' . $e->getMessage());
}
}
示例13: renderJavascript
/**
* @param Flot\Plot $plot
* @return string
*/
public function renderJavascript(Flot\Plot $plot)
{
$args = array();
$args[] = Utils\Json::encode('#' . $plot->getName());
$args[] = Utils\Json::encode($this->exportData($plot));
$args[] = Utils\Json::encode($this->exportOptions($plot));
return sprintf(self::PLOT_METHOD, implode(', ', $args));
}
示例14: send
/**
* @param Http\IRequest $request
* @param Http\IResponse $response
*/
public function send(Http\IRequest $request, Http\IResponse $response)
{
$response->setContentType($this->contentType);
$response->setCode($this->code ?: Http\IResponse::S200_OK);
$response->setExpiration($this->expiration);
$response->setHeader('Pragma', $this->expiration ? 'cache' : 'no-cache');
echo Json::encode($this->data);
}
示例15: preSend
/**
* {@inheritDoc}
*/
public function preSend(RequestInterface $request)
{
$content = $request->getContent();
if (is_array($content) || $content instanceof \JsonSerializable) {
$request->setContent(Json::encode($content));
$request->addHeader('Content-Type: application/json');
}
}