當前位置: 首頁>>代碼示例>>PHP>>正文


PHP JsonFile::parseJson方法代碼示例

本文整理匯總了PHP中Composer\Json\JsonFile::parseJson方法的典型用法代碼示例。如果您正苦於以下問題:PHP JsonFile::parseJson方法的具體用法?PHP JsonFile::parseJson怎麽用?PHP JsonFile::parseJson使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Composer\Json\JsonFile的用法示例。


在下文中一共展示了JsonFile::parseJson方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: getComposerInformation

 /**
  * {@inheritDoc}
  */
 public function getComposerInformation($identifier)
 {
     if (!isset($this->infoCache[$identifier])) {
         preg_match('{^(.+?)(@\\d+)?$}', $identifier, $match);
         if (!empty($match[2])) {
             $identifier = $match[1];
             $rev = $match[2];
         } else {
             $rev = '';
         }
         $this->process->execute(sprintf('svn cat --non-interactive %s', escapeshellarg($this->baseUrl . $identifier . 'composer.json' . $rev)), $composer);
         if (!trim($composer)) {
             throw new \UnexpectedValueException('Failed to retrieve composer information for identifier ' . $identifier . ' in ' . $this->getUrl());
         }
         $composer = JsonFile::parseJson($composer);
         if (!isset($composer['time'])) {
             $this->process->execute(sprintf('svn info %s', escapeshellarg($this->baseUrl . $identifier . $rev)), $output);
             foreach ($this->process->splitLines($output) as $line) {
                 if ($line && preg_match('{^Last Changed Date: ([^(]+)}', $line, $match)) {
                     $date = new \DateTime($match[1]);
                     $composer['time'] = $date->format('Y-m-d H:i:s');
                     break;
                 }
             }
         }
         $this->infoCache[$identifier] = $composer;
     }
     return $this->infoCache[$identifier];
 }
開發者ID:natxet,項目名稱:composer,代碼行數:32,代碼來源:SvnDriver.php

示例2: authorizeOAuthInteractively

 public function authorizeOAuthInteractively($originUrl, $message = null)
 {
     $attemptCounter = 0;
     $apiUrl = 'github.com' === $originUrl ? 'api.github.com' : $originUrl . '/api/v3';
     if ($message) {
         $this->io->write($message);
     }
     $this->io->write('The credentials will be swapped for an OAuth token stored in ' . $this->config->get('home') . '/config.json, your password will not be stored');
     $this->io->write('To revoke access to this token you can visit https://github.com/settings/applications');
     while ($attemptCounter++ < 5) {
         try {
             $username = $this->io->ask('Username: ');
             $password = $this->io->askAndHideAnswer('Password: ');
             $this->io->setAuthentication($originUrl, $username, $password);
             $appName = 'Composer';
             if (0 === $this->process->execute('hostname', $output)) {
                 $appName .= ' on ' . trim($output);
             }
             $contents = JsonFile::parseJson($this->remoteFilesystem->getContents($originUrl, 'https://' . $apiUrl . '/authorizations', false, array('http' => array('method' => 'POST', 'follow_location' => false, 'header' => "Content-Type: application/json\r\n", 'content' => json_encode(array('scopes' => array('repo'), 'note' => $appName, 'note_url' => 'https://getcomposer.org/'))))));
         } catch (TransportException $e) {
             if (in_array($e->getCode(), array(403, 401))) {
                 $this->io->write('Invalid credentials.');
                 continue;
             }
             throw $e;
         }
         $this->io->setAuthentication($originUrl, $contents['token'], 'x-oauth-basic');
         $githubTokens = $this->config->get('github-oauth') ?: array();
         $githubTokens[$originUrl] = $contents['token'];
         $this->config->getConfigSource()->addConfigSetting('github-oauth', $githubTokens);
         return true;
     }
     throw new \RuntimeException("Invalid GitHub credentials 5 times in a row, aborting.");
 }
開發者ID:itillawarra,項目名稱:cmfive,代碼行數:34,代碼來源:GitHub.php

