Parse composer.json

@return self Returns itself

@throws Exception on error
345832
protected function loadComposerFile() {
        $composerFile = $this->config['appDir'] . '/composer.json';

        if (!is_readable($composerFile)) {
            throw new Exception(sprintf(
                'Composer file "%s" is missing or not readable',
                $composerFile
            ), ExitApp::RUNTIME_ERROR);
        }

        $this->config['composer'] = JSONFile::read($composerFile);

        if (!array_key_exists('extra', $this->config['composer']) ||
            !is_array($this->config['composer']['extra'])) {
            throw new Exception(sprintf(
                'Missing "extra" in composer file "%s"',
                $composerFile
            ), ExitApp::RUNTIME_ERROR);
        }

        $keys = [
            'name',
            'version'
        ];

        foreach ($keys as $key) {
            if (!array_key_exists($key, $this->config['composer']['extra'])) {
                throw new Exception(sprintf(
                    'Missing "extra.%s" in composer file "%s"',
                    $key,
                    $composerFile
                ), ExitApp::RUNTIME_ERROR);
            }
        }

        return $this;
    }
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);
    }
1278878
public function GetComposer() {

		$filepath = "{$this->ProjectRoot}/composer.json";

		try { $composer = new Nether\Project\Composer($filepath); }
		catch(Exception $e) {
			$this->ShowMessage($e->getMessage());
			exit(0);
		}

		return $composer;
	}
886672
public function getComposerJsonFile() : string
    {
        $json_file = base_path('composer.json');

        if ($this->isJsonFile($json_file) === false) {
            // Notifica o sistema para não efetuar a ofuscação
            $this->getObfuscator()->addErrorMessage("Json file is invalid");
            $this->stop();
        }

        return $json_file;
    }
1064248
function Composer () {
  this.p = {
    product: 'Unknown',
    productVersion: 'Unknown',
    os: os.type(),
    osVersion: os.release(),
    platform: '',
    exts: []
  }
}
1265218
private function setupJson()
    {
        $this->io->title('Creating/updating composer.json');
        $this->app['extend.manager.json']->update();
        $this->io->success('Success');
    }
450153
public function parseAutoloads()
    {
        /** @var Composer $composer */
        $composer = $this->composer;

        /** @var Package $package */
        $package = $composer->getPackage();
        if (!$package) {
            return;
        }

        $exclude = $this->getExcludedFiles($package);

        if (!$exclude) {
            return;
        }

        $filesystem = new Filesystem();
        $config     = $composer->getConfig();
        $vendorPath = $filesystem->normalizePath(realpath(realpath($config->get('vendor-dir'))));
        $exclude    = $this->parseExcludedFiles($exclude, $vendorPath);

        $generator  = $composer->getAutoloadGenerator();
        $packages   = $composer->getRepositoryManager()->getLocalRepository()->getCanonicalPackages();
        $packageMap = $generator->buildPackageMap($composer->getInstallationManager(), $package, $packages);

        $this->filterAutoloads($packageMap, $package, $exclude);
    }
933236
protected function setComposerJson() {
    if (file_exists($this->getConfigValue('repo.root') . '/composer.json')) {
      $composer_json = json_decode(file_get_contents($this->getConfigValue('repo.root') . '/composer.json'), TRUE);
      $this->composerJson = $composer_json;

      return $composer_json;
    }

    return [];
  }
347435
protected function getJsonFromResponse(Response $response)
    {
        $responseBody = $response->getBody();
        if ($response->getStatusCode() >= 400) {
            throw new Exception($responseBody);
        }
        $json = @json_decode($responseBody, true);
        if ($json === null) {
            throw new Exception('Failed to decode CommunityTranslation response');
        }

        return $json;
    }
