Esempio n. 1
0
 public function dump(PackageInterface $package)
 {
     $keys = array('binaries' => 'bin', 'type', 'extra', 'installationSource' => 'installation-source', 'autoload', 'notificationUrl' => 'notification-url', 'includePaths' => 'include-path');
     $data = array();
     $data['name'] = $package->getPrettyName();
     $data['version'] = $package->getPrettyVersion();
     $data['version_normalized'] = $package->getVersion();
     if ($package->getTargetDir()) {
         $data['target-dir'] = $package->getTargetDir();
     }
     if ($package->getSourceType()) {
         $data['source']['type'] = $package->getSourceType();
         $data['source']['url'] = $package->getSourceUrl();
         $data['source']['reference'] = $package->getSourceReference();
     }
     if ($package->getDistType()) {
         $data['dist']['type'] = $package->getDistType();
         $data['dist']['url'] = $package->getDistUrl();
         $data['dist']['reference'] = $package->getDistReference();
         $data['dist']['shasum'] = $package->getDistSha1Checksum();
     }
     if ($package->getArchiveExcludes()) {
         $data['archive']['exclude'] = $package->getArchiveExcludes();
     }
     foreach (BasePackage::$supportedLinkTypes as $type => $opts) {
         if ($links = $package->{'get' . ucfirst($opts['method'])}()) {
             foreach ($links as $link) {
                 $data[$type][$link->getTarget()] = $link->getPrettyConstraint();
             }
             ksort($data[$type]);
         }
     }
     if ($packages = $package->getSuggests()) {
         ksort($packages);
         $data['suggest'] = $packages;
     }
     if ($package->getReleaseDate()) {
         $data['time'] = $package->getReleaseDate()->format('Y-m-d H:i:s');
     }
     $data = $this->dumpValues($package, $keys, $data);
     if ($package instanceof CompletePackageInterface) {
         $keys = array('scripts', 'license', 'authors', 'description', 'homepage', 'keywords', 'repositories', 'support');
         $data = $this->dumpValues($package, $keys, $data);
         if (isset($data['keywords']) && is_array($data['keywords'])) {
             sort($data['keywords']);
         }
     }
     if ($package instanceof RootPackageInterface) {
         $minimumStability = $package->getMinimumStability();
         if ($minimumStability) {
             $data['minimum-stability'] = $minimumStability;
         }
     }
     return $data;
 }
 /**
  * @param array
  * @param \Composer\Package\PackageInterface
  */
 public function parseAutoloadsTypeFiles($paths, PackageInterface $mainPackage)
 {
     $autoloads = array();
     $installPath = '';
     foreach ((array) $paths as $path) {
         if ($mainPackage->getTargetDir() && !is_readable($installPath . '/' . $path)) {
             // remove target-dir from file paths of the root package
             $targetDir = str_replace('\\<dirsep\\>', '[\\\\/]', preg_quote(str_replace(array('/', '\\'), '<dirsep>', $mainPackage->getTargetDir())));
             $path = ltrim(preg_replace('{^' . $targetDir . '}', '', ltrim($path, '\\/')), '\\/');
         }
         $relativePath = empty($installPath) ? empty($path) ? '.' : $path : $installPath . '/' . $path;
         $autoloads[$this->getFileIdentifier($mainPackage, $path)] = $relativePath;
     }
     return $autoloads;
 }
 /**
  * {@inheritdoc}
  */
 public function getInstallPath(PackageInterface $package)
 {
     $this->initializeVendorDir();
     $targetDir = $package->getTargetDir();
     list(, $name) = explode('/', $package->getPrettyName(), 2);
     return ($this->vendorDir ? $this->vendorDir . '/' : '') . $name . ($targetDir ? '/' . $targetDir : '');
 }
