Esempio n. 1
0
 /**
  * Get ability to process file
  *
  * @param string $content
  * @param string $file
  * @return bool
  */
 public function validate($content, $file)
 {
     if (!$file) {
         return false;
     }
     $matchSkip = new PathMatch();
     $matchSkip->setAllowed($this->getPathList(self::XPATH_SKIP_PATH));
     if ($matchSkip->test($file) || $this->isExtensionSkipped($file)) {
         /**
          * Return FALSE as file is not allowed to validate, ie should be skipped
          *
          * @see \PreCommit\Processor\PreCommit::process()
          */
         return false;
     }
     $match = new PathMatch();
     $match->setAllowedByDefault($this->getValue(self::XPATH_ALLOW_BY_DEFAULT));
     $match->setAllowed($this->getPathList(self::XPATH_ALLOW_PATH));
     $match->setProtected($this->getPathList(self::XPATH_PROTECT_PATH));
     if ($match->test($file)) {
         return true;
     }
     if (!$match->getMatch() && !$match->getAllowedByDefault()) {
         $this->addError($file, self::PROTECTED_ALL);
     } else {
         $this->addError($file, self::PROTECTED_PATH, $match->getMatch());
     }
     return false;
 }
Esempio n. 2
0
 /**
  * Get path matcher
  *
  * @return PathMatch
  */
 protected function getPathMatcher()
 {
     if ($this->matcher === null) {
         $this->matcher = new PathMatch();
         $this->matcher->setAllowedByDefault(false)->setAllowed($this->getPaths('required'))->setProtected($this->getPaths('ignored'));
     }
     return $this->matcher;
 }
Esempio n. 3
0
 /**
  * Check
  *
  * @param string $file
  * @return bool
  */
 protected function isLicenseRequired($file)
 {
     $matcher = new PathMatch();
     return $matcher->setAllowed($this->getPaths('required'))->setProtected($this->getPaths('ignored'))->test($file);
 }
Esempio n. 4
0
 /**
  * Test simple match with recursive asterisk (**)
  *
  * E.g.: test/11 should not match with test/1111
  */
 public function testMatchAsteriskDirectoryNoSlash()
 {
     $match = new PathMatch();
     $match->setAllowed(['test/*/11']);
     $this->assertTrue($match->test('test/a/11/test.1'));
     $this->assertTrue($match->test('test/a/11'));
     $this->assertFalse($match->test('test/a/11111'));
 }