/**
  * Creates and returns a new Exception instance.
  *
  * @param string $message The message itself
  * @param string $key The key for I18N
  * @return Faett_Core_Exceptions_InvalidPackageFileException
  */
 public static function create($message, $key = '')
 {
     // create a new message
     $e = new Faett_Core_Exceptions_InvalidPackageFileException($message);
     // set the message key
     $e->_setKey($key);
     // return the message
     return $e;
 }
 /**
  * (non-PHPdoc)
  * @see lib/Faett/Core/Interfaces/Faett_Core_Interfaces_Service#packageFile($package)
  */
 public function packageFile($package)
 {
     // initialize the archive
     $tar = new Archive_Tar($package);
     // try to load the content of the package2.xml file
     $contents = $tar->extractInString($packageFileName = 'package2.xml');
     // if not available, try to load from package.xml file
     if (!$contents) {
         $contents = $tar->extractInString($packageFileName = 'package.xml');
     }
     // initialize the parser for the package file and parse it
     $pkg = new PEAR_PackageFile_Parser_v2();
     $pkg->setConfig($this->getConfig());
     $pf = $pkg->parse($contents, $packageFileName);
     // check if errors occurs and throw an exception if necessary
     if (PEAR::isError($pf)) {
         throw Faett_Core_Exceptions_InvalidPackageFileException::create($pf->getMessage());
     }
     // validate the package
     if (!$pf->validate()) {
         // initialize the string for the errors and warnings
         $errors = '';
         // concatenate the message
         foreach ($pf->getValidationWarnings() as $warning) {
             $errors .= PHP_EOL . ucfirst($warning['level']) . ': ' . $warning['message'];
         }
         // throw an exception with the warnings
         throw Faett_Core_Exceptions_InvalidPackageFileException::create($errors);
     }
     // return the package file
     return $pf;
 }