Esempio n. 4
0
 public function dump(PackageInterface $package)
 {
     $keys = array('binaries' => 'bin', 'scripts', 'type', 'extra', 'installationSource' => 'installation-source', 'license', 'authors', 'description', 'homepage', 'keywords', 'autoload', 'repositories', 'includePaths' => 'include-path', 'support');
     $data = array();
     $data['name'] = $package->getPrettyName();
     $data['version'] = $package->getPrettyVersion();
     $data['version_normalized'] = $package->getVersion();
     if ($package->getTargetDir()) {
         $data['target-dir'] = $package->getTargetDir();
     }
     if ($package->getReleaseDate()) {
         $data['time'] = $package->getReleaseDate()->format('Y-m-d H:i:s');
     }
     if ($package->getSourceType()) {
         $data['source']['type'] = $package->getSourceType();
         $data['source']['url'] = $package->getSourceUrl();
         $data['source']['reference'] = $package->getSourceReference();
     }
     if ($package->getDistType()) {
         $data['dist']['type'] = $package->getDistType();
         $data['dist']['url'] = $package->getDistUrl();
         $data['dist']['reference'] = $package->getDistReference();
         $data['dist']['shasum'] = $package->getDistSha1Checksum();
     }
     foreach (BasePackage::$supportedLinkTypes as $type => $opts) {
         if ($links = $package->{'get' . ucfirst($opts['method'])}()) {
             foreach ($links as $link) {
                 $data[$type][$link->getTarget()] = $link->getPrettyConstraint();
             }
         }
     }
     if ($packages = $package->getSuggests()) {
         $data['suggest'] = $packages;
     }
     foreach ($keys as $method => $key) {
         if (is_numeric($method)) {
             $method = $key;
         }
         $getter = 'get' . ucfirst($method);
         $value = $package->{$getter}();
         if (null !== $value && !(is_array($value) && 0 === count($value))) {
             $data[$key] = $value;
         }
     }
     return $data;
 }
Esempio n. 5
0
 /**
  * {@inheritDoc}
  */
 public function getInstallPath(PackageInterface $package)
 {
     $prefix = substr($package->getPrettyName(), 0, 14);
     if ('zepluf/plugin-' !== $prefix) {
         throw new \InvalidArgumentException('Unable to install plugin ' . $package->getPrettyName() . ', ZePLUF plugin package names  should always begin with "zepluf/plugin-"');
     }
     return 'app/plugins/' . $package->getTargetDir();
 }
 /**
  * @param PackageInterface $package
  * @return string
  */
 public function getInstallPath(PackageInterface $package)
 {
     $targetDir = $package->getTargetDir();
     if ($targetDir) {
         return sprintf('%s/%s', $this->getPackageBasePath($package), $targetDir);
     }
     return $this->getPackageBasePath($package);
 }
 public function getInstallPath(PackageInterface $package)
 {
     $path = $this->vendorDir;
     $path .= '/' . $package->getPrettyName();
     $targetDir = $package->getTargetDir();
     if ($targetDir) {
         $path .= '/' . $targetDir;
     }
     return $path;
 }
 /**
  * Install extensions before vendor dir
  */
 public function getInstallPath(PackageInterface $package)
 {
     $this->initializeVendorDir();
     $basePath = $this->vendorDir ? $this->vendorDir : '';
     $extras = $package->getExtra();
     if (!is_null($extras) && isset($extras[self::EXT_NAME_KEY]) && !empty($extras[self::EXT_NAME_KEY])) {
         // get extension
         return $basePath . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . $extras[self::EXT_NAME_KEY];
     } else {
         // default path
         $targetDir = $package->getTargetDir();
         return (empty($basePath) ? '' : $basePapth . DIRECTORY_SEPARATOR) . $package->getPrettyName() . ($targetDir ? DIRECTORY_SEPARATOR . $targetDir : '');
     }
 }
 /**
  * {@inheritDoc}
  */
 public function getInstallPath(PackageInterface $package)
 {
     $type = $package->getType();
     $prettyName = $package->getPrettyName();
     if (strpos($prettyName, '/') !== false) {
         list($vendor, $name) = explode('/', $prettyName);
     } else {
         $vendor = '';
         $name = $prettyName;
     }
     $installerPaths = $this->composer->getConfig()->get('installer-paths');
     $availableVars = $this->inflectPackageVars(compact('name', 'vendor', 'type'));
     if (!empty($installerPaths)) {
         $customPath = $this->mapCustomInstallPaths($installerPaths, $prettyName, $type);
         if ($customPath !== false) {
             return $this->templatePath($customPath, $availableVars);
         }
     }
     $this->initializeVendorDir();
     $basePath = ($this->vendorDir ? $this->vendorDir . '/' : '') . $package->getPrettyName();
     $targetDir = $package->getTargetDir();
     return $basePath . ($targetDir ? '/' . $targetDir : '');
 }
Esempio n. 10
0
 /**
  * {@inheritDoc}
  */
 public function getInstallPath(PackageInterface $package)
 {
     $targetDir = $package->getTargetDir();
     return $package->getPrettyName() . ($targetDir ? '/' . $targetDir : '');
 }
