GrumPHP\Util\Regex::addPatternModifier PHP Метод

addPatternModifier() публичный Метод

public addPatternModifier ( string $modifier )
$modifier string
    public function addPatternModifier($modifier)
    {
        if (!strlen($modifier) == 1 || !strstr(self::ALLOWED_MODIFIERS, $modifier)) {
            throw new RuntimeException('Invalid regex modifier: ' . $modifier);
        }
        // Find all modifiers of current regex:
        $modifiersPattern = '/([' . self::ALLOWED_MODIFIERS . ']*$)/';
        preg_match($modifiersPattern, $this->regex, $matches);
        $modifiers = $matches[0];
        // Skip if the modifier is already available
        if (strstr($modifiers, $modifier) !== false) {
            return;
        }
        $this->regex .= $modifier;
    }

Usage Example

Пример #1
0
 /**
  * @param ContextInterface|GitCommitMsgContext $context
  */
 public function run(ContextInterface $context)
 {
     $config = $this->getConfiguration();
     $commitMessage = $context->getCommitMessage();
     foreach ($config['matchers'] as $rule) {
         $regex = new Regex($rule);
         if ((bool) $config['case_insensitive']) {
             $regex->addPatternModifier('i');
         }
         if ((bool) $config['multiline']) {
             $regex->addPatternModifier('m');
         }
         if (!preg_match($regex->__toString(), $commitMessage)) {
             throw new RuntimeException(sprintf('The commit message does not match the rule: %s', $rule));
         }
     }
 }
All Usage Examples Of GrumPHP\Util\Regex::addPatternModifier