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 * list of known package installation plugins
23 protected $packageInstallationPlugins = array();
26 * package validation archive object
27 * @var \wcf\system\package\validation\PackageValidationArchive
29 protected $packageValidationArchive = null;
32 * virtual package list containing package => packageVersion
35 protected $virtualPackageList = array();
38 * @see \wcf\system\SingletonFactory::init()
40 protected function init() {
41 $pipList = new PackageInstallationPluginList();
42 $pipList->readObjects();
43 foreach ($pipList as $pip) {
44 $this->packageInstallationPlugins
[$pip->pluginName
] = $pip->className
;
49 * Validates given archive for existance and ability to be installed/updated. If you set the
50 * second parameter $deepInspection to "false", the system will only check if the archive
51 * looks fine, this is useful for a rough check during upload when a more detailed check will
52 * be performed afterwards.
54 * @param string $archive
55 * @param boolean $deepInspection
58 public function validate($archive, $deepInspection = true) {
59 $this->virtualPackageList
= array();
60 $this->packageValidationArchive
= new PackageValidationArchive($archive);
62 return $this->packageValidationArchive
->validate($deepInspection);
66 * Returns package validation archive object.
68 * @return \wcf\system\package\validation\PackageValidationArchive
70 public function getPackageValidationArchive() {
71 return $this->packageValidationArchive
;
75 * Adds a virtual package with the corresponding version, if the package is already known,
76 * the higher version number will be stored.
78 * @param string $package
79 * @param string $packageVersion
82 public function addVirtualPackage($package, $packageVersion) {
83 if (isset($this->virtualPackageList
[$package])) {
84 if (Package
::compareVersion($packageVersion, $this->virtualPackageList
[$package], '<')) {
89 $this->virtualPackageList
[$package] = $packageVersion;
95 * Returns the version number of a virtual package or null if it doesn't exist.
97 * @param string $package
100 public function getVirtualPackage($package) {
101 if (isset($this->virtualPackageList
[$package])) {
102 return $this->virtualPackageList
[$package];
109 * Returns the iteratable package archive list.
111 * @return \RecursiveIteratorIterator
113 public function getPackageValidationArchiveList() {
114 $packageValidationArchive = new PackageValidationArchive('');
115 $packageValidationArchive->setChildren(array($this->packageValidationArchive
));
117 return new \
RecursiveIteratorIterator($packageValidationArchive, \RecursiveIteratorIterator
::SELF_FIRST
);
121 * Recursively traverses the package validation archives and returns the first exception message.
125 public function getExceptionMessage() {
126 foreach ($this->getPackageValidationArchiveList() as $packageArchive) {
127 if ($packageArchive->getExceptionMessage()) {
128 return $packageArchive->getExceptionMessage();
136 * Validates an instruction against the corresponding package installation plugin.
138 * Please be aware that unknown PIPs will silently ignored and cause no error.
140 * @param \wcf\data\package\PackageArchive $archive
142 * @param string $instruction
145 public function validatePackageInstallationPluginInstruction(PackageArchive
$archive, $pip, $instruction) {
146 if (isset($this->packageInstallationPlugins
[$pip])) {
147 return call_user_func(array($this->packageInstallationPlugins
[$pip], 'isValid'), $archive, $instruction);