Esempio n. 11
0
 public function getTargetDir()
 {
     return $this->aliasOf->getTargetDir();
 }
 /**
  * @param PackageInterface $package
  *
  * @return string
  */
 protected function getSymlinkSourcePath(PackageInterface $package)
 {
     if (null != $this->config->getSymlinkBasePath()) {
         $targetDir = $package->getTargetDir();
         $sourcePath = $this->config->getSymlinkBasePath() . '/' . $package->getPrettyName() . '/' . $package->getPrettyVersion() . ($targetDir ? '/' . $targetDir : '');
     } else {
         $sourcePath = $this->getInstallPath($package);
     }
     return $sourcePath;
 }
Esempio n. 13
0
 /**
  * {@inheritDoc}
  */
 public function getInstallPath(PackageInterface $package)
 {
     $this->initializeVendorDir();
     $basePath = ($this->vendorDir ? $this->vendorDir . '/' : '') . $package->getPrettyName();
     $targetDir = $package->getTargetDir();
     return $basePath . ($targetDir ? '/' . $targetDir : '');
 }
Esempio n. 14
0
 /**
  * {@inheritDoc}
  */
 public function getInstallPath(PackageInterface $package)
 {
     if (!is_null($this->modmanRootDir) && true === $this->modmanRootDir->isDir()) {
         $targetDir = $package->getTargetDir();
         if (!$targetDir) {
             list($vendor, $targetDir) = explode('/', $package->getPrettyName());
         }
         $installPath = $this->modmanRootDir . '/' . $targetDir;
     } else {
         $installPath = parent::getInstallPath($package);
     }
     // Make install path absolute. This is needed in the symlink deploy strategies.
     if (DIRECTORY_SEPARATOR !== $installPath[0] && $installPath[1] !== ':') {
         $installPath = getcwd() . "/{$installPath}";
     }
     return $installPath;
 }
