Ensure a proper PHP version has been set in composer.json.

@param array $composerJson The contents of the composer.json.

@return bool
339765
public function validatePhpVersionComposerJson($composerJson)
    {
        if (!isset($composerJson['require']['php'])) {
            $this->output->writeln(
                '<info>No PHP version mentioned in composer.json!</info>'
            );

            return true;
        }

        $versionParser = new VersionParser();
        try {
            $versionParser->parseConstraints($composerJson['require']['php']);
        } catch (\Exception $e) {
            $this->output->writeln('<error>' . $e->getMessage() . '</error>');

            return false;
        }

        return true;
    }
1338742
public function validatePhpVersionAgainstTravis($composerJson, $travisYml)
    {
        if (empty($composerJson['require']['php'])) {
            return true;
        }

        $versionParser       = new VersionParser();
        $constraintsComposer = $versionParser->parseConstraints($composerJson['require']['php']);

        foreach (!empty($travisYml['php']) ? $travisYml['php'] : array() as $version) {
            if ('nightly' === $version) {
                continue;
            }

            // Travis only allows major.minor specification.
            $constraintsTravis = $versionParser->parseConstraints($version . '.9999999.9999999');
            if (!$constraintsComposer->matches($constraintsTravis)) {
                $this->output->writeln(
                    sprintf(
                        '<error>composer.json "%s" does not match travis.yml "%s". ' .
                        'Please remove "%s" from .travis.yml</error>',
                        $constraintsComposer->getPrettyString(),
                        $version,
                        $version
                    )
                );

                return false;
            }
        }

        return true;
    }
926349
protected function getPackageNameByComposerJson($projectName)
    {
        $file = $this->cwd.'/'.$this->projectsDir.'/'.$projectName.'/composer.json';
        if (!file_exists($file)) {
            return;
        }

        $json = json_decode(file_get_contents($file));
        if (!isset($json->name) || !$this->isPackageName($json->name)) {
            return;
        }

        return $json->name;
    }
183869
public function getVersion()
  {
    $composerJson = config('app.dir') . 'composer.json';

    if (file_exists($composerJson)) {
      $composer = json_decode(file_get_contents($composerJson, true));

      $version  = isset($composer->version) ? $composer->version : '1';
      $require  = isset($composer->require) ? (array)$composer->require : false;

      if (!is_array($require)) return "{$version} (1)";

      if (isset($require['modulusphp/framework'])) {
        return $version . " ({$require['modulusphp/framework']})";
      } else {
        return "{$version} (1)";
      }
    }

    return '1';
  }
505080
public static function create(array $json)
    {
        $setTagsResponse = new SetTagsResponse();
        $setTagsResponse->setStatusCode($json['status_code']);
        $setTagsResponse->setStatusMessage($json['status_message']);

        return $setTagsResponse;
    }
402192
public function isValid($json=null) {
			if (empty($json) || ctype_space($json)) return false;
			json_decode($json);
			return (json_last_error() === JSON_ERROR_NONE);
		}
133527
public function supportsNativeJson()
    {
        if ($this->_supportsNativeJson !== null) {
            return $this->_supportsNativeJson;
        }

        if ($this->_version === null) {
            $this->_version = $this->_connection->getAttribute(PDO::ATTR_SERVER_VERSION);
        }

        return $this->_supportsNativeJson = version_compare($this->_version, '5.7.0', '>=');
    }
367374
public static function isJson($value): bool
    {
        if (!static::isStringCastable($value)) {
            return false;
        }

        if (((string) $value) === 'null') {
            return true;
        }

        return (json_decode((string) $value) !== null && json_last_error() === JSON_ERROR_NONE);
    }
