/** * Constructor. Set path to PHP interpreter * * @param array $options * @throws Exception */ public function __construct(array $options) { $interpreter = (string) Config::getInstance()->getNode('code/interpreter/php'); if (empty($interpreter)) { throw new Exception('Path to PHP interpreter is not set.'); } $this->interpreterPath = $interpreter; parent::__construct($options); }
/** * Get password * * @param string $trackerType * @return null|string * @throws \PreCommit\Exception */ public function getPassword($trackerType) { try { $password = Config::getInstance()->getNode('tracker/' . $trackerType . '/password'); if (!$password) { return null; } if (strlen($password) < $this->maxLength) { //password doesn't look like encrypted return $password; } return $this->decrypt($password) ?: null; } catch (Exception $e) { throw new UserException('Cannot get password of tracker.', 0, $e); } }
/** * Get xpath value * * @param string $xpath * @return array|null */ protected function getValue($xpath) { return Config::getInstance()->getNode($xpath); }
/** * Get config model * * @return Config * @throws \PreCommit\Exception */ protected function getConfig() { return Config::getInstance(); }
/** * Get configuration of underscore using in non-public methods * * @return bool */ protected function useUnderscoreInNonPublic() { // use old value for backward compatibility $old = Config::getInstance()->getNode('validators/CodingStandard/underscore_in_non_public'); if ($old) { return (bool) $old; } return (bool) Config::getInstance()->getNode('validators/CodingStandard-UnderscoreInMethod/underscore_in_non_public'); }
/** * Get base config (without project files) * * @return Config */ public function getConfigBase() { static $config; if (null === $config) { //TODO Make single load $config = Config::initInstance(['file' => $this->commithookDir . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'root.xml']); if (!Config::loadCache()) { Config::mergeExtraConfig(); } $config = Config::getInstance(); } return $config; }
/** * Get standard config file * * @return string */ protected function getStandardConfigDir() { $dir = Config::getInstance()->getNode('validators/CodeSniffer/rule/directory'); if (realpath($dir)) { return $dir; } $dir = Config::getProjectDir() . DIRECTORY_SEPARATOR . trim($dir, '\\/'); if (realpath($dir)) { return $dir; } return null; }
/** * Check if tracker type is defined * * @throws Exception */ protected function validateCommand() { if (!Config::getInstance()->getNode('tracker/type')) { throw new Exception('Tracker type is not defined.' . PHP_EOL . 'Please define it via command "commithook config --project tracker %value%"' . PHP_EOL . 'Allowed values: jira, github.'); } }