Esempio n. 15
0
 private function updateInformation(Package $package, PackageInterface $data, $flags)
 {
     $em = $this->doctrine->getManager();
     $version = new Version();
     $normVersion = $data->getVersion();
     $existingVersion = $package->getVersion($normVersion);
     if ($existingVersion) {
         $source = $existingVersion->getSource();
         // update if the right flag is set, or the source reference has changed (re-tag or new commit on branch)
         if ($source['reference'] !== $data->getSourceReference() || $flags & self::UPDATE_EQUAL_REFS) {
             $version = $existingVersion;
         } else {
             // mark it updated to avoid it being pruned
             $existingVersion->setUpdatedAt(new \DateTime());
             return false;
         }
     }
     $version->setName($package->getName());
     $version->setVersion($data->getPrettyVersion());
     $version->setNormalizedVersion($normVersion);
     $version->setDevelopment($data->isDev());
     $em->persist($version);
     $descr = $this->sanitize($data->getDescription());
     $version->setDescription($descr);
     $package->setDescription($descr);
     $version->setHomepage($data->getHomepage());
     $version->setLicense($data->getLicense() ?: array());
     $version->setPackage($package);
     $version->setUpdatedAt(new \DateTime());
     $version->setReleasedAt($data->getReleaseDate());
     if ($data->getSourceType()) {
         $source['type'] = $data->getSourceType();
         $source['url'] = $data->getSourceUrl();
         $source['reference'] = $data->getSourceReference();
         $version->setSource($source);
     } else {
         $version->setSource(null);
     }
     if ($data->getDistType()) {
         $dist['type'] = $data->getDistType();
         $dist['url'] = $data->getDistUrl();
         $dist['reference'] = $data->getDistReference();
         $dist['shasum'] = $data->getDistSha1Checksum();
         $version->setDist($dist);
     } else {
         $version->setDist(null);
     }
     if ($data->getType()) {
         $type = $this->sanitize($data->getType());
         $version->setType($type);
         if ($type !== $package->getType()) {
             $package->setType($type);
         }
     }
     $version->setTargetDir($data->getTargetDir());
     $version->setAutoload($data->getAutoload());
     $version->setExtra($data->getExtra());
     $version->setBinaries($data->getBinaries());
     $version->setIncludePaths($data->getIncludePaths());
     $version->setSupport($data->getSupport());
     if ($data->getKeywords()) {
         $keywords = array();
         foreach ($data->getKeywords() as $keyword) {
             $keywords[mb_strtolower($keyword, 'UTF-8')] = $keyword;
         }
         $existingTags = [];
         foreach ($version->getTags() as $tag) {
             $existingTags[mb_strtolower($tag->getName(), 'UTF-8')] = $tag;
         }
         foreach ($keywords as $tagKey => $keyword) {
             if (isset($existingTags[$tagKey])) {
                 unset($existingTags[$tagKey]);
                 continue;
             }
             $tag = Tag::getByName($em, $keyword, true);
             if (!$version->getTags()->contains($tag)) {
                 $version->addTag($tag);
             }
         }
         foreach ($existingTags as $tag) {
             $version->getTags()->removeElement($tag);
         }
     } elseif (count($version->getTags())) {
         $version->getTags()->clear();
     }
     $authorRepository = $this->doctrine->getRepository('PackagistWebBundle:Author');
     $version->getAuthors()->clear();
     if ($data->getAuthors()) {
         foreach ($data->getAuthors() as $authorData) {
             $author = null;
             foreach (array('email', 'name', 'homepage', 'role') as $field) {
                 if (isset($authorData[$field])) {
                     $authorData[$field] = trim($authorData[$field]);
                     if ('' === $authorData[$field]) {
                         $authorData[$field] = null;
                     }
                 } else {
                     $authorData[$field] = null;
                 }
             }
             // skip authors with no information
             if (!isset($authorData['email']) && !isset($authorData['name'])) {
                 continue;
             }
             $author = $authorRepository->findOneBy(array('email' => $authorData['email'], 'name' => $authorData['name'], 'homepage' => $authorData['homepage'], 'role' => $authorData['role']));
             if (!$author) {
                 $author = new Author();
                 $em->persist($author);
             }
             foreach (array('email', 'name', 'homepage', 'role') as $field) {
                 if (isset($authorData[$field])) {
                     $author->{'set' . $field}($authorData[$field]);
                 }
             }
             // only update the author timestamp once a month at most as the value is kinda unused
             if ($author->getUpdatedAt() === null || $author->getUpdatedAt()->getTimestamp() < time() - 86400 * 30) {
                 $author->setUpdatedAt(new \DateTime());
             }
             if (!$version->getAuthors()->contains($author)) {
                 $version->addAuthor($author);
             }
             if (!$author->getVersions()->contains($version)) {
                 $author->addVersion($version);
             }
         }
     }
     // handle links
     foreach ($this->supportedLinkTypes as $linkType => $opts) {
         $links = array();
         foreach ($data->{$opts['method']}() as $link) {
             $constraint = $link->getPrettyConstraint();
             if (false !== strpos($constraint, ',') && false !== strpos($constraint, '@')) {
                 $constraint = preg_replace_callback('{([><]=?\\s*[^@]+?)@([a-z]+)}i', function ($matches) {
                     if ($matches[2] === 'stable') {
                         return $matches[1];
                     }
                     return $matches[1] . '-' . $matches[2];
                 }, $constraint);
             }
             $links[$link->getTarget()] = $constraint;
         }
         foreach ($version->{'get' . $linkType}() as $link) {
             // clear links that have changed/disappeared (for updates)
             if (!isset($links[$link->getPackageName()]) || $links[$link->getPackageName()] !== $link->getPackageVersion()) {
                 $version->{'get' . $linkType}()->removeElement($link);
                 $em->remove($link);
             } else {
                 // clear those that are already set
                 unset($links[$link->getPackageName()]);
             }
         }
         foreach ($links as $linkPackageName => $linkPackageVersion) {
             $class = 'Packagist\\WebBundle\\Entity\\' . $opts['entity'];
             $link = new $class();
             $link->setPackageName($linkPackageName);
             $link->setPackageVersion($linkPackageVersion);
             $version->{'add' . $linkType . 'Link'}($link);
             $link->setVersion($version);
             $em->persist($link);
         }
     }
     // handle suggests
     if ($suggests = $data->getSuggests()) {
         foreach ($version->getSuggest() as $link) {
             // clear links that have changed/disappeared (for updates)
             if (!isset($suggests[$link->getPackageName()]) || $suggests[$link->getPackageName()] !== $link->getPackageVersion()) {
                 $version->getSuggest()->removeElement($link);
                 $em->remove($link);
             } else {
                 // clear those that are already set
                 unset($suggests[$link->getPackageName()]);
             }
         }
         foreach ($suggests as $linkPackageName => $linkPackageVersion) {
             $link = new SuggestLink();
             $link->setPackageName($linkPackageName);
             $link->setPackageVersion($linkPackageVersion);
             $version->addSuggestLink($link);
             $link->setVersion($version);
             $em->persist($link);
         }
     } elseif (count($version->getSuggest())) {
         // clear existing suggests if present
         foreach ($version->getSuggest() as $link) {
             $em->remove($link);
         }
         $version->getSuggest()->clear();
     }
     if (!$package->getVersions()->contains($version)) {
         $package->addVersions($version);
     }
     return true;
 }
 public function getInstallPath(PackageInterface $package) : string
 {
     $targetDir = $package->getTargetDir();
     return $this->getPackageBasePath($package) . ($targetDir ? '/' . $targetDir : '');
 }