17209
public function jsonSerialize()
    {
        $payload = self::getDefaultPayloadStructure();

        if ($this->alert instanceof Alert || is_string($this->alert)) {
            $payload[self::PAYLOAD_ROOT_KEY][self::PAYLOAD_ALERT_KEY] = $this->alert;
        }

        if (is_int($this->badge)) {
            $payload[self::PAYLOAD_ROOT_KEY][self::PAYLOAD_BADGE_KEY] = $this->badge;
        }

        if (is_string($this->sound)) {
            $payload[self::PAYLOAD_ROOT_KEY][self::PAYLOAD_SOUND_KEY] = $this->sound;
        }

        if (is_bool($this->contentAvailable)) {
            $payload[self::PAYLOAD_ROOT_KEY][self::PAYLOAD_CONTENT_AVAILABLE_KEY] = (int)$this->contentAvailable;
        }

        if (is_bool($this->mutableContent)) {
            $payload[self::PAYLOAD_ROOT_KEY][self::PAYLOAD_MUTABLE_CONTENT_KEY] = (int)$this->mutableContent;
        }

        if (is_string($this->category)) {
            $payload[self::PAYLOAD_ROOT_KEY][self::PAYLOAD_CATEGORY_KEY] = $this->category;
        }

        if (is_string($this->threadId)) {
            $payload[self::PAYLOAD_ROOT_KEY][self::PAYLOAD_THREAD_ID_KEY] = $this->threadId;
        }

        if (is_countable($this->customValues) && count($this->customValues)) {
            $payload = array_merge($payload, $this->customValues);
        }

        return $payload;
    }
812279
private function getComposer(): string
    {
        $filePath = $this->app->basePath('composer.json');

        if (! File::exists($filePath)) {
            $this->app->abort(400, 'The file composer.json not found');
        }

        return File::get($filePath);
    }
1176062
private function loadComposerConfiguration() : array
    {
        $contents = file_get_contents($this->root . '/composer.json');
        $config = json_decode($contents, true);

        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new RuntimeException(json_last_error_msg());
        }

        return $config;
    }
309971
public function parseJsonResponse(): self
    {
        $jsonResponse = $this->_response;
        if (!is_array($jsonResponse)) {
            throw new RuntimeException('Response must be a scalar value');
        }

        if (array_key_exists('quantity', $jsonResponse)) {
            $this->_quantity = $jsonResponse['quantity'];
        }

        if (array_key_exists('receiptId', $jsonResponse)) {
            $this->_transaction_id = $jsonResponse['receiptId'];
        }

        if (array_key_exists('productId', $jsonResponse)) {
            $this->_product_id = $jsonResponse['productId'];
        }

        if (array_key_exists('purchaseDate', $jsonResponse) && !empty($jsonResponse['purchaseDate'])) {
            $this->_purchase_date = Carbon::createFromTimestampUTC(intval(round($jsonResponse['purchaseDate'] / 1000)));
        }

        if (array_key_exists('cancelDate', $jsonResponse) && !empty($jsonResponse['cancelDate'])) {
            $this->_cancellation_date = Carbon::createFromTimestampUTC(
                intval(round($jsonResponse['cancelDate'] / 1000))
            );
        }

        if (array_key_exists('renewalDate', $jsonResponse) && !empty($jsonResponse['renewalDate'])) {
            $this->_renewal_date = Carbon::createFromTimestampUTC(intval(round($jsonResponse['renewalDate'] / 1000)));
        }

        return $this;
    }