示例3: testNotifyBatch

 public function testNotifyBatch()
 {
     $packagesBuilder = new PackagesBuilder(new NullOutput(), vfsStream::url('build'), array('notify-batch' => 'http://localhost:54715/notify', 'repositories' => array(array('type' => 'composer', 'url' => 'http://localhost:54715')), 'require' => array('vendor/name' => '*')), false);
     $packages = array($this->package);
     $packagesBuilder->dump($packages);
     $packagesJson = JsonFile::parseJson($this->root->getChild('build/packages.json')->getContent());
     $this->assertEquals('http://localhost:54715/notify', $packagesJson['notify-batch']);
 }
開發者ID:zyfran,項目名稱:satis,代碼行數:8,代碼來源:PackagesBuilderDumpTest.php

示例4: doGetComposerInformation

 /**
  * Get composer information.
  *
  * @param string          $resource
  * @param ProcessExecutor $process
  * @param string          $cmdGet
  * @param string          $cmdLog
  * @param string          $repoDir
  * @param string          $datetimePrefix
  *
  * @return array The composer
  */
 protected static function doGetComposerInformation($resource, ProcessExecutor $process, $cmdGet, $cmdLog, $repoDir, $datetimePrefix = '')
 {
     $process->execute($cmdGet, $composer, $repoDir);
     if (!trim($composer)) {
         return array('_nonexistent_package' => true);
     }
     $composer = JsonFile::parseJson($composer, $resource);
     return static::addComposerTime($composer, $process, $cmdLog, $repoDir, $datetimePrefix);
 }
開發者ID:MvegaR,項目名稱:ingSotfware,代碼行數:21,代碼來源:ProcessUtil.php

示例5: load

 public function load($json)
 {
     if ($json instanceof JsonFile) {
         $config = $json->read();
     } elseif (file_exists($json)) {
         $config = JsonFile::parseJson(file_get_contents($json));
     } elseif (is_string($json)) {
         $config = JsonFile::parseJson($json);
     }
     return parent::load($config);
 }
開發者ID:nlegoff,項目名稱:composer,代碼行數:11,代碼來源:JsonLoader.php

示例6: getLatest

 public function getLatest()
 {
     $protocol = extension_loaded('openssl') ? 'https' : 'http';
     $versions = JsonFile::parseJson($this->rfs->getContents('getcomposer.org', $protocol . '://getcomposer.org/versions', false));
     foreach ($versions[$this->getChannel()] as $version) {
         if ($version['min-php'] <= PHP_VERSION_ID) {
             return $version;
         }
     }
     throw new \LogicException('There is no version of Composer available for your PHP version (' . PHP_VERSION . ')');
 }
開發者ID:neon64,項目名稱:composer,代碼行數:11,代碼來源:Versions.php

示例7: getBranches

 /**
  * {@inheritDoc}
  */
 public function getBranches()
 {
     if (null === $this->branches) {
         $resource = $this->getScheme() . '://bitbucket.org/api/1.0/repositories/' . $this->owner . '/' . $this->repository . '/branches';
         $branchData = JsonFile::parseJson($this->getContents($resource), $resource);
         $this->branches = array();
         foreach ($branchData as $branch => $data) {
             $this->branches[$branch] = $data['raw_node'];
         }
     }
     return $this->branches;
 }
開發者ID:Rudloff,項目名稱:composer,代碼行數:15,代碼來源:HgBitbucketDriver.php

示例8: getComposerInformation

 /**
  * {@inheritDoc}
  */
 public function getComposerInformation($identifier)
 {
     if (!isset($this->infoCache[$identifier])) {
         $composer = $this->getContents($this->getScheme() . '://raw.github.com/' . $this->owner . '/' . $this->repository . '/' . $identifier . '/composer.json');
         if (!$composer) {
             throw new \UnexpectedValueException('Failed to retrieve composer information for identifier ' . $identifier . ' in ' . $this->getUrl());
         }
         $composer = JsonFile::parseJson($composer);
         if (!isset($composer['time'])) {
             $commit = json_decode($this->getContents($this->getScheme() . '://api.github.com/repos/' . $this->owner . '/' . $this->repository . '/commits/' . $identifier), true);
             $composer['time'] = $commit['commit']['committer']['date'];
         }
         $this->infoCache[$identifier] = $composer;
     }
     return $this->infoCache[$identifier];
 }
