/**
  * @param \Composer\Script\Event $event
  */
 public function linkAutoloader(\Composer\Script\Event $event)
 {
     $composer = $event->getComposer();
     $composerConfig = $composer->getConfig();
     $localRepository = $composer->getRepositoryManager()->getLocalRepository();
     foreach ($localRepository->getCanonicalPackages() as $package) {
         if ($package->getType() === 'typo3-cms-core') {
             $defaultVendorDir = \Composer\Config::$defaultConfig['vendor-dir'];
             $packagePath = $composer->getInstallationManager()->getInstallPath($package);
             $jsonFile = new \Composer\Json\JsonFile($packagePath . DIRECTORY_SEPARATOR . 'composer.json', new \Composer\Util\RemoteFilesystem($event->getIO()));
             $packageJson = $jsonFile->read();
             $packageVendorDir = !empty($packageJson['config']['vendor-dir']) ? $this->filesystem->normalizePath($packageJson['config']['vendor-dir']) : $defaultVendorDir;
             $autoloaderSourceDir = $composerConfig->get('vendor-dir');
             $autoloaderTargetDir = $packagePath . DIRECTORY_SEPARATOR . $packageVendorDir;
             $autoloaderFileName = 'autoload.php';
             $this->filesystem->ensureDirectoryExists($autoloaderTargetDir);
             $this->filesystem->remove($autoloaderTargetDir . DIRECTORY_SEPARATOR . $autoloaderFileName);
             try {
                 $this->filesystem->symlink($autoloaderSourceDir . DIRECTORY_SEPARATOR . $autoloaderFileName, $autoloaderTargetDir . DIRECTORY_SEPARATOR . $autoloaderFileName, FALSE, TRUE);
             } catch (\RuntimeException $e) {
                 if ($e->getCode() !== 1430494084) {
                     throw $e;
                 }
                 $code = array('<?php', 'return require ' . $this->filesystem->findShortestPathCode($autoloaderTargetDir . DIRECTORY_SEPARATOR . $autoloaderFileName, $autoloaderSourceDir . DIRECTORY_SEPARATOR . $autoloaderFileName) . ';');
                 file_put_contents($autoloaderTargetDir . DIRECTORY_SEPARATOR . $autoloaderFileName, implode(chr(10), $code));
             }
             $this->insertComposerModeConstant($event);
             break;
         }
     }
 }
 /**
  * Download file and decode the JSON string to PHP object
  *
  * @param string $json
  * @return stdClass
  */
 public function getJson($url)
 {
     $key = 'json://' . $url;
     if (array_key_exists($key, $this->cache)) {
         return $this->cache[$key];
     }
     $json = new \Composer\Json\JsonFile($url, $this->remoteFileSystem);
     return $this->cache[$key] = $json->read();
 }
Beispiel #3
0
 /**
  * @param string $rootDir
  * @return \Composer\Composer
  */
 public function createComposerFromRootDir($rootDir)
 {
     $composerPath = $rootDir . 'composer.json';
     $composerFile = new Composer\Json\JsonFile($composerPath);
     $composerFile->validateSchema(Composer\Json\JsonFile::LAX_SCHEMA);
     $localConfig = $composerFile->read();
     $composerFactory = new CM_App_ComposerFactory();
     $composer = $composerFactory->createComposer($localConfig);
     $vendorDir = $rootDir . $composer->getConfig()->get('vendor-dir');
     $vendorConfig = new Composer\Json\JsonFile($vendorDir . '/composer/installed.json');
     $vendorRepository = new Composer\Repository\InstalledFilesystemRepository($vendorConfig);
     $composer->getRepositoryManager()->setLocalRepository($vendorRepository);
     return $composer;
 }
Beispiel #4
0
 /**
  * @param \Composer\IO\IOInterface $io
  * @param \Composer\Config $composerConfig
  * @return Config
  * @throws \RuntimeException
  * @throws \InvalidArgumentException
  */
 public static function load(\Composer\IO\IOInterface $io, \Composer\Config $composerConfig)
 {
     static $config;
     if ($config === null) {
         $baseDir = realpath(substr($composerConfig->get('vendor-dir'), 0, -strlen($composerConfig->get('vendor-dir', Config::RELATIVE_PATHS))));
         $localConfig = \Composer\Factory::getComposerFile();
         $file = new \Composer\Json\JsonFile($localConfig, new \Composer\Util\RemoteFilesystem($io));
         $config = new static($baseDir);
         $config->merge($file->read());
     }
     return $config;
 }
Beispiel #5
0
 /**
  * @param array $hash
  */
 private function _writeToComposerFile(array $hash)
 {
     $composerFile = new Composer\Json\JsonFile($this->_installation->getDirRoot() . 'composer.json');
     $configCurrent = $composerFile->read();
     $this->_filesystemHelper->notify('modify', 'composer.json');
     $configMerged = $this->_mergeConfigs($configCurrent, $hash);
     $composerFile->write($configMerged);
     $this->_installation->reload();
 }
Beispiel #6
0
 /**
  * @param string $cacheDir
  * @return array
  * @throws \Exception
  */
 protected function getInstalledPackages($cacheDir)
 {
     $file = new \Composer\Json\JsonFile($cacheDir . '/composer/installed.json');
     if (!$file->exists()) {
         throw new \Exception('no packages installed in repository');
     }
     $packages = $file->read();
     usort($packages, function ($a, $b) {
         return strnatcasecmp($a['name'], $b['name']);
     });
     return $packages;
 }