Exemplo n.º 1
0
 /**
  * Fixes the config escaped values and sets them on the json builder.
  *
  * @param array $config The config.
  */
 protected function fixConfigEscapedValues(array $config)
 {
     if (isset($config['protectedSource'])) {
         foreach ($config['protectedSource'] as $key => $value) {
             $this->jsonBuilder->setValue(sprintf('[protectedSource][%s]', $key), $value, false);
         }
     }
     $escapedValueKeys = array('stylesheetParser_skipSelectors', 'stylesheetParser_validSelectors');
     foreach ($escapedValueKeys as $escapedValueKey) {
         if (isset($config[$escapedValueKey])) {
             $this->jsonBuilder->setValue(sprintf('[%s]', $escapedValueKey), $config[$escapedValueKey], false);
         }
     }
 }
/**
 * Converts data to JSON and writes/appends this to specified filename.
 *
 * @param string $filename Name of file to write to.
 * @param mixed $data Data to write to file.
 */
function writeToFile($filename, $data)
{
    $builder = new JsonBuilder();
    $builder->setJsonEncodeOptions(JSON_UNESCAPED_SLASHES);
    $builder->setValues($data);
    $json = $builder->build();
    file_put_contents($filename, $json . PHP_EOL, FILE_APPEND);
}
Exemplo n.º 3
0
 /**
  * Asserts the json builder default state.
  */
 protected function assertDefaultState()
 {
     $this->assertSame(0, $this->jsonBuilder->getJsonEncodeOptions());
     $this->assertFalse($this->jsonBuilder->hasValues());
     $this->assertEmpty($this->jsonBuilder->getValues());
 }
Exemplo n.º 4
0
<?php

require_once __DIR__ . "/vendor/autoload.php";
use Symfony\Component\Finder\Finder;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Filesystem\Exception\IOExceptionInterface;
use PhpParser\Parser;
use PhpParser\NodeTraverser;
use PhpParser\Lexer;
use PhpParser\NodeVisitor;
use Ivory\JsonBuilder;
$builder = new JsonBuilder\JsonBuilder();
$finder = new Finder();
$fs = new Filesystem();
$sourcePath = $argv[1];
$targetPath = $argv[2];
$finder->files()->in($sourcePath)->name('*.php');
$start = time();
foreach ($finder as $file) {
    $hintVisitor = new PhpCodeHints\HintVisitor();
    $parser = new Parser(new PhpParser\Lexer());
    $traverser = new NodeTraverser();
    $traverser->addVisitor(new NodeVisitor\NameResolver());
    $traverser->addVisitor($hintVisitor);
    $code = $file->getContents();
    try {
        $stmts = $parser->parse($code);
        $stmts = $traverser->traverse($stmts);
        $jsonContent = "";
        $builder->setJsonEncodeOptions(JSON_PRETTY_PRINT);
        $builder->setValues($hintVisitor->fileStmts);