当前位置: 首页>>代码示例>>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;未经允许,请勿转载。