Esempio n. 17
0
 private function buildOperation($type, PackageInterface $package)
 {
     $vendorDir = $this->kernel->getRootDir() . '/../vendor';
     $targetDir = $package->getTargetDir() ?: '';
     $packageDir = empty($targetDir) ? $package->getPrettyName() : "{$package->getName()}/{$targetDir}";
     $fqcn = $this->detector->detectBundle("{$vendorDir}/{$packageDir}");
     return new Operation($type, $package, $fqcn);
 }
Esempio n. 18
0
 /**
  * {@inheritdoc}
  */
 public function getTargetDir()
 {
     return $this->package->getTargetDir();
 }
Esempio n. 19
0
 private function updateInformation(OutputInterface $output, RegistryInterface $doctrine, $package, PackageInterface $data)
 {
     $em = $doctrine->getEntityManager();
     $version = new Version();
     $version->setName($package->getName());
     $version->setNormalizedVersion(preg_replace('{-dev$}i', '', $data->getVersion()));
     // check if we have that version yet
     foreach ($package->getVersions() as $existingVersion) {
         if ($existingVersion->equals($version)) {
             // avoid updating newer versions, in case two branches have the same version in their composer.json
             if ($existingVersion->getReleasedAt() > $data->getReleaseDate()) {
                 return;
             }
             if ($existingVersion->getDevelopment()) {
                 $version = $existingVersion;
                 break;
             }
             return;
         }
     }
     $version->setVersion($data->getPrettyVersion());
     $version->setDevelopment(substr($data->getVersion(), -4) === '-dev');
     $em->persist($version);
     $version->setDescription($data->getDescription());
     $package->setDescription($data->getDescription());
     $version->setHomepage($data->getHomepage());
     $version->setLicense($data->getLicense() ?: array());
     $version->setPackage($package);
     $version->setUpdatedAt(new \DateTime());
     $version->setReleasedAt($data->getReleaseDate());
     if ($data->getSourceType()) {
         $source['type'] = $data->getSourceType();
         $source['url'] = $data->getSourceUrl();
         $source['reference'] = $data->getSourceReference();
         $version->setSource($source);
     }
     if ($data->getDistType()) {
         $dist['type'] = $data->getDistType();
         $dist['url'] = $data->getDistUrl();
         $dist['reference'] = $data->getDistReference();
         $dist['shasum'] = $data->getDistSha1Checksum();
         $version->setDist($dist);
     }
     if ($data->getType()) {
         $version->setType($data->getType());
         if ($data->getType() && $data->getType() !== $package->getType()) {
             $package->setType($data->getType());
         }
     }
     $version->setTargetDir($data->getTargetDir());
     $version->setAutoload($data->getAutoload());
     $version->setExtra($data->getExtra());
     $version->setBinaries($data->getBinaries());
     $version->getTags()->clear();
     if ($data->getKeywords()) {
         foreach ($data->getKeywords() as $keyword) {
             $version->addTag(Tag::getByName($em, $keyword, true));
         }
     }
     $version->getAuthors()->clear();
     if ($data->getAuthors()) {
         foreach ($data->getAuthors() as $authorData) {
             $author = null;
             // skip authors with no information
             if (empty($authorData['email']) && empty($authorData['name'])) {
                 continue;
             }
             if (!empty($authorData['email'])) {
                 $author = $doctrine->getRepository('PackagistWebBundle:Author')->findOneByEmail($authorData['email']);
             }
             if (!$author && !empty($authorData['homepage'])) {
                 $author = $doctrine->getRepository('PackagistWebBundle:Author')->findOneBy(array('name' => $authorData['name'], 'homepage' => $authorData['homepage']));
             }
             if (!$author && !empty($authorData['name'])) {
                 $author = $doctrine->getRepository('PackagistWebBundle:Author')->findOneByNameAndPackage($authorData['name'], $package);
             }
             if (!$author) {
                 $author = new Author();
                 $em->persist($author);
             }
             foreach (array('email', 'name', 'homepage') as $field) {
                 if (isset($authorData[$field])) {
                     $author->{'set' . $field}($authorData[$field]);
                 }
             }
             $author->setUpdatedAt(new \DateTime());
             if (!$version->getAuthors()->contains($author)) {
                 $version->addAuthor($author);
             }
             if (!$author->getVersions()->contains($version)) {
                 $author->addVersion($version);
             }
         }
     }
     foreach ($this->supportedLinkTypes as $linkType => $linkEntity) {
         $links = array();
         foreach ($data->{'get' . $linkType . 's'}() as $link) {
             $links[$link->getTarget()] = $link->getPrettyConstraint();
         }
         foreach ($version->{'get' . $linkType}() as $link) {
             // clear links that have changed/disappeared (for updates)
             if (!isset($links[$link->getPackageName()]) || $links[$link->getPackageName()] !== $link->getPackageVersion()) {
                 $version->{'get' . $linkType}()->removeElement($link);
                 $em->remove($link);
             } else {
                 // clear those that are already set
                 unset($links[$link->getPackageName()]);
             }
         }
         foreach ($links as $linkPackageName => $linkPackageVersion) {
             $class = 'Packagist\\WebBundle\\Entity\\' . $linkEntity;
             $link = new $class();
             $link->setPackageName($linkPackageName);
             $link->setPackageVersion($linkPackageVersion);
             $version->{'add' . $linkType . 'Link'}($link);
             $link->setVersion($version);
             $em->persist($link);
         }
     }
     if (!$package->getVersions()->contains($version)) {
         $package->addVersions($version);
     }
 }
 /**
  * Returns the installation path of a package
  * We don't use the parent class for this because Magento Core should never be installed in  the modman-root-dir
  *
  * @param  PackageInterface $package
  * @return string           path
  */
 public function getInstallPath(PackageInterface $package)
 {
     $targetDir = $package->getTargetDir();
     $installPath = $this->getPackageBasePath($package) . ($targetDir ? '/' . $targetDir : '');
     // Make install path absolute. This is needed in the symlink deploy strategies.
     if (DIRECTORY_SEPARATOR !== $installPath[0] && $installPath[1] !== ':') {
         $installPath = getcwd() . "/{$installPath}";
     }
     return $installPath;
 }