159481
public static function Parse(){
            $oThis = self::CreateInstanceIfNotExists();
            $sRoot = str_replace(array("index.php", " "), array("", "%20"), $_SERVER["SCRIPT_NAME"]);//Bugfix
            $sUri = ($sRoot != "/") ? str_replace($sRoot, "", $_SERVER["REQUEST_URI"]) : substr($_SERVER["REQUEST_URI"], 1, strlen($_SERVER["REQUEST_URI"])-1);
            $aParsedRoute = explode("/", $sUri);
            $mID = (array_key_exists(1, $aParsedRoute)) ? $aParsedRoute[1] : null;
            $sMethod = $oThis->Restful();  
            $oThis->RestParams();

            if(!$oThis->bOverloadFrontend){
                $bResult = Bootstrap::AutoLoad(((!empty($aParsedRoute[0]) && $aParsedRoute[0] != "/" ) ? strtolower(str_replace("@", "", $aParsedRoute[0])) : "main"));

                if(!$bResult)
                    Bootstrap::AutoLoad("main");
            }
            
            $sUri = preg_replace("/\?.*$/", "", $sUri);//Removendo path
            $sUri = preg_replace("/\#.*$/", "", $sUri);//Removendo path
            $bCall = false;

            $aIdent = array("int" => "\d+", "str" => "\w+", "flt" => "[\d.]+");

            foreach($oThis->aRoutes as $sRoute => $fFunc){  
                if (preg_match_all('/{(?P<field>\w+)(:((?P<type>\w{3,3})|regex\((?P<regex>.*)\)))?(:(?P<notnull>notnull))?}/i',$sRoute, $aMatches)){
                    if (preg_match('/(?P<pre>.*\w)\/\{/i',$sRoute, $aMatch)){
                        $sOk = str_replace('/', '\/', $aMatch['pre']);
                        $sRoute = str_replace($aMatch['pre'], $sOk, $sRoute);
                    } 
                    foreach ($aMatches['field'] as $iKey => $sValue) {
                        if ($aMatches['regex'][$iKey]){
                            if ($aMatches['notnull'][$iKey] == 'notnull'){
                                $sRoute = preg_replace('/\/{'.$aMatches['field'][$iKey].':regex('.$aMatches['regex'][$iKey].'):notnull}/i',"\/(".$aMatches['regex'][$iKey].")", $sRoute);
                            }else{
                                $sRoute = preg_replace('/\/{'.$aMatches['field'][$iKey].':regex('.$aMatches['regex'][$iKey].')}/i',"\/?(".$aMatches['regex'][$iKey].")?", $sRoute);                                                                                
                            }
                        }else{
                            if ($aMatches['type'][$iKey]){ 
                                if ($aMatches['notnull'][$iKey] == 'notnull'){
                                    $sRoute = preg_replace('/\/{'.$aMatches['field'][$iKey].':'.$aMatches['type'][$iKey].':notnull}/i',"\/(".$aIdent[$aMatches['type'][$iKey]].")", $sRoute);                                        
                                }else{
                                    $sRoute = preg_replace('/\/?{'.$aMatches['field'][$iKey].':'.$aMatches['type'][$iKey].'}/i',"\/?(".$aIdent[$aMatches['type'][$iKey]].")?", $sRoute);                                        
                                }
                            }else{
                                if ($aMatches['notnull'][$iKey] == 'notnull'){
                                    $sRoute = preg_replace('/\/{'.$aMatches['field'][$iKey].':notnull}/i',"\/([^\/]*)", $sRoute);                                        
                                }else{
                                    $sRoute = preg_replace("/\/?{".$aMatches['field'][$iKey]."}/", "\/?([^\/]*)?", $sRoute);                                                                                            
                                }
                            }
                        } 
                    }
                }
                else{
                    $sRoute = str_replace('/', '\/', $sRoute);
                }                    
                
                if(preg_match_all("/^".$sRoute."\/?$/i", $sMethod."_".$sUri, $aMatches)){
                    $aParams = array();
                    foreach($aMatches as $iKey => $aResult){
                        if($iKey > 0){
                            $aParams[] = $aResult[0];
                        }
                    }

                    $bCall = true; 
                    Storage::Set("route.request", $sRoute);

                    if(is_array($fFunc)){
                        if(is_array($fFunc[1]))
                            $aParams = array_merge($fFunc[1], $aParams);
                        else
                            $aParams = array_merge(array($fFunc[1]), $aParams);

                        call_user_func_array($fFunc[0], $aParams);
                    }
                    else{
                        call_user_func_array($fFunc, $aParams);
                    }

                    break;
                }              
            }        
            
            if(array_key_exists("__dynamicroute", $oThis->aRoutes) && !$bCall)
                call_user_func($oThis->aRoutes["__dynamicroute"]);  
            else
                Output::SendHTTPCode(404);
        }
348070
public function getComposerInstall()
    {
        if (file_exists('composer.lock')) {
            $json = json_decode(file_get_contents('composer.lock'));
            foreach ($json->packages as $package) {
                if ($package->name === 'gestionlan/framework') {
                    return $package;
                }
            }
        }

        return false;
    }
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;
    }
1262306
public function parse($str = null, $initialVariables = null)
    {
        if (is_array($str)) {
            $initialVariables = $str;
            $str = null;
        }

        $oldVars = $this->registeredVars;
        if ($initialVariables !== null) {
            $this->setVariables($initialVariables);
        }

        if ($str == null) {
            if (empty($this->_parseFile)) {
                throw new exception('nothing to parse');
            }

            $out = $this->compileFile($this->_parseFile);
        } else {
            $out = $this->compile($str);
        }

        $this->registeredVars = $oldVars;

        return $out;
    }