/** * 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; }
/** * static method to instantiate and build an operation * * @param string $firstOperand * @param string $operator * @param string $secondOperand * @param int $priority * * @return Operation|NULL * @access public */ public static function build($firstOperand = null, $operator = null, $secondOperand = null, $priority = 0) { $operation = new self(); $operation->setOperation($firstOperand, $operator, $secondOperand, $priority); return $operation; }
/** * 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; }