Ejemplo n.º 1
0
    /**
     * @dataProvider getDataProvider
     */
    public function testAddComposerTimeWithSimpleKey($resourceKey)
    {
        $composer = array(
            'name' => 'test',
        );
        $driver = new MockVcsDriver();

        $value = null;
        $keys = explode('.', $resourceKey);
        $start = count($keys) - 1;

        for ($i = $start; $i>=0; $i--) {
            if (null === $value) {
                $value = 'level ' . $i;
            }

            $value = array($keys[$i] => $value);
        }

        $driver->contents = json_encode($value);
        $composerValid = array_merge($composer, array(
            'time' => 'level ' . (count($keys) - 1),
        ));

        $composer = Util::addComposerTime($composer, $resourceKey, 'http://example.tld', $driver);

        $this->assertSame($composerValid, $composer);
    }
Ejemplo n.º 2
0
 /**
  * {@inheritDoc}
  */
 public function getComposerInformation($identifier)
 {
     $this->infoCache[$identifier] = Util::readCache($this->infoCache, $this->cache, $this->repoConfig['asset-type'], $identifier, true);
     if (!isset($this->infoCache[$identifier])) {
         $composer = $this->getComposerContent($identifier);
         Util::writeCache($this->cache, $this->repoConfig['asset-type'], $identifier, $composer, true);
         $this->infoCache[$identifier] = $composer;
     }
     return $this->infoCache[$identifier];
 }
Ejemplo n.º 3
0
 /**
  * Get composer information.
  *
  * @param Cache           $cache
  * @param array           $infoCache
  * @param string          $assetType
  * @param ProcessExecutor $process
  * @param string          $identifier
  * @param string          $resource
  * @param string          $cmdGet
  * @param string          $cmdLog
  * @param string          $repoDir
  * @param string          $datetimePrefix
  *
  * @return array The composer
  */
 public static function getComposerInformation(Cache $cache, array &$infoCache, $assetType, ProcessExecutor $process, $identifier, $resource, $cmdGet, $cmdLog, $repoDir, $datetimePrefix = '')
 {
     $infoCache[$identifier] = Util::readCache($infoCache, $cache, $assetType, $identifier);
     if (!isset($infoCache[$identifier])) {
         $composer = static::doGetComposerInformation($resource, $process, $cmdGet, $cmdLog, $repoDir, $datetimePrefix);
         Util::writeCache($cache, $assetType, $identifier, $composer);
         $infoCache[$identifier] = $composer;
     }
     return $infoCache[$identifier];
 }
Ejemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function getComposerInformation($identifier)
 {
     $identifier = '/' . trim($identifier, '/') . '/';
     $this->infoCache[$identifier] = Util::readCache($this->infoCache, $this->cache, $this->repoConfig['asset-type'], trim($identifier, '/'), true);
     if (!isset($this->infoCache[$identifier])) {
         list($path, $rev) = $this->getPathRev($identifier);
         $resource = $path . $this->repoConfig['filename'];
         $output = $this->getComposerContent($resource, $rev);
         $composer = $this->parseComposerContent($output, $resource, $path, $rev);
         Util::writeCache($this->cache, $this->repoConfig['asset-type'], trim($identifier, '/'), $composer, true);
         $this->infoCache[$identifier] = $composer;
     }
     return $this->infoCache[$identifier];
 }
Ejemplo n.º 5
0
    /**
     * Format composer content.
     *
     * @param array              $composer   The composer
     * @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 formatComposerContent(array $composer, $identifier, $scheme, $owner, $repository, $driver, $method)
    {
        $resource = $scheme . '://api.bitbucket.org/1.0/repositories/'.$owner.'/'.$repository.'/changesets/'.$identifier;
        $composer = Util::addComposerTime($composer, 'timestamp', $resource, $driver, $method);

        return $composer;
    }
Ejemplo n.º 6
0
    /**
     * Converts json composer file to array.
     *
     * @param string $composer
     * @param string $resource
     * @param string $identifier
     *
     * @return array
     */
    protected function convertComposerContent($composer, $resource, $identifier)
    {
        $composer = JsonFile::parseJson($composer, $resource);
        $resource = $this->getApiUrl() . '/repos/'.$this->owner.'/'.$this->repository.'/commits/'.urlencode($identifier);
        $composer = Util::addComposerTime($composer, 'commit.committer.date', $resource, $this);

        if (!isset($composer['support']['source'])) {
            $label = array_search($identifier, $this->getTags()) ?: array_search($identifier, $this->getBranches()) ?: $identifier;
            $composer['support']['source'] = sprintf('https://%s/%s/%s/tree/%s', $this->originUrl, $this->owner, $this->repository, $label);
        }
        if (!isset($composer['support']['issues']) && $this->hasIssues) {
            $composer['support']['issues'] = sprintf('https://%s/%s/%s/issues', $this->originUrl, $this->owner, $this->repository);
        }

        return $composer;
    }