Create a new matcher package from composer.json

@param string $composerJson composer.json path

@throws \expect\package\ComposerJsonNotFoundException
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);
    }
638442
protected function updateComposerJson($type)
    {
        // If the generated package is a Module.
        if ($type == 'module') {
            $namespace = 'Modules\\';

            $directory = 'modules/';
        }

        // If the generated package is a Theme.
        else if ($type == 'theme') {
            $namespace = 'Themes\\';

            $directory = 'themes/';
        }

        // Standard processing for the Packages.
        else {
            $namespace = $this->data['namespace'] .'\\';

            $directory = 'packages/' . $this->data['name'] . "/src/";
        }

        $composerJson = getenv('COMPOSER') ?: 'composer.json';

        $path = base_path($composerJson);

        // Get the composer.json contents in a decoded form.
        $config = json_decode(file_get_contents($path), true);

        if (! is_array($config)) {
            return;
        }

        // Update the composer.json
        else if (! Arr::has($config, "autoload.psr-4.$namespace")) {
            Arr::set($config, "autoload.psr-4.$namespace", $directory);

            $output = json_encode($config, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . "\n";

            file_put_contents($path, $output);
        }
    }
764487
public static function createFromJson(string $json): self
    {
        $data = \json_decode($json, true);
        if (!\is_array($data)) {
            throw new InvalidArgumentException('Invalid argument.');
        }

        return self::createFromKeyData($data);
    }
1264277
public static function create(array $json)
    {
        $pushStatResponse = new PushStatResponse();
        $pushStatResponse->setStatusCode($json['status_code']);
        $pushStatResponse->setStatusMessage($json['status_message']);

        return $pushStatResponse;
    }
186328
public static function fromJson($json)
    {
        $responseData = json_decode($json, true);

        if (! $responseData) {
            return new Response(false, ['invalid-json']);
        }

        if (isset($responseData['success']) && $responseData['success'] == true) {
            return new Response(true);
        }

        if (isset($responseData['error-codes']) && is_array($responseData['error-codes'])) {
            return new Response(false, $responseData['error-codes']);
        }

        return new Response(false);
    }
626445
protected function saveComposerJson($composerJson)
    {
        $newComposerJson = json_encode(
            $composerJson,
            JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES
        );

        $composerJsonPath = $this->getComposerJsonPath();
        if (File::put($composerJsonPath, $newComposerJson) === false) {
            throw new RuntimeException("Cannot write to composer.json [$composerJsonPath]");
        }
    }
220206
public static function set_Json( $json, $inputValidate )
    {
        if( $json instanceof Json ) {
            return $json;
        } elseif( null === $json ) {
            return null;
        } elseif ( !is_string($json) ) {
            return Json::makeFromObject( $json );
        }

        return new Json( $json, $inputValidate );
    }
8225
private function updateComposerJson(JsonFile $jsonFile, array $package, $isPostInstall)
    {
        $composerJson = $jsonFile->parse();

        $sortPackages = $this->getOptions()->sortPackages();
        $requireKey = $this->getOptions()->dev() ? 'require-dev' : 'require';
        $removeKey = $this->getOptions()->dev() ? 'require' : 'require-dev';
        $baseRequirements = array_key_exists($requireKey, $composerJson) ? $composerJson[$requireKey] : [];

        if (!$this->updateFileCleanly($jsonFile, $package, $requireKey, $removeKey, $sortPackages, $isPostInstall)) {
            foreach ($package as $name => $version) {
                $baseRequirements[$name] = $version;

                if (isset($composerJson[$removeKey][$name])) {
                    unset($composerJson[$removeKey][$name]);
                }
            }

            $composerJson[$requireKey] = $baseRequirements;
            $jsonFile->dump($composerJson);
        }
    }
1333527
protected function loadComposerJson()
    {
        $composerJsonPath = $this->getComposerJsonPath();

        if (! File::exists($composerJsonPath)) {
            throw new FileNotFoundException('composer.json does not exist');
        }

        $composerJsonContent = File::get($composerJsonPath);
        $composerJson = json_decode($composerJsonContent, true);

        if (! is_array($composerJson)) {
            throw new RuntimeException("Invalid composer.json file [$composerJsonPath]");
        }

        return $composerJson;
    }
1094218
public function execute($packages, $onlyname = true)
    {
        /** @var \Composer\Composer $composer */
        $composer = $this->getComposer();
        $io = $this->getIO();

        $platformRepo = new PlatformRepository();

        if ($composer) {
            $localRepo = $composer->getRepositoryManager()->getLocalRepository();
            $installedRepo = new CompositeRepository([$localRepo, $platformRepo]);
            $repos = new CompositeRepository(array_merge([$installedRepo], $composer->getRepositoryManager()->getRepositories()));
        } else {
            $defaultRepos = RepositoryFactory::defaultRepos($io);

            //No composer.json found in the current directory, showing packages from local repo
            $installedRepo = $platformRepo;
            $repos = new CompositeRepository(array_merge([$installedRepo], $defaultRepos));
        }

        $flags = $onlyname ? RepositoryInterface::SEARCH_NAME : RepositoryInterface::SEARCH_FULLTEXT;

        try {
            return $repos->search(implode(' ', $packages), $flags);
        } catch (\Exception $e) {
            $msg = sprintf('%s received an error from Composer: %s in %s::%s', __METHOD__, $e->getMessage(), $e->getFile(), $e->getLine());
            $this->app['logger.system']->critical($msg, ['event' => 'exception', 'exception' => $e]);

            throw new PackageManagerException($e->getMessage(), $e->getCode(), $e);
        }
    }
1206089
public static function getJson()
    {
        if (!static::$json) {
            $root = Ioc::getConfig()->get('path.root');
            $file = realpath($root . '/composer.json');

            static::$json = new Structure(is_file($file) ? file_get_contents($file) : null);
        }

        return static::$json;
    }
953992
public function getPackageJsonFile($package)
    {
        // We get the project vendor path
        $vendorPath = $this->getVendorPath();
        // We get the target dir of the iterated package
        $targetDir = $package->getTarget();
        $jsonPath = $vendorPath . $targetDir . "/composer.json";
        if (method_exists($package, 'getJsonFile')) {
            $jsonFile = $package->getJsonFile($jsonPath);
        } else {
            // @codeCoverageIgnoreStart
            $jsonFile = new JsonFile($jsonPath);
            // @codeCoverageIgnoreEnd
        }

        return $this->fs->exists($jsonPath) ? $jsonFile->read() : null;
    }
340597
public static function create(array $json)
    {
        $createTargetedMessageResponse = new CreateTargetedMessageResponse();
        $createTargetedMessageResponse->setStatusCode($json['status_code']);
        $createTargetedMessageResponse->setStatusMessage($json['status_message']);
    
        // If a 'response' is provided
        if (array_key_exists('response', $json) && isset($json['response'])) {
            $createTargetedMessageResponseResponse = new CreateTargetedMessageResponseResponse();
    
            // If 'messageCode' is provided
            if (array_key_exists('messageCode', $json['response'])) {
                $createTargetedMessageResponseResponse->setMessageCode($json['response']['messageCode']);
            }
    
            $createTargetedMessageResponse->setResponse($createTargetedMessageResponseResponse);
        }
    
        return $createTargetedMessageResponse;
    }
1289133
private function setup()
    {
        if ($this->started) {
            return;
        }

        if ($this->app['extend.writeable']) {
            // Do required JSON update/set up
            try {
                $this->updateJson();
            } catch (ParseException $e) {
                $this->app['logger.flash']->danger(Trans::__('Error reading extensions/composer.json file: %ERROR%', ['%ERROR%' => $e->getMessage()]));
                $this->started = false;

                return;
            }
        }

        $this->started = true;
    }
1084615
public static function validateJsonConfiguration(array $json) : void
    {
        foreach (HookUtil::getValidHooks() as $hook => $class) {
            if (isset($json[$hook])) {
                self::validateHookConfig($json[$hook]);
            }
        }
    }
469084
public static function createFromJsonString(string $json): BunqModel
    {
        $responseArray = ModelUtil::deserializeResponseArray($json);

        return static::createFromResponseArray($responseArray);
    }
1177950
public static function create(array $json)
    {
        $getTagsResponse = new GetTagsResponse();
        $getTagsResponse->setStatusCode($json['status_code']);
        $getTagsResponse->setStatusMessage($json['status_message']);

        // If a 'response' is provided
        if (array_key_exists('response', $json) && isset($json['response'])) {
            $getTagsResponseResponse = new GetTagsResponseResponse();

            // If a 'result' is provided
            if (array_key_exists('result', $json['response'])) {
                $getTagsResponseResponse->setResult($json['response']['result']);
            }

            $getTagsResponse->setResponse($getTagsResponseResponse);
        }

        return $getTagsResponse;
    }