Esempio n. 21
0
 /**
  * {@inheritDoc}
  */
 public function getInstallPath(PackageInterface $package)
 {
     $targetDir = $package->getTargetDir();
     return ($this->vendorDir ? $this->vendorDir . '/' : '') . $package->getPrettyName() . ($targetDir ? '/' . $targetDir : '');
 }
Esempio n. 22
0
 /**
  * @param PackageInterface $package
  * @return string
  */
 private function getPackageSourceDirectory(PackageInterface $package)
 {
     $path = sprintf("%s/%s", $this->config->getVendorDir(), $package->getPrettyName());
     $targetDir = $package->getTargetDir();
     if ($targetDir) {
         $path = sprintf("%s/%s", $path, $targetDir);
     }
     $path = realpath($path);
     return $path;
 }
Esempio n. 23
0
 /**
  * @param string $cacheDir
  * @param string $targetDir
  * @param \Composer\Package\PackageInterface $package
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  * @param \Composer\Util\ProcessExecutor $process
  * @return string
  * @throws \Exception
  */
 protected function createZipFile($cacheDir, $targetDir, \Composer\Package\PackageInterface $package, OutputInterface $output, \Composer\Util\ProcessExecutor $process)
 {
     $zipfileName = str_replace('/', '_', strtolower($package->getPrettyName()));
     if ($package->getDistType() === 'pear') {
         $rootPath = $cacheDir;
         $zipPath = escapeshellarg($package->getPrettyName());
     } else {
         if ($package->getTargetDir()) {
             $rootPath = $cacheDir . '/' . $package->getPrettyName() . '/' . $package->getTargetDir();
             $zipPath = '.';
         } else {
             $rootPath = $cacheDir . '/' . $package->getPrettyName();
             $zipPath = '.';
         }
     }
     $output->writeln('  - ' . $zipfileName . '.zip');
     if (!class_exists('ZipArchive')) {
         $command = 'cd ' . escapeshellarg($rootPath) . ' && zip -9 -r ' . escapeshellarg($targetDir . '/dists/' . $zipfileName . '.zip') . ' ' . $zipPath;
         $result = $process->execute($command);
         if ($result) {
             throw new \Exception('could not create dist package for ' . $package->getName());
         }
     } else {
         $zipFile = $targetDir . '/dists/' . $zipfileName . '.zip';
         $zipArchive = new ZipArchive();
         $zipArchive->addExcludeDirectory('.svn');
         $zipArchive->setArchiveBaseDir($rootPath);
         if (($result = $zipArchive->open($zipFile, ZipArchive::OVERWRITE)) === TRUE) {
             $zipArchive->addDir($rootPath);
             $zipArchive->close();
         } else {
             throw new \Exception('could not create dist package for ' . $package->getName() . ' error code: ' . $result);
         }
     }
     return $zipfileName;
 }