開發者ID:natxet,項目名稱:composer,代碼行數:19,代碼來源:GitHubDriver.php

示例9: getComposerInformation

 /**
  * {@inheritDoc}
  */
 public function getComposerInformation($identifier)
 {
     if (!isset($this->infoCache[$identifier])) {
         $composer = $this->getContents($this->getScheme() . '://bitbucket.org/' . $this->owner . '/' . $this->repository . '/raw/' . $identifier . '/composer.json');
         if (!$composer) {
             throw new \UnexpectedValueException('Failed to retrieve composer information for identifier ' . $identifier . ' in ' . $this->getUrl());
         }
         $composer = JsonFile::parseJson($composer);
         if (!isset($composer['time'])) {
             $changeset = json_decode($this->getContents($this->getScheme() . '://api.bitbucket.org/1.0/repositories/' . $this->owner . '/' . $this->repository . '/changesets/' . $identifier), true);
             $composer['time'] = $changeset['timestamp'];
         }
         $this->infoCache[$identifier] = $composer;
     }
     return $this->infoCache[$identifier];
 }
開發者ID:natxet,項目名稱:composer,代碼行數:19,代碼來源:HgBitbucketDriver.php

示例10: getComposerContent

 /**
  * Gets content of composer information.
  *
  * @param string             $resource   The resource
  * @param string             $identifier The identifier
  * @param string             $scheme     The scheme
  * @param string             $owner      The owner
  * @param string             $repository The repository
  * @param VcsDriverInterface $driver     The vcs driver
  * @param string             $method     The method for get content
  *
  * @return array
  */
 protected static function getComposerContent($resource, $identifier, $scheme, $owner, $repository, $driver, $method)
 {
     try {
         $ref = new \ReflectionClass($driver);
         $meth = $ref->getMethod($method);
         $meth->setAccessible(true);
         $composer = $meth->invoke($driver, $resource);
     } catch (\Exception $e) {
         $composer = false;
     }
     if ($composer) {
         $composer = (array) JsonFile::parseJson((string) $composer, $resource);
         $composer = static::formatComposerContent($composer, $identifier, $scheme, $owner, $repository, $driver, $method);
         return $composer;
     }
     return array('_nonexistent_package' => true);
 }
開發者ID:MvegaR,項目名稱:ingSotfware,代碼行數:30,代碼來源:BitbucketUtil.php

示例11: testNominalCase

 public function testNominalCase()
 {
     $arrayPackage = array("vendor/name" => array("1.0" => array("name" => "vendor/name", "version" => "1.0", "version_normalized" => "1.0.0.0", "type" => "library")));
     vfsStreamWrapper::register();
     $root = vfsStream::newDirectory('build');
     vfsStreamWrapper::setRoot($root);
     $packagesBuilder = new PackagesBuilder(new NullOutput(), vfsStream::url('build'), array('repositories' => array(array('type' => 'composer', 'url' => 'http://localhost:54715')), 'require' => array('vendor/name' => '*')), false);
     $packages = array(new Package('vendor/name', '1.0.0.0', '1.0'));
     $packagesBuilder->dump($packages);
     $packagesJson = JsonFile::parseJson($root->getChild('build/packages.json')->getContent());
     $tmpArray = array_keys($packagesJson['includes']);
     $includeJson = array_shift($tmpArray);
     $includeJsonFile = 'build/' . $includeJson;
     $this->assertTrue(is_file(vfsStream::url($includeJsonFile)));
     $packagesIncludeJson = JsonFile::parseJson($root->getChild($includeJsonFile)->getContent());
     $this->assertEquals($arrayPackage, $packagesIncludeJson['packages']);
 }
