示例#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;
 }