Пример #1
0
 /**
  * Dumps the state of Configure data into an json string.
  */
 public function dump($filename, $data)
 {
     $runtime = array('routes' => '', 'controller_properties' => '', 'model_properties' => '');
     if (isset($data['Hook'])) {
         $data['Hook'] = array_diff_key($data['Hook'], $runtime);
     }
     $options = 0;
     if (version_compare(PHP_VERSION, '5.3.3', '>=')) {
         $options |= JSON_NUMERIC_CHECK;
     }
     if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
         $options |= JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT;
     }
     $contents = CroogoJson::stringify($data, $options);
     return $this->_writeFile($this->_path . $filename, $contents);
 }
Пример #2
0
    /**
     * testStringify
     */
    public function testStringify()
    {
        $options = 0;
        if (version_compare(PHP_VERSION, '5.3.3', '>=')) {
            $options |= JSON_NUMERIC_CHECK;
        }
        if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
            $options |= JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT;
        }
        $data = array('foo' => 'bar', 'spam' => 'eggs');
        $expected = <<<END
{
\\s+"foo": "bar",
\\s+"spam": "eggs"
}
END;
        $result = CroogoJson::stringify($data, $options);
        $this->assertRegExp($expected, $result);
        $data = array('name' => 'rchavik/sites', 'install_count' => 10, 'numeric_list' => array(1, 2, 3), 'nested' => array('hello' => 'world', 'value' => 20), 'combination' => array('spam', 'eggs', 'hello' => 'world'));
        $expected = <<<END
{
\\s+"name": "rchavik\\/sites",
\\s+"install_count": 10,
\\s+"numeric_list": \\[
\\s+1,
\\s+2,
\\s+3
\\s+\\],
\\s+"nested": {
\\s+"hello": "world",
\\s+"value": 20
\\s+},
\\s+"combination": {
\\s+"0": "spam",
\\s+"1": "eggs",
\\s+"hello": "world"
\\s+}
}
END;
        $result = CroogoJson::stringify($data, $options);
        $this->assertRegExp($expected, $result);
    }
Пример #3
0
 /**
  * setConfig
  *
  * @param array $requires
  * @return boolean
  */
 public function setConfig($requires = array())
 {
     $filename = 'composer.json';
     if (file_exists($this->appPath . $filename)) {
         $file = new File($this->appPath . $filename);
         $json = json_decode($file->read(), true);
     } else {
         $file = new File($this->appPath . $filename, true);
         $json = array();
     }
     if (!isset($json['minimum-stability'])) {
         $json['minimum-stability'] = 'dev';
     }
     if (!isset($json['config']['vendor-dir'])) {
         $json['config']['vendor-dir'] = 'Vendor';
     }
     if (!isset($json['config']['bin-dir'])) {
         $json['config']['bin-dir'] = 'Vendor/bin';
     }
     if (!isset($json['require'])) {
         $json['require'] = array('composer/installers' => '*');
     }
     foreach ($requires as $pkg => $ver) {
         if (strpos($ver, '/') !== false) {
             $pkg = $ver;
             $ver = '*';
         }
         $json['require'][$pkg] = $ver;
     }
     $options = 0;
     if (version_compare(PHP_VERSION, '5.3.3', '>=')) {
         $options |= JSON_NUMERIC_CHECK;
     }
     if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
         $options |= JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT;
     }
     $json = CroogoJson::stringify($json, $options) . "\n";
     $file->write($json);
     $file->close();
     return true;
 }