/** * Gets the version of the GnuPG binary * * @return string a version number string containing the version of GnuPG * being used. This value is suitable to use with PHP's * version_compare() function. * * @throws Crypt_GPG_Exception if an unknown or unexpected error occurs. * Use the <kbd>debug</kbd> option and file a bug report if these * exceptions occur. * * @throws Crypt_GPG_UnsupportedException if the provided binary is not * GnuPG or if the GnuPG version is less than 1.0.2. */ public function getVersion() { if ($this->_version == '') { $options = array('homedir' => $this->_homedir, 'binary' => $this->_binary, 'debug' => $this->_debug, 'agent' => $this->_agent); $engine = new self($options); $info = ''; // Set a garbage version so we do not end up looking up the version // recursively. $engine->_version = '1.0.0'; $engine->reset(); $engine->setOutput($info); $engine->setOperation('--version'); $engine->run(); $matches = array(); $expression = '#gpg \\(GnuPG[A-Za-z0-9/]*?\\) (\\S+)#'; if (preg_match($expression, $info, $matches) === 1) { $this->_version = $matches[1]; } else { throw new Crypt_GPG_Exception('No GnuPG version information provided by the binary "' . $this->_binary . '". Are you sure it is GnuPG?'); } if (version_compare($this->_version, self::MIN_VERSION, 'lt')) { throw new Crypt_GPG_Exception('The version of GnuPG being used (' . $this->_version . ') is not supported by Crypt_GPG. The minimum version ' . 'required by Crypt_GPG is ' . self::MIN_VERSION); } } return $this->_version; }
/** * Creates an instance of this exception. * * @param string $msg - Message. * @param int $exitCode - Exit Code. * @param array $output - Output. * @param string $cmd - Command executed. * @param array $arguments - Command arguments. * * @return CommandException */ public static function create(string $msg, int $exitCode, array $output, string $cmd, array $arguments = []) : CommandException { $e = new self($msg, $exitCode); $e->setOutput($output)->setCmd($cmd)->setArguments($arguments); return $e; }
/** * Gets the version of the GnuPG binary * * @return string a version number string containing the version of GnuPG * being used. This value is suitable to use with PHP's * version_compare() function. * * @throws Crypt_GPG_Exception if an unknown or unexpected error occurs. * Use the <kbd>debug</kbd> option and file a bug report if these * exceptions occur. * * @throws Crypt_GPG_UnsupportedException if the provided binary is not * GnuPG or if the GnuPG version is less than 1.0.2. */ public function getVersion() { if ($this->_version == '') { $options = array('homedir' => $this->_homedir, 'binary' => $this->_binary, 'debug' => $this->_debug); $engine = new self($options); $info = ''; // Set a garbage version so we do not end up looking up the version // recursively. $engine->_version = '1.0.0'; $engine->reset(); $engine->setOutput($info); $engine->setOperation('--version'); $engine->run(); $code = $this->getErrorCode(); if ($code !== Crypt_GPG::ERROR_NONE) { throw new Crypt_GPG_Exception('Unknown error getting GnuPG version information. Please ' . 'use the \'debug\' option when creating the Crypt_GPG ' . 'object, and file a bug report at ' . Crypt_GPG::BUG_URI, $code); } $matches = array(); $expression = '/gpg \\(GnuPG\\) (\\S+)/'; if (preg_match($expression, $info, $matches) === 1) { $this->_version = $matches[1]; } else { throw new Crypt_GPG_Exception('No GnuPG version information provided by the binary "' . $this->_binary . '". Are you sure it is GnuPG?'); } if (version_compare($this->_version, self::MIN_VERSION, 'lt')) { throw new Crypt_GPG_Exception('The version of GnuPG being used (' . $this->_version . ') is not supported by Crypt_GPG. The minimum version ' . 'required by Crypt_GPG is ' . self::MIN_VERSION); } } return $this->_version; }
/** * @param $data * @param string $root XML Root element name * @param string $version Root element version number * @param array $parameters Array of root element attributes * @param string $itemName Generic item name. * @return Response */ public static function xml($data, $root = 'root', $version = '1.0', array $parameters = array(), $itemName = 'item') { $in = new self(); $in->setData($data); $in->setOutput(new XML($root, $version, $parameters, $itemName)); return $in; }