2 namespace wcf\system\package\validation
;
3 use wcf\data\package\installation\plugin\PackageInstallationPluginList
;
4 use wcf\data\package\Package
;
5 use wcf\system\package\PackageArchive
;
6 use wcf\system\SingletonFactory
;
9 * Manages recursive validation of package archives.
11 * @author Alexander Ebert
12 * @copyright 2001-2014 WoltLab GmbH
13 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
14 * @package com.woltlab.wcf
15 * @subpackage system.package.validation
16 * @category Community Framework
18 class PackageValidationManager
extends SingletonFactory
{
20 * package validation archive object
21 * @var \wcf\system\package\validation\PackageValidationArchive
23 protected $packageValidationArchive = null;
26 * virtual package list containing package => packageVersion
29 protected $virtualPackageList = array();
32 * validation will only check if the primary package looks like it can be installed or updated
35 const VALIDATION_WEAK
= 0;
38 * validation will recursively check dependencies
41 const VALIDATION_RECURSIVE
= 1;
44 * validation will use the previously gathered exclusions and check them
47 const VALIDATION_EXCLUSION
= 2;
50 * Validates given archive for existance and ability to be installed/updated. If you set the
51 * second parameter $deepInspection to "false", the system will only check if the archive
52 * looks fine, this is useful for a rough check during upload when a more detailed check will
53 * be performed afterwards.
55 * @param string $archive
56 * @param boolean $deepInspection
59 public function validate($archive, $deepInspection) {
60 $this->virtualPackageList
= array();
61 $this->packageValidationArchive
= new PackageValidationArchive($archive);
63 if ($deepInspection) {
64 if (!$this->packageValidationArchive
->validate(self
::VALIDATION_RECURSIVE
)) {
68 return $this->packageValidationArchive
->validate(self
::VALIDATION_EXCLUSION
);
71 return $this->packageValidationArchive
->validate(self
::VALIDATION_WEAK
);
75 * Returns package validation archive object.
77 * @return \wcf\system\package\validation\PackageValidationArchive
79 public function getPackageValidationArchive() {
80 return $this->packageValidationArchive
;
84 * Adds a virtual package with the corresponding version, if the package is already known,
85 * the higher version number will be stored.
87 * @param string $package
88 * @param string $packageVersion
91 public function addVirtualPackage($package, $packageVersion) {
92 if (isset($this->virtualPackageList
[$package])) {
93 if (Package
::compareVersion($packageVersion, $this->virtualPackageList
[$package], '<')) {
98 $this->virtualPackageList
[$package] = $packageVersion;
104 * Returns the version number of a virtual package or null if it doesn't exist.
106 * @param string $package
109 public function getVirtualPackage($package) {
110 if (isset($this->virtualPackageList
[$package])) {
111 return $this->virtualPackageList
[$package];
118 * Returns the iteratable package archive list.
120 * @return \RecursiveIteratorIterator
122 public function getPackageValidationArchiveList() {
123 $packageValidationArchive = new PackageValidationArchive('');
124 $packageValidationArchive->setChildren(array($this->packageValidationArchive
));
126 return new \
RecursiveIteratorIterator($packageValidationArchive, \RecursiveIteratorIterator
::SELF_FIRST
);
130 * Recursively traverses the package validation archives and returns the first exception message.
134 public function getExceptionMessage() {
135 foreach ($this->getPackageValidationArchiveList() as $packageArchive) {
136 if ($packageArchive->getExceptionMessage()) {
137 return $packageArchive->getExceptionMessage();
145 * Recursively traverses the package validation archives and returns the first exception.
149 public function getException() {
150 foreach ($this->getPackageValidationArchiveList() as $packageArchive) {
151 if ($packageArchive->getException() !== null) {
152 return $packageArchive->getException();