public static function writeData($file, $data)
 {
     $jsonPretty = new JsonPretty();
     $data = $jsonPretty->prettify($data);
     if (!file_put_contents($file, $data)) {
         return false;
     }
 }
Пример #2
0
 /**
  * For PHP 5.3 from php >= 5.4* use parameter JSON_PRETTY_PRINT.
  * See {@link http://www.php.net/manual/en/function.json-encode.php}.
  *
  * @param mixed $value
  *
  * @return string
  */
 public static function encode($value)
 {
     if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
         return json_encode($value, JSON_PRETTY_PRINT);
     }
     $jsonPretty = new JsonPretty();
     return $jsonPretty->prettify($value, null, '    ');
 }
Пример #3
0
 /**
  * We can't user JsonResponse here, because
  * it improperly encodes the data array
  *
  * @return Response
  */
 public function manifestAction()
 {
     $data = array('start_url' => '/', 'gcm_sender_id' => '446150739532', 'gcm_user_visible_only' => true);
     // @deprecated: Drop when pushing minimum php version to 5.4
     if (version_compare(PHP_VERSION, '5.4', '<')) {
         $jsonPretty = new JsonPretty();
         $data = $jsonPretty->prettify($data);
     } else {
         $data = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
     }
     return new Response($data, 200, array('Content-Type' => 'application/json'));
 }
Пример #4
0
 /**
  * Encodes an array to json strutcture
  * @param  array   $data        Data to encode
  * @param  boolean $prettyPrint True to output the encoded data a little bit more readable for the humans
  * @return string
  */
 public static function encode($data, $prettyPrint = false)
 {
     if ($prettyPrint) {
         // Check if the PHP version is >= 5.4 and has the JSON_PRETTY_PRINT constant
         if (version_compare(PHP_VERSION, '5.4.0', '>=') && defined('JSON_PRETTY_PRINT')) {
             return json_encode($data, JSON_PRETTY_PRINT);
         } else {
             $jsonPretty = new JsonPretty();
             return $jsonPretty->prettify($data, null, '    ');
         }
     }
     return json_encode($data);
 }
Пример #5
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $options = $input->getOptions();
     $theme = $options['theme'];
     $savePhpConfig = $options['save-php-config'];
     $themePath = realpath($this->getContainer()->get('mautic.factory')->getSystemPath('themes') . '/' . $theme);
     if (empty($themePath)) {
         $output->writeln("\n\n<error>The specified theme ({$theme}) does not exist.</error>");
         return 1;
     }
     $jsonConfigPath = $themePath . '/config.json';
     if (file_exists($jsonConfigPath)) {
         $output->writeln("\n\n<error>The specified theme ({$theme}) already has a JSON config file.");
         return 1;
     }
     $configPath = $themePath . '/config.php';
     if (!file_exists($configPath)) {
         $output->writeln("\n\n<error>The php config file for the specified theme ({$theme}) could not be found.</error>");
         return 1;
     }
     $config = (include $configPath);
     if (!is_array($config) || !array_key_exists('name', $config)) {
         $output->writeln("\n\n<error>The php config file for the specified theme ({$theme}) is not a valid config file.</error>");
         return 1;
     }
     // @deprecated: Drop when pushing minimum php version to 5.4
     if (version_compare(PHP_VERSION, '5.4', '<')) {
         $jsonPretty = new JsonPretty();
         $jsonConfig = $jsonPretty->prettify($config);
     } else {
         $jsonConfig = json_encode($config, JSON_PRETTY_PRINT);
     }
     if (!file_put_contents($jsonConfigPath, $jsonConfig)) {
         $output->writeln("\n\n<error>Error writing json config file for the specified theme ({$theme}).</error>");
         return 1;
     } else {
         $output->writeln("\n\n<info>Successfully wrote json config file for the specified theme ({$theme}).</info>");
     }
     if (!$savePhpConfig) {
         if (!unlink($configPath)) {
             $output->writeln("\n\n<error>Error deleting php config file for the specified theme ({$theme}).</error>");
         } else {
             $output->writeln("\n\n<info>PHP config file for theme ({$theme}) has been deleted.</info>");
         }
     } else {
         $output->writeln("\n\n<info>PHP config file for theme ({$theme}) was preserved.</info>");
     }
     return 0;
 }
Пример #6
0
#!/usr/bin/php -q
<?php 
define('URL_TIENDAS', 'http://cms-rewards.starbucks.mx/cms/xml/tiendas.xml');
require 'vendor/autoload.php';
use Camspiers\JsonPretty\JsonPretty;
use MarkWilson\XmlToJson\XmlToJsonConverter;
$tiendas = file_get_contents(URL_TIENDAS);
$xml = new SimpleXMLElement($tiendas);
$converter = new XmlToJsonConverter();
$jsonTiendas = $converter->convert($xml);
$jsonPretty = new JsonPretty();
file_put_contents('tiendas.json', $jsonPretty->prettify($jsonTiendas));
echo 'Listo, actualizado en "tiendas.json"' . PHP_EOL;
Пример #7
0
 /**
  * {@inheritdoc}
  */
 public function write($file = null)
 {
     $jsonPretty = new JsonPretty();
     $output = $jsonPretty->prettify($this->data);
     file_put_contents($file ? $file : $this->file, $output);
 }
Пример #8
0
{
    if (($handle = fopen($file, 'r')) !== FALSE) {
        $i = 0;
        while (($lineArray = fgetcsv($handle, 4000, $delimiter, '"')) !== FALSE) {
            for ($j = 0; $j < count($lineArray); $j++) {
                $arr[$i][$j] = $lineArray[$j];
            }
            $i++;
        }
        fclose($handle);
    }
    return $arr;
}
$data = csvToArray($feed, ',');
$count = count($data) - 1;
$labels = array_shift($data);
foreach ($labels as $label) {
    $keys[] = $label;
}
$keys[] = 'id';
for ($i = 0; $i < $count; $i++) {
    $data[$i][] = $i;
}
for ($j = 0; $j < $count; $j++) {
    $d = array_combine($keys, $data[$j]);
    $newArray[$j] = $d;
}
$verificentrosJson = array();
$verificentrosJson['verificentros'] = $newArray;
$jsonPretty = new JsonPretty();
file_put_contents('verificentros.json', $jsonPretty->prettify(json_encode($verificentrosJson)));
Пример #9
0
 protected function updateJsonContentInFile($path, \stdClass $content)
 {
     array_unshift($content->_readme, '------------------------------------------------------------------');
     array_unshift($content->_readme, 'ATTENTION: This file has been changed by silpion/composer-checker.');
     array_unshift($content->_readme, '------------------------------------------------------------------');
     // Write new content to same file
     $jsonPretty = new JsonPretty();
     file_put_contents($path, $jsonPretty->prettify($content));
     $this->output->writeln('<info>Updated file.</info>');
 }
Пример #10
0
 /**
  * Destructor. Will write app config to file
  * to keep configuration persistent across app
  * runs.
  *
  * @todo throw a warning when file is not writable.
  */
 public function __destruct()
 {
     $configurationFile = $this->configurationFile();
     if (is_writable($this->getBaseDir()) && (!file_exists($configurationFile) or is_writable($configurationFile))) {
         $jsonPretty = new JsonPretty();
         $json = $jsonPretty->prettify($this->getArrayCopy());
         file_put_contents($configurationFile, $json);
     }
 }
Пример #11
0
 /**
  * @return string
  * @throws ConnectorException
  */
 public function getPrettyData()
 {
     $jsonPretty = new JsonPretty();
     return $jsonPretty->prettify($this->getParsedData());
 }