예제 #1
0
    public function testAddRootSettingDoesNotBreakDots()
    {
        $manipulator = new JsonManipulator('{
    "github-oauth": {
        "github.com": "foo"
    }
}');
        $this->assertTrue($manipulator->addSubNode('github-oauth', 'bar', 'baz'));
        $this->assertEquals('{
    "github-oauth": {
        "github.com": "foo",
        "bar": "baz"
    }
}
', $manipulator->getContents());
    }
예제 #2
0
 protected function updateFileCleanly(JsonFile $json, array $base, array $new, $requireKey, $removeKey, $sortPackages)
 {
     $extra = $this->extra;
     $contents = file_get_contents($json->getPath());
     $manipulator = new JsonManipulator($contents);
     foreach ($new as $package => $constraint) {
         if (!$manipulator->addLink($requireKey, $package, $constraint, $sortPackages)) {
             return false;
         }
         if (!$manipulator->removeSubNode($removeKey, $package)) {
             return false;
         }
     }
     if (isset($extra['installer-modules']) && is_array($extra['installer-modules'])) {
         $manipulator->addSubNode('extra', 'installer-modules', $extra['installer-modules']);
     }
     $paths = $this->getComposer()->getPackage()->getExtra();
     $paths = $paths['installer-paths'];
     if (isset($extra['installer-paths']) && is_array($extra['installer-paths'])) {
         foreach ($extra['installer-paths'] as $path => $list) {
             if (!is_array($list)) {
                 continue;
             }
             if (isset($paths[$path])) {
                 $result = array_merge($paths[$path], $list);
                 $result = array_keys(array_flip($result));
                 $paths[$path] = $result;
             } else {
                 $paths[$path] = $list;
             }
         }
     }
     if (isset($extra['system-modules']) && is_array($extra['system-modules'])) {
         $modules = $extra['system-modules'];
         foreach ($modules as &$module) {
             if (strpos($module, '/') === false) {
                 $module = 'opis-colibri/' . $module;
             }
         }
         $path = 'system/modules/{$name}/';
         if (isset($paths[$path])) {
             $result = array_merge($paths[$path], $modules);
             $result = array_keys(array_flip($result));
             $paths[$path] = $result;
         }
     }
     $manipulator->addSubNode('extra', 'installer-paths', $paths);
     file_put_contents($json->getPath(), $manipulator->getContents());
     return true;
 }