開發者ID:robertgit,項目名稱:satis,代碼行數:17,代碼來源:PackagesBuilderDumpTest.php

示例12: getComposerInformation

 public function getComposerInformation($identifier)
 {
     if (!isset($this->infoCache[$identifier])) {
         $this->process->execute(sprintf('hg cat -r %s composer.json', escapeshellarg($identifier)), $composer, $this->repoDir);
         if (!trim($composer)) {
             return;
         }
         $composer = JsonFile::parseJson($composer, $identifier);
         if (!isset($composer['time'])) {
             $this->process->execute(sprintf('hg log --template "{date|rfc3339date}" -r %s', escapeshellarg($identifier)), $output, $this->repoDir);
             $date = new \DateTime(trim($output), new \DateTimeZone('UTC'));
             $composer['time'] = $date->format('Y-m-d H:i:s');
         }
         $this->infoCache[$identifier] = $composer;
     }
     return $this->infoCache[$identifier];
 }
開發者ID:itillawarra,項目名稱:cmfive,代碼行數:17,代碼來源:HgDriver.php

示例13: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $file = $input->getArgument('file');
     if (!file_exists($file)) {
         $output->writeln('<error>' . $file . ' not found.</error>');
         return 1;
     }
     if (!is_readable($file)) {
         $output->writeln('<error>' . $file . ' is not readable.</error>');
         return 1;
     }
     try {
         JsonFile::parseJson(file_get_contents($file));
     } catch (\Exception $e) {
         $output->writeln('<error>' . $e->getMessage() . '</error>');
         return 1;
     }
     $output->writeln('<info>' . $file . ' is valid</info>');
 }
開發者ID:natxet,項目名稱:composer,代碼行數:19,代碼來源:ValidateCommand.php

示例14: getComposerInformation

 private function getComposerInformation(\SplFileInfo $file)
 {
     $zip = new \ZipArchive();
     $zip->open($file->getPathname());
     if (0 == $zip->numFiles) {
         return false;
     }
     $foundFileIndex = $zip->locateName('composer.json', \ZipArchive::FL_NODIR);
     if (false === $foundFileIndex) {
         return false;
     }
     $configurationFileName = $zip->getNameIndex($foundFileIndex);
     $composerFile = "zip://{$file->getPathname()}#{$configurationFileName}";
     $json = file_get_contents($composerFile);
     $package = JsonFile::parseJson($json, $composerFile);
     $package['dist'] = array('type' => 'zip', 'url' => $file->getRealPath(), 'reference' => $file->getBasename(), 'shasum' => sha1_file($file->getRealPath()));
     $package = $this->loader->load($package);
     return $package;
 }
開發者ID:shabbirvividads,項目名稱:magento2,代碼行數:19,代碼來源:ArtifactRepository.php

示例15: getIndex

 public function getIndex()
 {
     $defaults = Config::get('ComposerUI::defaults');
     $workingDir = Input::get('workingDir', $defaults['workingDir']);
     $realpath = realpath($workingDir);
     if ($realpath != $workingDir && $realpath != false) {
         return Redirect::to('composer?workingDir=' . urlencode($realpath));
     } else {
         $jsonComposer = null;
         if (file_exists($workingDir . DIRECTORY_SEPARATOR . 'composer.json')) {
             try {
                 $jsonComposer = JsonFile::parseJson(file_get_contents($workingDir . DIRECTORY_SEPARATOR . 'composer.json'));
             } catch (Exception $e) {
                 $jsonComposer = null;
             }
         }
         Session::put("ComposerUI.workingDir", $workingDir);
         return View::make('ComposerUI::home')->with(array('workingDir' => $workingDir, 'jsonComposer' => $jsonComposer));
     }
 }
開發者ID:composer-ui,項目名稱:composer-ui,代碼行數:20,代碼來源:ComposerUIController.php


注:本文中的Composer\Json\JsonFile::parseJson方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。