Esempio n. 24
0
 /**
  * @param PackageInterface $package
  *
  * @throws \InvalidArgumentException Throws an exception, if the package has illegal settings.
  */
 protected function validatePackage(PackageInterface $package)
 {
     $autoload = $package->getAutoload();
     if (!empty($autoload['psr-4']) && null !== $package->getTargetDir()) {
         $name = $package->getName();
         $package->getTargetDir();
         throw new \InvalidArgumentException("PSR-4 autoloading is incompatible with the target-dir property, remove the target-dir in package '{$name}'.");
     }
     if (!empty($autoload['psr-4'])) {
         foreach ($autoload['psr-4'] as $namespace => $dirs) {
             if ($namespace !== '' && '\\' !== substr($namespace, -1)) {
                 throw new \InvalidArgumentException("psr-4 namespaces must end with a namespace separator, '{$namespace}' does not, use '{$namespace}\\'.");
             }
         }
     }
 }
Esempio n. 25
0
 private function updateInformation(Package $package, PackageInterface $data, $flags)
 {
     $em = $this->doctrine->getEntityManager();
     $version = new Version();
     $version->setNormalizedVersion($data->getVersion());
     // check if we have that version yet
     foreach ($package->getVersions() as $existingVersion) {
         if ($existingVersion->getNormalizedVersion() === $version->getNormalizedVersion()) {
             if ($existingVersion->getDevelopment() || $flags & self::UPDATE_TAGS) {
                 $version = $existingVersion;
                 break;
             }
             // mark it updated to avoid it being pruned
             $existingVersion->setUpdatedAt(new \DateTime());
             return;
         }
     }
     $version->setName($package->getName());
     $version->setVersion($data->getPrettyVersion());
     $version->setDevelopment($data->isDev());
     $em->persist($version);
     $version->setDescription($data->getDescription());
     $package->setDescription($data->getDescription());
     $version->setHomepage($data->getHomepage());
     $version->setLicense($data->getLicense() ?: array());
     $version->setPackage($package);
     $version->setUpdatedAt(new \DateTime());
     $version->setReleasedAt($data->getReleaseDate());
     if ($data->getSourceType()) {
         $source['type'] = $data->getSourceType();
         $source['url'] = $data->getSourceUrl();
         $source['reference'] = $data->getSourceReference();
         $version->setSource($source);
     }
     if ($data->getDistType()) {
         $dist['type'] = $data->getDistType();
         $dist['url'] = $data->getDistUrl();
         $dist['reference'] = $data->getDistReference();
         $dist['shasum'] = $data->getDistSha1Checksum();
         $version->setDist($dist);
     }
     if ($data->getType()) {
         $version->setType($data->getType());
         if ($data->getType() && $data->getType() !== $package->getType()) {
             $package->setType($data->getType());
         }
     }
     $version->setTargetDir($data->getTargetDir());
     $version->setAutoload($data->getAutoload());
     $version->setExtra($data->getExtra());
     $version->setBinaries($data->getBinaries());
     $version->setIncludePaths($data->getIncludePaths());
     $version->setSupport($data->getSupport());
     $version->getTags()->clear();
     if ($data->getKeywords()) {
         foreach ($data->getKeywords() as $keyword) {
             $tag = Tag::getByName($em, $keyword, true);
             if (!$version->getTags()->contains($tag)) {
                 $version->addTag($tag);
             }
         }
     }
     $authorRepository = $this->doctrine->getRepository('PackagistWebBundle:Author');
     $version->getAuthors()->clear();
     if ($data->getAuthors()) {
         foreach ($data->getAuthors() as $authorData) {
             $author = null;
             // skip authors with no information
             if (empty($authorData['email']) && empty($authorData['name'])) {
                 continue;
             }
             if (!empty($authorData['email'])) {
                 $author = $authorRepository->findOneByEmail($authorData['email']);
             }
             if (!$author && !empty($authorData['homepage'])) {
                 $author = $authorRepository->findOneBy(array('name' => $authorData['name'], 'homepage' => $authorData['homepage']));
             }
             if (!$author && !empty($authorData['name'])) {
                 $author = $authorRepository->findOneByNameAndPackage($authorData['name'], $package);
             }
             if (!$author) {
                 $author = new Author();
                 $em->persist($author);
             }
             foreach (array('email', 'name', 'homepage', 'role') as $field) {
                 if (isset($authorData[$field])) {
                     $author->{'set' . $field}($authorData[$field]);
                 }
             }
             $author->setUpdatedAt(new \DateTime());
             if (!$version->getAuthors()->contains($author)) {
                 $version->addAuthor($author);
             }
             if (!$author->getVersions()->contains($version)) {
                 $author->addVersion($version);
             }
         }
     }
     // handle links
     foreach ($this->supportedLinkTypes as $linkType => $opts) {
         $links = array();
         foreach ($data->{$opts['method']}() as $link) {
             $constraint = $link->getPrettyConstraint();
             if (false !== strpos($constraint, '~')) {
                 $constraint = str_replace(array('[', ']'), '', $link->getConstraint());
                 $constraint = preg_replace('{(\\d\\.\\d)(\\.0)+(?=$|,|-)}', '$1', $constraint);
                 $constraint = preg_replace('{([><=,]) }', '$1', $constraint);
                 $constraint = preg_replace('{(<[0-9.]+)-dev}', '$1', $constraint);
             }
             if (false !== strpos($constraint, ',') && false !== strpos($constraint, '@')) {
                 $constraint = preg_replace_callback('{([><]=?\\s*[^@]+?)@([a-z]+)}i', function ($matches) {
                     if ($matches[2] === 'stable') {
                         return $matches[1];
                     }
                     return $matches[1] . '-' . $matches[2];
                 }, $constraint);
             }
             $links[$link->getTarget()] = $constraint;
         }
         foreach ($version->{'get' . $linkType}() as $link) {
             // clear links that have changed/disappeared (for updates)
             if (!isset($links[$link->getPackageName()]) || $links[$link->getPackageName()] !== $link->getPackageVersion()) {
                 $version->{'get' . $linkType}()->removeElement($link);
                 $em->remove($link);
             } else {
                 // clear those that are already set
                 unset($links[$link->getPackageName()]);
             }
         }
         foreach ($links as $linkPackageName => $linkPackageVersion) {
             $class = 'Packagist\\WebBundle\\Entity\\' . $opts['entity'];
             $link = new $class();
             $link->setPackageName($linkPackageName);
             $link->setPackageVersion($linkPackageVersion);
             $version->{'add' . $linkType . 'Link'}($link);
             $link->setVersion($version);
             $em->persist($link);
         }
     }
     // handle suggests
     if ($suggests = $data->getSuggests()) {
         foreach ($version->getSuggest() as $link) {
             // clear links that have changed/disappeared (for updates)
             if (!isset($suggests[$link->getPackageName()]) || $suggests[$link->getPackageName()] !== $link->getPackageVersion()) {
                 $version->getSuggest()->removeElement($link);
                 $em->remove($link);
             } else {
                 // clear those that are already set
                 unset($suggests[$link->getPackageName()]);
             }
         }
         foreach ($suggests as $linkPackageName => $linkPackageVersion) {
             $link = new SuggestLink();
             $link->setPackageName($linkPackageName);
             $link->setPackageVersion($linkPackageVersion);
             $version->addSuggestLink($link);
             $link->setVersion($version);
             $em->persist($link);
         }
     }
     if (!$package->getVersions()->contains($version)) {
         $package->addVersions($version);
     }
 }