2 namespace wcf\system\package\validation
;
3 use wcf\system\exception\SystemException
;
4 use wcf\system\package\PackageArchive
;
8 * Represents exceptions occured during validation of a package archive. This exception
9 * does not cause the details to be logged.
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 PackageValidationException
extends SystemException
{
20 * list of additional details for each subtype
23 protected $details = array();
26 * missing archive, expects the detail 'archive' and optionally 'targetArchive' (extracting archive from the archive)
29 const FILE_NOT_FOUND
= 1;
32 * missing package.xml, expects the detail 'archive'
35 const MISSING_PACKAGE_XML
= 2;
38 * package name violates WCF's schema, expects the detail 'packageName'
41 const INVALID_PACKAGE_NAME
= 3;
44 * package version violates WCF's schema, expects the detail 'packageVersion'
47 const INVALID_PACKAGE_VERSION
= 4;
50 * package contains no install instructions and an update is not possible, expects the detail 'packageName'
53 const NO_INSTALL_PATH
= 5;
56 * package is already installed and cannot be updated using current archive, expects the details 'packageName', 'packageVersion' and 'deliveredPackageVersion'
59 const NO_UPDATE_PATH
= 6;
62 * packages which exclude the current package, expects the detail 'packages' (list of \wcf\data\package\Package)
65 const EXCLUDING_PACKAGES
= 7;
68 * packages which are excluded by current package, expects the detail 'packages' (list of \wcf\data\package\Package)
71 const EXCLUDED_PACKAGES
= 8;
74 * package version is lower than the request version, expects the details 'packageName', 'packageVersion' and 'deliveredPackageVersion'
77 const INSUFFICIENT_VERSION
= 9;
80 * requirement is set but neither installed nor provided, expects the details 'packageName' and 'packageVersion'
83 const MISSING_REQUIREMENT
= 10;
86 * file reference for a package installation plugin is missing, expects the details 'pip', 'type' and 'value'
89 const MISSING_INSTRUCTION_FILE
= 11;
92 * Creates a new PackageArchiveValidationException.
94 * @param integer $code
95 * @param array<string> $details
97 public function __construct($code, array $details = array()) {
98 parent
::__construct($this->getLegacyMessage(), $code);
100 $this->details
= $details;
104 * Returns exception details.
106 * @return array<string>
108 public function getDetails() {
109 return $this->details
;
113 * Returns the readable error message.
117 public function getErrorMessage() {
118 return WCF
::getLanguage()->getDynamicVariable('wcf.acp.package.validation.errorCode.' . $this->getCode(), $this->getDetails());
122 * Returns legacy error messages to mimic WCF 2.0.x PackageArchive's exceptions.
126 protected function getLegacyMessage() {
127 switch ($this->getCode()) {
128 case self
::FILE_NOT_FOUND
:
129 if (isset($this->details
['targetArchive'])) {
130 return "tar archive '".$this->details
['targetArchive']."' not found in '".$this->details
['archive']."'.";
133 return "unable to find package file '".$this->details
['archive']."'";
136 case self
::MISSING_PACKAGE_XML
:
137 return "package information file '".PackageArchive
::INFO_FILE
."' not found in '".$this->details
['archive']."'";
140 case self
::INVALID_PACKAGE_NAME
:
141 return "'".$this->details
['packageName']."' is not a valid package name.";
144 case self
::INVALID_PACKAGE_VERSION
:
145 return "package version '".$this->details
['packageVersion']."' is invalid";
149 return 'Using getMessage() is discouraged, please use getErrorMessage() instead';
155 * @see \wcf\system\exception\LoggedException::logError()
157 protected function logError() {