Exemple #1
0
 /**
  * @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;
 }
Exemple #2
0
 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);
     }
 }
 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;
 }
 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;
     }
 }
 /**
  * @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');
 }
Exemple #6
0
 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;
 }
Exemple #7
0
 /**
  * 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;
 }
Exemple #8
0
 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);
 }
Exemple #9
0
 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;
 }
Exemple #10
0
 /**
  * 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;
 }
Exemple #11
0
 /**
  * @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 />&nbsp;&nbsp;&nbsp;&nbsp;"four":4,<br />&nbsp;&nbsp;&nbsp;&nbsp;"foo":[<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3<br />&nbsp;&nbsp;&nbsp;&nbsp;]<br />}';
     $this->assertEquals($targetHtmlOutput, Zend_Json::prettyPrint($jsonstr, array('format' => 'html')));
 }
<?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) {
    }
}
// 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);
Exemple #14
0
 /**
  * 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;
 }
Exemple #15
0
 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;
 }
Exemple #16
0
/**
 * @see df_xml_prettify()
 * @param string $value
 * @return string
 */
function df_json_prettify($value)
{
    return Zend_Json::prettyPrint(df_t()->adjustCyrillicInJson($value));
}
 /**
  * @param $objectBrick
  * @return string
  */
 public static function generateObjectBrickJson($objectBrick)
 {
     unset($objectBrick->key);
     unset($objectBrick->fieldDefinitions);
     // set classname attribute to the real class name not to the class ID
     // this will allow to import the brick on a different instance with identical class names but different class IDs
     if (is_array($objectBrick->classDefinitions)) {
         foreach ($objectBrick->classDefinitions as &$cd) {
             $class = Object\ClassDefinition::getById($cd["classname"]);
             if ($class) {
                 $cd["classname"] = $class->getName();
             }
         }
     }
     $json = \Zend_Json::encode($objectBrick);
     $json = \Zend_Json::prettyPrint($json);
     return $json;
 }
 public function rulerdenomAction()
 {
     if ($this->_getParam('term', false)) {
         $denominations = new Denominations();
         $data = $denominations->getRomanRulerDenom($this->_getParam('term'));
         if ($data) {
             $response = $data;
         } else {
             $response = array(array('id' => NULL, 'term' => 'No options available'));
         }
     } else {
         $response = array(array('id' => NULL, 'term' => 'No ruler specified'));
     }
     $data = Zend_Json::encode($response);
     echo Zend_Json::prettyPrint($data, array("indent" => " ", 'format' => 'html'));
 }
    /**
     * Returns a serialized string for the passed data structure based on type
     * @param array $array
     * @param string $type
     * @return string
     * @static
     */
    public static function encode($array, $type)
    {
        if ($type == self::JSON || $type == self::JAVASCRIPT || $type == self::ANYTHING) {
            require_once 'Zend/Json.php';
            return Zend_Json::encode($array);
        }

        if ($type == self::JSON_READABLE) {
            require_once 'Zend/Json.php';
            return Zend_Json::prettyPrint(Zend_Json::encode($array), array("indent" => "  "));
        }

        if ($type == self::XML) {
            return 'XML not yet implemented, sorry, come again';
        }

        if ($type == self::URL_ENCODE) {
            return 'Url encoded format not yet implemented';
        }

        return false;
    }
Exemple #20
0
 /**
  * Outputs the reflection - can be to the command line or a file
  * or a directory.
  *
  * @param string $infile
  * @param object $reflection 
  * @return void
  */
 protected function _outputReflectionFile($infile, $reflection)
 {
     // May need Vonnegut_Output_Json and Vonnegut_Output_Otherformat classes
     // in the future.
     if ($this->_format == 'json') {
         $json = Zend_Json::encode($reflection);
         $output = $this->_pretty ? Zend_Json::prettyPrint($json) : $json;
         if ($this->_outputPath) {
             if ($this->_singleFile) {
                 $filepath = $this->_outputPath;
             } else {
                 $filename = str_replace(DIRECTORY_SEPARATOR, '_', $infile);
                 $filepath = $this->_outputPath . DIRECTORY_SEPARATOR . $filename . '.json';
             }
             $this->log("Writing {$filepath}");
             $file = fopen($filepath, 'w');
             $rote = fwrite($file, $output);
             if ($rote === false) {
                 $this->log("Could not write {$filename}", Vonnegut_Cli::LOG_LEVEL_WARN);
             }
         } else {
             $this->log($output, Vonnegut_Cli::LOG_LEVEL_CRITICAL);
         }
     }
 }