/** * Get file types where mentioned validator * * @param AppConfig $config * @return array */ public function getValidatorFileTypes(AppConfig $config) { if ($this->fileTypes === null) { $nodes = $config->getNodesExpr(FileType::XPATH_FILE_TYPES); $this->fileTypes = array_keys($nodes); } return $this->fileTypes; }
/** * Set up test model */ public static function setUpBeforeClass() { //init config Config::initInstance(['file' => PROJECT_ROOT . '/config/root.xml']); Config::setSrcRootDir(PROJECT_ROOT); Config::mergeExtraConfig(); }
/** * 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); }
/** * Set up test model */ public static function setUpBeforeClass() { Config::initInstance(['file' => PROJECT_ROOT . '/config/root.xml']); Config::setSrcRootDir(PROJECT_ROOT); $vcsAdapter = self::getVcsAdapterMock(); /** @var PreCommit $preCommit */ $preCommit = Processor::factory('pre-commit', $vcsAdapter); $preCommit->setCodePath(self::getCodePath())->setFiles([self::$classTest]); $preCommit->process(); self::$model = $preCommit; }
/** * Set up test model */ public static function setUpBeforeClass() { //init config object Config::initInstance(['file' => PROJECT_ROOT . '/config/root.xml']); Config::setSrcRootDir(PROJECT_ROOT); Config::mergeExtraConfig(); $vcsAdapter = self::getVcsAdapterMock(); /** @var Processor\PreCommit $processor */ $processor = Processor::factory('pre-commit', ['vcs' => $vcsAdapter]); $processor->setCodePath(PROJECT_ROOT)->setFiles([self::$fileTest]); $processor->process(); self::$model = $processor; }
/** * 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 config model * * @return Config * @throws \PreCommit\Exception */ protected function getConfig() { return Config::getInstance(); }
/** * Get issue cache directories * * @return array * @throws \PreCommit\Exception */ protected function getCachedIssueDirs() { $finder = new Finder(); $list = array(); /** @var \Symfony\Component\Finder\SplFileInfo $file */ foreach ($finder->directories()->in(ConfigInstance::getCacheDir())->path('/^issue-.*/') as $file) { $list[] = $file->getRealpath(); } return $list; }
/** * Load config * * @param string $file * @return Config * @throws \PreCommit\Exception */ protected function loadConfig($file) { if (!file_exists($file)) { //@startSkipCommitHooks $xml = <<<XML <?xml version="1.0"?> <config> </config> XML; //@finishSkipCommitHooks $this->writeContent($file, $xml); } $config = Config::loadInstance(array('file' => $file), false); return $config; }
/** * 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; }
/** * Test get node */ public function testGetMultiNode() { $result = self::$model->getMultiNode('list/same', true, false); $this->assertEquals(['same1', 'same2', 'same3', 'same4'], $result); }
/** * 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; }
*/ !defined('COMMIT_HOOKS_ROOT') && define('COMMIT_HOOKS_ROOT', realpath(__DIR__ . '/..')); !defined('TEST_MODE') && define('TEST_MODE', false); !defined('GIT_BIN') && define('GIT_BIN', 'git'); set_include_path(implode(PATH_SEPARATOR, array(get_include_path(), COMMIT_HOOKS_ROOT . '/src/lib'))); //init autoloader require_once __DIR__ . '/../bin/autoload-init.php'; //Get VCS type $vcs = isset($vcs) ? $vcs : 'git'; //Get VCS files $vcsFiles = isset($vcsFiles) ? $vcsFiles : null; //load config if (!isset($rootConfigFile)) { $rootConfigFile = COMMIT_HOOKS_ROOT . '/src/config/root.xml'; } $config = \PreCommit\Config::initInstance(array('file' => $rootConfigFile)); //prepare head block for output $output = array(); $output['head'] = 'PHP CommitHooks v' . $config->getNode('version'); $output['head'] .= PHP_EOL; $output['head'] .= 'Please report all hook bugs to the GitHub project.'; $output['head'] .= PHP_EOL; $output['head'] .= 'http://github.com/andkirby/commithook'; $output['head'] .= PHP_EOL . PHP_EOL; //Process hook name $supportedHooks = $config->getNodeArray('supported_hooks'); $supportedHooks = $supportedHooks['hook']; if (empty($hookFile)) { //try to get hook name from backtrace $backtrace = debug_backtrace(); if (isset($backtrace[0]['file'])) {
/** * Get xpath value * * @param string $xpath * @return array|null */ protected function getValue($xpath) { return Config::getInstance()->getNode($xpath); }
<?php // @codingStandardsIgnoreFile /** * @license https://raw.githubusercontent.com/andkirby/commithook/master/LICENSE.md */ define('PROJECT_ROOT', realpath(__DIR__ . '/../..')); !defined('GIT_BIN') && define('GIT_BIN', 'git'); /** @var Composer\Autoload\ClassLoader $autoloader */ require realpath(__DIR__ . '/../../..') . '/bin/autoload-init.php'; //load config try { \PreCommit\Config::setSrcRootDir(__DIR__ . '/../../'); $config = \PreCommit\Config::initInstance(array('file' => __DIR__ . '/root.xml')); \PreCommit\Config::mergeExtraConfig(); } catch (\Exception $e) { echo $e; exit(1); }
/** * Get cached config files * * @return array * @throws \PreCommit\Exception */ protected function getCachedConfigFiles() { $finder = new Finder(); $list = []; foreach ($finder->files()->in(ConfigInstance::getCacheDir())->name('*.xml') as $file) { $list[] = $file->getRealpath(); } return $list; }
/** * 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.'); } }