Set up Composer JSON file.

@return array|null
961132
public function update()
    {
        /** @var \Bolt\Filesystem\Handler\JsonFile $jsonFile */
        $jsonFile = $this->app['filesystem']->get('extensions://composer.json', new JsonFile());

        if (!$jsonFile->exists()) {
            try {
                $this->init('extensions://composer.json');
            } catch (IOException $e) {
                $this->messages[] = Trans::__('page.extend.error-composer-json-not-readable');

                $this->app['extend.writeable'] = false;
                $this->app['extend.online'] = false;

                return null;
            }
        }

        $json = $jsonOrig = $jsonFile->parse();

        // Workaround Bolt 2.0 installs with "require": []
        if (isset($json['require']) && empty($json['require'])) {
            unset($json['require']);
        }

        $json = $this->setJsonDefaults($json);

        // Write out the file, but only if it's actually changed, and if it's writable.
        if ($json != $jsonOrig) {
            try {
                $jsonFile->dump($json);
            } catch (IOException $e) {
                $this->messages[] = Trans::__('page.extend.error-composer-json-not-writable');
            }
        }

        return $json;
    }
933213
protected function addThemeRepositoryToRootComposer()
    {
        $composer = json_decode(file_get_contents(base_path('composer.json')), true);

        $composer['repositories'][] = [
            'type' => 'path',
            'url' => './'.$this->relativeThemePath(),
        ];

        file_put_contents(
            base_path('composer.json'),
            json_encode($composer, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
        );
    }
981696
public function writeComposerJson($contents) {
    // Ensure that require and require-dev are objects and not arrays.
    if (array_key_exists('require', $contents) && is_array($contents['require'])) {
      ksort($contents['require']);
      $contents['require'] = (object) $contents['require'];
    }
    if (array_key_exists('require-dev', $contents)&& is_array($contents['require-dev'])) {
      ksort($contents['require-dev']);
      $contents['require-dev'] = (object) $contents['require-dev'];
    }
    file_put_contents($this->composerJsonFilepath, json_encode($contents, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
  }
823071
final protected static function initialJSON()
    {
        $base = __DIR__."/../../";
        $f = json_decode(file_get_contents($base."/elements/config_files/core/framework.config.json"));
        $f->installation = new \DateTime();
        $f->location = realpath($base);
        $f->default_env = "dev";
        $rs = json_encode($f, JSON_PRETTY_PRINT);
        file_put_contents($base."/elements/config_files/core/framework.config.json", $rs);
    }
237775
public function jsonSerialize()
    {
        $properties = [
            '_templatePath', '_template', '_plugin', '_theme', '_layout', '_autoLayout',
            '_layoutPath', '_name', '_className', '_options', '_helpers'
        ];

        $array = [];

        foreach ($properties as $property) {
            $array[$property] = $this->{$property};
        }

        return array_filter($array, function ($i) {
            return !is_array($i) && strlen($i) || !empty($i);
        });
    }
468672
final protected function initialJSON()
    {
        $file = json_decode(file_get_contents(FEnvFcm::get("framework.config.core.config.file")));
        if (isset($file->installation) && $file->installation == null) {
            $file->installation = new \DateTime();
            $file->default_env =  "dev";
            $file->location = realpath(__DIR__."../../../../../../../../").DIRECTORY_SEPARATOR;
            $result = json_encode($file, JSON_PRETTY_PRINT);
            file_put_contents(FEnvFcm::get("framework.config.core.config.file"), $result);
        }
    }
555487
private function load()
    {
        $decoder = new JsonDecoder();
        $decoder->setObjectDecoding(JsonDecoder::ASSOC_ARRAY);

        $this->json = file_exists($this->path)
            ? $decoder->decodeFile($this->path)
            : array();
    }
230446
public function setup($args)
    {
        if(count($args) < 2) {
            Index::error('Not enough arguments.', 'Usage: eve generate <schema> <namespace>');
        }

        $this->name = $args[1];

        if(isset($args[2])) {
            $this->namespace = $args[2];
        } else {


            if(file_exists($this->cwd.'/composer.json')) {
                $json = $this('file', $this->cwd.'/composer.json')->getContent();
                $json = json_decode($json, true);

                if(isset($json['autoload']['psr-4'])
                    && is_array($json['autoload']['psr-4'])
                ) {
                    foreach($json['autoload']['psr-4'] as $namespace => $path) {
                        if(strlen($path) === 0) {
                            $this->namespace = substr($namespace, 0, -1);
                            break;
                        }
                    }
                }
            }

            if(!$this->namespace) {
                $this->namespace = '';
                //$this->namespace = explode('/', $this->cwd);
                //$this->namespace = array_pop($this->namespace);
                //$this->namespace = ucwords($this->namespace);
            }

            Index::warning('No namespace provided.');
        }

        $file = $this->cwd.'/schema/'.$this->name.'.php';

        if(!file_exists($file)) {
            $file = $this->cwd.'/'.$this->name.'.php';

            if(!file_exists($file)) {
                Index::error('Cannot find /' . $this->name . '.php');
            }
        }

        $this->schema = include($file);

        if(!is_array($this->schema)) {
            Index::error('Schema is invalid.');
        }

        return $this;
    }
1348123
public function loadNamespaces()
    {
        $data       = json_decode(file_get_contents(base_path('composer.json')), JSON_OBJECT_AS_ARRAY);
        $namespaces = array_get($data, 'autoload.psr-4');
        $this->setNamespaces($namespaces);
        return $this;
    }
765525
public function json($file = null) : Json
    {
        if ($file === null) {
            $file = 'module.json';
        }

        return Arr::get($this->moduleJson, $file, function () use ($file) {
            return $this->moduleJson[$file] = new Json($this->getPath() . '/' . $file, $this->app['files']);
        });
    }
354445
public function jsonSerialize()
    {
        return array(
            self::METADATA_SOURCE   => $this->metadataSource,
            self::TEMPLATE_VARIABLE => $this->templateVariable,
            self::FILES             => $this->getFiles(),
            self::DIRECTORIES       => $this->directories,
            self::NAME              => $this->name,
            self::ENVIRONNEMENT     => $this->environnement,
            self::DEPENDENCIES      => $this->dependencies,
            self::DTO               => $this->dto,
        );
    }
903703
public static function getComposerJsonDecoded(string $path = null): array
    {
        $path     = $path ?? self::getProjectRootDirectory() . '/composer.json';
        $contents = (string)\file_get_contents($path);
        if ('' === $contents) {
            throw new \RuntimeException('composer.json is empty');
        }
        $decoded = \json_decode($contents, true);
        if (JSON_ERROR_NONE !== \json_last_error()) {
            throw new \RuntimeException('Failed loading composer.json: ' . \json_last_error_msg());
        }

        return $decoded;
    }
1298140
public function getComposerJSON()
    {
        if (!$this->composerJsonLoaded && !$this->composerJson) {
            $this->composerJsonLoaded = true;
            $this->composerJson = null;
            $jsonFile = new JsonFile(__DIR__ . '/composer.json');
            if ($jsonFile->exists()) {
                $this->composerJson = $jsonFile->read();
            }
        }

        return $this->composerJson;
    }
345625
public static function fromPackageFile($composerJson)
    {
        if (file_exists($composerJson) === false) {
            throw new ComposerJsonNotFoundException("File {$composerJson} not found.");
        }

        $config = Config::load($composerJson);
        $autoload = $config->get('autoload.psr-4');

        $composerJsonDirectory = dirname($composerJson);

        $keys = array_keys($autoload);
        $namespace = array_shift($keys);

        $values = array_values($autoload);
        $namespaceDirectory = array_shift($values);
        $namespaceDirectory = realpath($composerJsonDirectory . '/' . $namespaceDirectory);

        return new self($namespace, $namespaceDirectory);
    }
59643
private function _jaxonSetup()
    {
        if(($this->bSetupCalled))
        {
            return;
        }

        $jaxon = jaxon();
        $sentry = $jaxon->sentry();
        // Use the Composer autoloader. It's important to call this before triggers and callbacks.
        $jaxon->useComposerAutoloader();

        // Set this object as the Armada in the DI container.
        // Now it will be returned by a call to jaxon()->armada().
        if(get_class($this) != 'Jaxon\\Armada\\Armada')
        {
            Container::getInstance()->setArmada($this);
        }

        // Event before setting up the module
        $sentry->triggerEvent('pre.setup');

        // Setup the Sentry library
        $sentry->setup();

        // Set the module/package/bundle specific specific options
        $this->jaxonSetup();

        // Event before the module has set the config
        $sentry->triggerEvent('pre.config');

        // Jaxon application settings
        $sentry->setClassNamespaces($this->appConfig);

        // Save the view namespaces
        $sentry->setViewNamespaces($this->appConfig);

        // Event after the module has read the config
        $sentry->triggerEvent('post.config');

        // Event before checking the module
        $sentry->triggerEvent('pre.check');

        $this->jaxonCheck();

        // Event after checking the module
        $sentry->triggerEvent('post.check');

        // Event after setting up the module
        $sentry->triggerEvent('post.setup');

        $this->bSetupCalled = true;
    }
314612
private function syncComposerLockFile()
    {
        $composerJsonFileContents = file_get_contents($this->projectDir.'/composer.json');
        $composerLockFileContents = json_decode(file_get_contents($this->projectDir.'/composer.lock'), true);

        if (array_key_exists('hash', $composerLockFileContents)) {
            $composerLockFileContents['hash'] = md5($composerJsonFileContents);
        }

        if (array_key_exists('content-hash', $composerLockFileContents)) {
            $composerLockFileContents['content-hash'] = $this->getComposerContentHash($composerJsonFileContents);
        }

        $this->fs->dumpFile($this->projectDir.'/composer.lock', json_encode($composerLockFileContents, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)."\n");
    }
1233096
private function load()
    {
        $decoder = new JsonDecoder();
        $decoder->setObjectDecoding(JsonDecoder::ASSOC_ARRAY);

        $this->json = file_exists($this->path)
            ? $decoder->decodeFile($this->path)
            : array();

        if (!isset($this->json['keysByTypeName'])) {
            $this->json['keysByTypeName'] = array();
            $this->json['typesByKey'] = array();
            $this->json['bindingsByKey'] = array();
            $this->json['nextKey'] = 0;
        }
    }