329339
private function setJsonDefaults(array $json)
    {
        $config = $this->app['config'];
        $pathResolver = $this->app['path_resolver'];

        $rootPath = $pathResolver->resolve('root');
        $extensionsPath = $pathResolver->resolve('extensions');
        $webPath = $pathResolver->resolve('web');
        $pathToRoot = Path::makeRelative($rootPath, $extensionsPath);
        $pathToWeb = Path::makeRelative($webPath, $extensionsPath);
        $pathToListeners = Path::makeRelative(__DIR__ . '/EventListener', $extensionsPath);
        /** @deprecated Handle BC on 'stability' key until 4.0 */
        $minimumStability = $config->get('general/extensions/stability') ?: $config->get('general/extensions/composer/minimum-stability', 'stable');

        $config = $config->get('general/extensions/composer/config', []) + [
            'discard-changes'   => true,
            'preferred-install' => 'dist',
        ];

        // Enforce standard settings
        $defaults = [
            'name'         => 'bolt/extensions',
            'description'  => 'Bolt extension installation interface',
            'license'      => 'MIT',
            'repositories' => [
                'packagist' => false,
                'bolt'      => [
                    'type' => 'composer',
                    'url'  => $this->app['extend.site'] . 'satis/',
                ],
            ],
            'minimum-stability' => $minimumStability,
            'prefer-stable'     => true,
            'config'            => $config,
            'provide'           => [
                'bolt/bolt' => Bolt\Version::forComposer(),
            ],
            'extra' => [
                'bolt-web-path'  => $pathToWeb,
                'bolt-root-path' => $pathToRoot,
            ],
            'autoload' => [
                'psr-4' => [
                    'Bolt\\Composer\\EventListener\\' => $pathToListeners,
                ],
            ],
            'scripts' => [
                'post-autoload-dump'   => 'Bolt\\Composer\\EventListener\\PackageEventListener::dump',
                'post-package-install' => 'Bolt\\Composer\\EventListener\\PackageEventListener::handle',
                'post-package-update'  => 'Bolt\\Composer\\EventListener\\PackageEventListener::handle',
            ],
        ];
        $json = Arr::replaceRecursive($json, $defaults);
        ksort($json);

        return $json;
    }
743438
public function dontSeeResponseContainsJson($json = [])
    {
        $jsonResponseArray = new JsonArray($this->connectionModule->_getResponseContent());
        $this->assertFalse(
            $jsonResponseArray->containsArray($json),
            "Response JSON contains provided JSON\n"
            . "- <info>" . var_export($json, true) . "</info>\n"
            . "+ " . var_export($jsonResponseArray->toArray(), true)
        );
    }
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;
    }
1185232
public function parseJson($json)
    {
        $this->mentionName = $json['mention_name'];
        $this->id = $json['id'];
        $this->name = $json['name'];
        if (isset($json['links'])) {
            $this->links = $json['links'];
        }
        if(isset($json['xmpp_jid'])) {
            $this->xmppJid = $json['xmpp_jid'];
            $this->deleted = $json['is_deleted'];
            $this->lastActive = $json['last_active'];
            $this->title = $json['title'];
            $this->created = new \Datetime($json['created']);
            $this->groupAdmin = $json['is_group_admin'];
            $this->timezone = $json['timezone'];
            $this->guest = $json['is_guest'];
            $this->email = $json['email'];
            $this->photoUrl = $json['photo_url'];
        }
    }
281858
public static function createFromComposerJson(array $composerJson)
    {
        $class = new self();
        $class->type = $composerJson['type'];
        $class->name = $composerJson['name'];
        $class->description = isset($composerJson['description']) ? $composerJson['description'] : '';
        $class->version = isset($composerJson['version']) ? $composerJson['version'] : 'local';
        $class->authors = isset($composerJson['authors']) ? $composerJson['authors'] : [];
        $class->keywords = isset($composerJson['keywords']) ? $composerJson['keywords'] : [];
        $class->constraint = isset($composerJson['require']['bolt/bolt']) ? $composerJson['require']['bolt/bolt'] : '0.0.0';

        return $class;
    }
241438
public static function acceptJson()
    {
        $accept = self::getService('HTTP_ACCEPT');
        if (false !== strpos($accept, 'json') || false !== strpos($accept, 'javascript')) {
            return true;
        }
        return false;
    }
140621
public static function validateHookConfig(array $json) : void
    {
        if (!self::keysExist(['enabled', 'actions'], $json)) {
            throw new \RuntimeException('Config error: invalid hook configuration');
        }
        if (!is_array($json['actions'])) {
            throw new \RuntimeException('Config error: \'actions\' must be an array');
        }
        self::validateActionsConfig($json['actions']);
    }
590691
private function updateComposerReplacesVersion($version, array $component)
    {
        $composer = $this->rootPath() .'/composer.json';
        if (!file_exists($composer)) {
            throw new \Exception('Invalid composer.json path');
        }

        $data = json_decode(file_get_contents($composer), true);

        $data['replace'][$component['name']] = $version;

        file_put_contents($composer, json_encode($data, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES));
    }
862605
public function wantsJson(): bool
    {
        $acceptable = $this->serverRequest->getHeaderLine('Accept');

        return $acceptable !== null && Strings::contains($acceptable, ['/json', '+json']);
    }