*/
protected $archive = null;
+ /**
+ * throw SystemExceptions rather than PackageValidationException
+ * @var boolean
+ */
+ protected $legacyExceptions = true;
+
/**
* package object of an existing package
* @var \wcf\data\package\Package
$this->package = $package;
}
+ /**
+ * Disables legacy exceptions, throwing PackageValidationException instead of SystemException.
+ */
+ public function disableLegacyExceptions() {
+ $this->legacyExceptions = false;
+ }
+
/**
* Sets associated package object.
*
public function openArchive() {
// check whether archive exists and is a TAR archive
if (!file_exists($this->archive)) {
- throw new SystemException("unable to find package file '".$this->archive."'", PackageValidationException::FILE_NOT_FOUND);
+ if ($this->legacyExceptions) {
+ throw new SystemException("unable to find package file '".$this->archive."'");
+ }
+ else {
+ throw new PackageValidationException(PackageValidationException::FILE_NOT_FOUND, array('archive' => $this->archive));
+ }
}
// open archive and read package information
// search package.xml in package archive
// throw error message if not found
if ($this->tar->getIndexByFilename(self::INFO_FILE) === false) {
- throw new SystemException("package information file '".(self::INFO_FILE)."' not found in '".$this->archive."'", PackageValidationException::MISSING_PACKAGE_XML);
+ if ($this->legacyExceptions) {
+ throw new SystemException("package information file '".(self::INFO_FILE)."' not found in '".$this->archive."'");
+ }
+ else {
+ throw new PackageValidationException(PackageValidationException::MISSING_PACKAGE_XML, array('archive' => $this->archive));
+ }
}
// extract package.xml, parse XML
$packageName = $package->getAttribute('name');
if (!Package::isValidPackageName($packageName)) {
// package name is not a valid package identifier
- throw new SystemException("'".$packageName."' is not a valid package name.");
+ if ($this->legacyExceptions) {
+ throw new SystemException("'".$packageName."' is not a valid package name.");
+ }
+ else {
+ throw new PackageValidationException(PackageValidationException::INVALID_PACKAGE_NAME, array('packageName' => $packageName));
+ }
}
$this->packageInfo['name'] = $packageName;
case 'version':
if (!Package::isValidVersion($element->nodeValue)) {
- throw new SystemException("package version '".$element->nodeValue."' is invalid", PackageValidationException::INVALID_PACKAGE_VERSION);
+ if ($this->legacyExceptions) {
+ throw new SystemException("package version '".$element->nodeValue."' is invalid");
+ }
+ else {
+ throw new PackageValidationException(PackageValidationException::INVALID_PACKAGE_VERSION, array('packageVersion' => $element->nodeValue));
+ }
}
$this->packageInfo['version'] = $element->nodeValue;
$elements = $xpath->query('child::ns:requiredpackages/ns:requiredpackage', $package);
foreach ($elements as $element) {
if (!Package::isValidPackageName($element->nodeValue)) {
- throw new SystemException("'".$element->nodeValue."' is not a valid package name.", PackageValidationException::INVALID_PACKAGE_NAME);
+ throw new SystemException("'".$element->nodeValue."' is not a valid package name.");
}
// read attributes
$elements = $xpath->query('child::ns:optionalpackages/ns:optionalpackage', $package);
foreach ($elements as $element) {
if (!Package::isValidPackageName($element->nodeValue)) {
- throw new SystemException("'".$element->nodeValue."' is not a valid package name.", PackageValidationException::INVALID_PACKAGE_NAME);
+ throw new SystemException("'".$element->nodeValue."' is not a valid package name.");
}
// read attributes
$elements = $xpath->query('child::ns:excludedpackages/ns:excludedpackage', $package);
foreach ($elements as $element) {
if (!Package::isValidPackageName($element->nodeValue)) {
- throw new SystemException("'".$element->nodeValue."' is not a valid package name.", PackageValidationException::INVALID_PACKAGE_NAME);
+ throw new SystemException("'".$element->nodeValue."' is not a valid package name.");
}
// read attributes