From 3a851b4059c5a9e8494c624254a0d0ce4eda3122 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 17 Apr 2011 21:36:05 +0200 Subject: [PATCH] Define an interface for packages and move package code to separate namespace. Ids are no longer needed, they are internal to the solver and not a part of packages. --- .../Package.php => Package/BasePackage.php} | 27 +--- .../MemoryPackage.php | 4 +- src/Composer/Package/PackageInterface.php | 116 ++++++++++++++++++ 3 files changed, 123 insertions(+), 24 deletions(-) rename src/Composer/{DependencyResolver/Package.php => Package/BasePackage.php} (89%) rename src/Composer/{DependencyResolver => Package}/MemoryPackage.php (98%) create mode 100644 src/Composer/Package/PackageInterface.php diff --git a/src/Composer/DependencyResolver/Package.php b/src/Composer/Package/BasePackage.php similarity index 89% rename from src/Composer/DependencyResolver/Package.php rename to src/Composer/Package/BasePackage.php index 7b3efab04..c64b67c61 100644 --- a/src/Composer/DependencyResolver/Package.php +++ b/src/Composer/Package/BasePackage.php @@ -9,46 +9,29 @@ * file that was distributed with this source code. */ -namespace Composer\DependencyResolver; +namespace Composer\Package; use Composer\DependencyResolver\RelationConstraint\RelationConstraintInterface; /** + * Base class for packages providing name storage and default match implementation + * * @author Nils Adermann */ -abstract class Package +abstract class Package implements PackageInterface { protected $name; protected $id; - static public $incremental_id = 1; - /** * All descendents' constructors should call this parent constructor * * @param string $name The package's name - * @param int $id A positive unique id, zero to auto generate */ - public function __construct($name, $id = 0) + public function __construct($name) { $this->name = $name; - if (!$id) { - $this->id = self::$incremental_id++; - } else { - $this->id = $id; - self::$incremental_id = $id + 1; - } - } - - /** - * Returns the package's identifier - * - * @return int Package id - a unique positive number - */ - public function getId() - { - return $this->id; } /** diff --git a/src/Composer/DependencyResolver/MemoryPackage.php b/src/Composer/Package/MemoryPackage.php similarity index 98% rename from src/Composer/DependencyResolver/MemoryPackage.php rename to src/Composer/Package/MemoryPackage.php index 28496a8f3..f2af5bc48 100644 --- a/src/Composer/DependencyResolver/MemoryPackage.php +++ b/src/Composer/Package/MemoryPackage.php @@ -9,14 +9,14 @@ * file that was distributed with this source code. */ -namespace Composer\DependencyResolver; +namespace Composer\Package; /** * A package with setters for all members to create it dynamically in memory * * @author Nils Adermann */ -class MemoryPackage extends Package +class MemoryPackage extends BasePackage { protected $releaseType; protected $version; diff --git a/src/Composer/Package/PackageInterface.php b/src/Composer/Package/PackageInterface.php new file mode 100644 index 000000000..294fea6d0 --- /dev/null +++ b/src/Composer/Package/PackageInterface.php @@ -0,0 +1,116 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Package; + +use Composer\DependencyResolver\RelationConstraint\RelationConstraintInterface; + +/** + * @author Nils Adermann + */ +interface PackageInterface +{ + /** + * Returns the package's name without version info, thus not a unique identifier + * + * @return string package name + */ + function getName(); + + /** + * Returns a set of names that could refer to this package + * + * No version or release type information should be included in any of the + * names. Provided or replaced package names need to be returned as well. + * + * @return array An array of strings refering to this package + */ + function getNames(); + + /** + * Checks if the package matches the given constraint directly or through + * provided or replaced packages + * + * @param string $name Name of the package to be matched + * @param RelationConstraintInterface $constraint The constraint to verify + * @return bool Whether this package matches the name and constraint + */ + function matches($name, RelationConstraintInterface $constraint); + + /** + * Returns the release type of this package, e.g. stable or beta + * + * @return string The release type + */ + function getReleaseType(); + + /** + * Returns the version of this package + * + * @return string version + */ + function getVersion(); + + /** + * Returns a set of relations to packages which need to be installed before + * this package can be installed + * + * @return array An array of package relations defining required packages + */ + function getRequires(); + + /** + * Returns a set of relations to packages which must not be installed at the + * same time as this package + * + * @return array An array of package relations defining conflicting packages + */ + function getConflicts(); + + /** + * Returns a set of relations to virtual packages that are provided through + * this package + * + * @return array An array of package relations defining provided packages + */ + function getProvides(); + + /** + * Returns a set of relations to packages which can alternatively be + * satisfied by installing this package + * + * @return array An array of package relations defining replaced packages + */ + function getReplaces(); + + /** + * Returns a set of relations to packages which are recommended in + * combination with this package. + * + * @return array An array of package relations defining recommended packages + */ + function getRecommends(); + + /** + * Returns a set of relations to packages which are suggested in combination + * with this package. + * + * @return array An array of package relations defining suggested packages + */ + function getSuggests(); + + /** + * Converts the package into a readable and unique string + * + * @return string + */ + function __toString(); +}