예제 #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;
 }
예제 #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;
 }
예제 #3
0
 /**
  * Test non-match allowed list within protected path
  *
  * E.g.: test/11 should not match with test/1111
  */
 public function testTopProtectWithNoChildAllowed()
 {
     $match = new PathMatch();
     $match->setAllowedByDefault(true);
     $match->setAllowed(['test/11', 'test/22']);
     $match->setProtected(['test']);
     $this->assertFalse($match->test('test/33333/test.1'));
 }