本文整理汇总了PHP中Zend_Json::prettyPrint方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Json::prettyPrint方法的具体用法?PHP Zend_Json::prettyPrint怎么用?PHP Zend_Json::prettyPrint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Json
的用法示例。
在下文中一共展示了Zend_Json::prettyPrint方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getRecursiveAsJson
/**
* @param string $directory
* @param boolean $prettyPrint
*/
public static function getRecursiveAsJson($directory, $prettyPrint = false)
{
$json = \Zend_Json::encode(self::getRecursive($directory));
if ($prettyPrint) {
return \Zend_Json::prettyPrint($json, array("indent" => " "));
}
return $json;
}
示例2: json
public static function json($data, $format = 'plain')
{
if ($format == 'pretty') {
$message = Zend_Json::encode($data);
return Zend_Json::prettyPrint($message, array("format" => "html"));
} else {
return Zend_Json::encode($data);
}
}
示例3: __toString
public function __toString()
{
$str = parent::__toString();
if ($this->_entity) {
$str .= "\nEntity: " . $this->_entity;
}
if (!empty($this->_validationErrors)) {
$str .= "\nValidation errors:\n" . \Zend_Json::prettyPrint(\Zend_Json::encode($this->_validationErrors), array("indent" => " "));
}
return $str;
}
示例4: deleteAction
public function deleteAction()
{
$this->_helper->viewRenderer->setNoRender();
if ($this->_request->isPost()) {
$paramId = $this->getParam('id');
$mdlPages = new Model_Admin($paramId);
$deletePage = $mdlPages->deletePage();
$json = Zend_Json::encode($deletePage);
echo Zend_Json::prettyPrint($json);
die;
}
}
示例5: uploadException
/**
* @param \Exception $e
*/
public function uploadException(\Exception $e)
{
$arrE = (array) $e;
$previous = array();
while (method_exists($e, 'getPrevious') && $e->getPrevious() && ($e = $e->getPrevious())) {
$previous[] = array("message" => $e->getMessage(), "trace" => $e->getTraceAsString());
}
while (!method_exists($e, 'getPrevious') && $e->_previous && ($e = $e->_previous)) {
$previous[] = array("message" => $e->getMessage(), "trace" => $e->getTraceAsString());
}
$arrE = $this->objectToArray($arrE, 3);
$arrE["previous"] = $previous;
$serialized = \Zend_Json::prettyPrint(\Zend_Json::encode($arrE));
return $this->_debugLogUploader->uploadString('exception', $serialized, 'text/plain');
}
示例6: find
function find($id)
{
$info = array();
if ($this->rech_db) {
$info = $this->find_db($id);
} else {
$info = $this->find_salesforce($id);
}
if (isset($info['UnitPrice'])) {
/* Formatage de prix */
$prix = $info['UnitPrice'];
$info['UnitPrice'] = $this->montant($prix);
$info['UnitPrice_ttc'] = $this->montant_ttc($prix);
}
$info['pdf'] = Zend_Json::prettyPrint(Zend_Json::encode($info));
return $info;
}
示例7: render
/**
* Render a Zend_Config into a JSON config string.
*
* @since 1.10
* @return string
*/
public function render()
{
$data = $this->_config->toArray();
$sectionName = $this->_config->getSectionName();
$extends = $this->_config->getExtends();
if (is_string($sectionName)) {
$data = array($sectionName => $data);
}
foreach ($extends as $section => $parent_section) {
$data[$section][ZendL_Config_Json::EXTENDS_NAME] = $parent_section;
}
$out = Zend_Json::encode($data);
if ($this->_prettyPrint) {
$out = Zend_Json::prettyPrint($out);
}
return $out;
}
示例8: postDispatch
public function postDispatch()
{
$data = $this->View()->getAssign();
$pretty = $this->Request()->getParam('pretty', false);
array_walk_recursive($data, function (&$value) {
// Convert DateTime instances to ISO-8601 Strings
if ($value instanceof DateTime) {
$value = $value->format(DateTime::ISO8601);
}
});
$data = Zend_Json::encode($data);
if ($pretty) {
$data = Zend_Json::prettyPrint($data);
}
$this->response()->setHeader('Content-type', 'application/json', true);
$this->response()->setBody($data);
}
示例9: _toHtml
public function _toHtml()
{
$output = '<table>';
foreach ($this->log->_data as $key => $value) {
if ($this->isJson($value)) {
$value = '<pre>' . Zend_Json::prettyPrint($value) . '</pre>';
} elseif ($this->isSerializedArray($value)) {
$value_lines = unserialize($value);
$value_output = '';
foreach ($value_lines as $key => $line) {
$value_output .= sprintf('<tr><td>%s</td><td>%s</td></tr>', $key, $line);
}
$value = '<table>' . $value_output . '</table>';
} else {
$value = '<pre>' . $value . '</pre>';
}
$output .= sprintf('<tr><th>%s</th><td>%s</td></tr>', $key, $value);
}
$output .= '</table>';
echo $output;
}
示例10: direct
/**
* Prepare the JSON, send it, and exit the application.
*
* @param mixed $data
*/
public function direct($data)
{
$response = $this->getResponse();
$request = $this->getRequest();
$response->setHeader('Content-Type', 'application/json', true);
// Add header data for JSONP requests.
if (isset($_GET['callback'])) {
$response->setHeader('Content-Type', 'application/javascript', true);
$headers = array('status' => $response->getHttpResponseCode());
$data = array('headers' => $headers, 'data' => $data);
}
$json = Zend_Json::encode($data);
// Pretty print the JSON if requested.
if (isset($_GET['pretty_print'])) {
$json = Zend_Json::prettyPrint($json);
}
// Wrap the JSON with a callback function if requested.
if (isset($_GET['callback'])) {
$json = $_GET['callback'] . "({$json});";
}
$response->setBody($json);
$response->sendResponse();
exit;
}
示例11: testJsonPrettyPrintWorksWithHtmlOutputFormat
/**
* @group ZF-9577
*/
public function testJsonPrettyPrintWorksWithHtmlOutputFormat()
{
$o = new stdClass();
$o->four = 4;
$o->foo = array(1, 2, 3);
$jsonstr = Zend_Json::encode($o);
$targetHtmlOutput = '{<br /> "four":4,<br /> "foo":[<br /> 1,<br /> 2,<br /> 3<br /> ]<br />}';
$this->assertEquals($targetHtmlOutput, Zend_Json::prettyPrint($jsonstr, array('format' => 'html')));
}
示例12: mkdir
<?php
\Pimcore\Cache::disable();
$customCacheFile = PIMCORE_CONFIGURATION_DIRECTORY . "/cache.xml";
// create legacy config folder
$legacyFolder = PIMCORE_CONFIGURATION_DIRECTORY . "/LEGACY";
if (!is_dir($legacyFolder)) {
mkdir($legacyFolder, 0777, true);
}
if (file_exists($customCacheFile)) {
try {
$conf = new \Zend_Config_Xml($customCacheFile);
$arrayConf = $conf->toArray();
$content = json_encode($arrayConf);
$content = \Zend_Json::prettyPrint($content);
$jsonFile = \Pimcore\Config::locateConfigFile("cache.json");
file_put_contents($jsonFile, $content);
rename($customCacheFile, $legacyFolder . "/cache.xml");
} catch (\Exception $e) {
}
}
示例13: foreach
// layouts
$classType = 'Block';
$layouts = $utilityFiles->getLayoutFiles([], false);
foreach ($layouts as $file) {
$xml = simplexml_load_file($file);
$classes = \Magento\Framework\App\Utility\Classes::collectLayoutClasses($xml);
$factoryNames = array_filter($classes, 'isFactoryName');
if (!$factoryNames) {
continue;
}
foreach ($factoryNames as $factoryName) {
list($module, $name) = getModuleName($factoryName, $compositeModules);
$map[$classType][$factoryName] = getClassName($module, $classType, $name);
}
}
echo Zend_Json::prettyPrint(Zend_Json::encode($map));
/**
* Get combined array from similar files by pattern
*
* @param string $dirPath
* @param string $filePattern
* @return array
*/
function getFilesCombinedArray($dirPath, $filePattern)
{
$result = [];
$directoryIterator = new DirectoryIterator($dirPath);
$patternIterator = new RegexIterator($directoryIterator, $filePattern);
foreach ($patternIterator as $fileInfo) {
$arrayFromFile = (include_once $fileInfo->getPathname());
$result = array_merge($result, $arrayFromFile);
示例14: render
/**
* Render a Zend_Config into a JSON config string.
*
* @since 1.10
* @return string
*/
public function render()
{
$data = $this->_config->toArray();
$sectionName = $this->_config->getSectionName();
$extends = $this->_config->getExtends();
if (is_string($sectionName)) {
$data = array($sectionName => $data);
}
foreach ($extends as $section => $parentSection) {
$data[$section][Zend_Config_Json::EXTENDS_NAME] = $parentSection;
}
// Ensure that each "extends" section actually exists
foreach ($data as $section => $sectionData) {
if (is_array($sectionData) && isset($sectionData[Zend_Config_Json::EXTENDS_NAME])) {
$sectionExtends = $sectionData[Zend_Config_Json::EXTENDS_NAME];
if (!isset($data[$sectionExtends])) {
// Remove "extends" declaration if section does not exist
unset($data[$section][Zend_Config_Json::EXTENDS_NAME]);
}
}
}
$out = Zend_Json::encode($data);
if ($this->prettyPrint()) {
$out = Zend_Json::prettyPrint($out);
}
return $out;
}
示例15: exportCustomLayoutDefinitionAction
public function exportCustomLayoutDefinitionAction()
{
$this->removeViewRenderer();
$id = intval($this->getParam("id"));
if ($id) {
$customLayout = Object\ClassDefinition\CustomLayout::getById($id);
if ($customLayout) {
$name = $customLayout->getName();
unset($customLayout->id);
unset($customLayout->classId);
unset($customLayout->name);
unset($customLayout->creationDate);
unset($customLayout->modificationDate);
unset($customLayout->userOwner);
unset($customLayout->userModification);
unset($customLayout->fieldDefinitions);
header("Content-type: application/json");
header("Content-Disposition: attachment; filename=\"custom_definition_" . $name . "_export.json\"");
$json = json_encode($customLayout);
$json = \Zend_Json::prettyPrint($json);
echo $json;
die;
}
}
$errorMessage = ": Custom Layout with id [ " . $id . " not found. ]";
Logger::error($errorMessage);
echo $errorMessage;
}