Bladeren bron

Add prettyConstraint on Links

Jordi Boggiano 13 jaren geleden
bovenliggende
commit
52a9014f1a
2 gewijzigde bestanden met toevoegingen van 12 en 4 verwijderingen
  1. 11 1
      src/Composer/Package/Link.php
  2. 1 3
      src/Composer/Package/Loader/ArrayLoader.php

+ 11 - 1
src/Composer/Package/Link.php

@@ -34,12 +34,13 @@ class Link
      * @param LinkConstraintInterface $constraint  Constraint applying to the target of this link
      * @param string                  $description Used to create a descriptive string representation
      */
-    public function __construct($source, $target, LinkConstraintInterface $constraint = null, $description = 'relates to')
+    public function __construct($source, $target, LinkConstraintInterface $constraint = null, $description = 'relates to', $prettyConstraint = null)
     {
         $this->source = strtolower($source);
         $this->target = strtolower($target);
         $this->constraint = $constraint;
         $this->description = $description;
+        $this->prettyConstraint = $prettyConstraint;
     }
 
     public function getSource()
@@ -57,6 +58,15 @@ class Link
         return $this->constraint;
     }
 
+    public function getPrettyConstraint()
+    {
+        if (null === $this->prettyConstraint) {
+            throw new \UnexpectedValueException(sprintf('Link %s has been misconfigured and had no prettyConstraint given.', $this));
+        }
+
+        return $this->prettyConstraint;
+    }
+
     public function __toString()
     {
         return $this->source.' '.$this->description.' '.$this->target.' ('.$this->constraint.')';

+ 1 - 3
src/Composer/Package/Loader/ArrayLoader.php

@@ -143,10 +143,8 @@ class ArrayLoader
     {
         $links = array();
         foreach ($linksSpecs as $packageName => $constraint) {
-            $name = strtolower($packageName);
-
             $constraint = $this->versionParser->parseConstraints($constraint);
-            $links[]    = new Package\Link($srcPackageName, $packageName, $constraint, $description);
+            $links[]    = new Package\Link($srcPackageName, $packageName, $constraint, $description, $constraint);
         }
 
         return $links;