コード例 #1
0
 public function testRestoreAuth()
 {
     $io = new IO\NullIO();
     $io->setAuthentication('example.com', 'user', 'pass');
     $req = new HttpGetRequest('example.com', 'http://example.com/foo.txt', $io);
     self::assertSame('user', $req->username);
     self::assertSame('pass', $req->password);
 }
コード例 #2
0
ファイル: AddCommand.php プロジェクト: zyfran/satis
 /**
  * Validate repository URL
  *
  * @param $repositoryUrl
  * @return bool
  */
 protected function isRepositoryValid($repositoryUrl)
 {
     $io = new NullIO();
     $config = Factory::createConfig();
     $io->loadConfiguration($config);
     $repository = new VcsRepository(array('url' => $repositoryUrl), $io, $config);
     if (!($driver = $repository->getDriver())) {
         return false;
     }
     $information = $driver->getComposerInformation($driver->getRootIdentifier());
     return !empty($information['name']);
 }
コード例 #3
0
ファイル: Github.php プロジェクト: Doanlmit/pickleweb
 /**
  * @param string $url
  * @param string $token
  * @param bool   $cacheDir
  * @param null   $bufferIO
  *
  * @throws \Exception
  */
 public function __construct($url, $token = '', $cacheDir = false, $bufferIO = null)
 {
     $this->url = $url;
     $this->io = new NullIO();
     $this->log = $bufferIO ? $bufferIO : new BufferIO();
     $config = Factory::createConfig();
     $cfg = ['config' => []];
     if ($cacheDir) {
         $cfg['config']['cache-dir'] = $cacheDir;
     }
     if ($token) {
         $cfg['config']['github-oauth'] = ['github.com' => $token];
     }
     $config->merge($cfg);
     $this->cacheDir = $cacheDir;
     $this->io->loadConfiguration($config);
     $this->repository = new Repository\VcsRepository(['url' => $url, 'no-api' => false], $this->io, $config);
     $driver = $this->vcsDriver = $this->repository->getDriver();
     if (!$driver) {
         throw new \Exception('No driver found for <' . $url . '>');
     }
     $this->driver = $driver;
     $composerInfoMaster = $this->driver->getComposerInformation($this->driver->getRootIdentifier());
     if (!$composerInfoMaster) {
         throw new \Exception('master must have a valid composer.json');
     }
     $this->name = $composerInfoMaster['name'];
     list($this->vendorName, $this->packageName) = explode('/', $this->name);
     preg_match('#^(?:(?:https?|git)://([^/]+)/|git@([^:]+):)([^/]+)/(.+?)(?:\\.git|/)?$#', $this->url, $match);
     $this->gitHubVendorName = $match[3];
     $this->gitHubRepositoryName = $match[4];
     $client = new \Github\Client();
     $client->authenticate($token, null, \GitHub\Client::AUTH_URL_TOKEN);
     $this->client = $client;
 }
コード例 #4
0
ファイル: NullIOTest.php プロジェクト: neon64/composer
 public function testSelect()
 {
     $io = new NullIO();
     $this->assertEquals('1', $io->select('question', array('item1', 'item2'), '1', 2, 'foo', true));
 }
コード例 #5
0
ファイル: Factory.php プロジェクト: tommygoud/composer
 /**
  * @param  Config                     $config The configuration
  * @param  Downloader\DownloadManager $dm     Manager use to download sources
  * @return Archiver\ArchiveManager
  */
 public function createArchiveManager(Config $config, Downloader\DownloadManager $dm = null)
 {
     if (null === $dm) {
         $io = new IO\NullIO();
         $io->loadConfiguration($config);
         $dm = $this->createDownloadManager($io, $config);
     }
     $am = new Archiver\ArchiveManager($dm);
     $am->addArchiver(new Archiver\PharArchiver());
     return $am;
 }
コード例 #6
0
 public function testAskAndValidate()
 {
     $io = new NullIO();
     $this->assertEquals('foo', $io->askAndValidate('question', 'validator', false, 'foo'));
 }
コード例 #7
0
 /**
  * Set repository
  *
  * @param string $repository
  */
 public function setRepository($repoUrl)
 {
     $this->vcsDriver = null;
     // prevent local filesystem URLs
     if (preg_match('{^(\\.|[a-z]:|/)}i', $repoUrl)) {
         return;
     }
     $this->repository = $repoUrl;
     // avoid user@host URLs
     if (preg_match('{https?://.+@}', $repoUrl)) {
         return;
     }
     try {
         $io = new NullIO();
         $config = Factory::createConfig();
         $io->loadConfiguration($config);
         $repository = new VcsRepository(array('url' => $this->repository), $io, $config);
         $driver = $this->vcsDriver = $repository->getDriver();
         if (!$driver) {
             return;
         }
         $information = $driver->getComposerInformation($driver->getRootIdentifier());
         if (!isset($information['name'])) {
             return;
         }
         if (null === $this->getName()) {
             $this->setName($information['name']);
         }
         if ($driver instanceof GitHubDriver) {
             $this->repository = $driver->getRepositoryUrl();
         }
     } catch (\Exception $e) {
         $this->vcsDriverError = '[' . get_class($e) . '] ' . $e->getMessage();
     }
 }