Back to Router class

Method detachRule

public bool
detachRule
(mixed $type, mixed $rule, mixed $stage = self::PROCESS_DURING)
Remove a rule
Parameters
  • string $type Type of rule to remove (parse or build)
  • callable $rule The rule to be removed.
  • string $stage The stage of the parse process that this should be added to. Possible values: 'preprocess', '' for the main parse process, 'postprocess'
Returns
  • bool Was a rule removed?
Since
  • 4.0.0
-
  • \InvalidArgumentException
Class: Router
Project: Joomla

Method detachRule - Source code

/**
 * Remove a rule
 *
 * @param   string    $type   Type of rule to remove (parse or build)
 * @param   callable  $rule   The rule to be removed.
 * @param   string    $stage  The stage of the parse process that
 *                             this should be added to. Possible values:
 *                             'preprocess', '' for the main parse process,
 *                             'postprocess'
 *
 * @return   boolean  Was a rule removed?
 *
 * @since   4.0.0
 * @throws  \InvalidArgumentException
 */
public function detachRule($type, $rule, $stage = self::PROCESS_DURING)
{
    if (!\in_array($type, array('parse', 'build'))) {
        throw new \InvalidArgumentException(sprintf('The %s type is not supported. (%s)', $type, __METHOD__));
    }
    if (!\array_key_exists($type . $stage, $this->rules)) {
        throw new \InvalidArgumentException(sprintf('The %s stage is not registered. (%s)', $stage, __METHOD__));
    }
    foreach ($this->rules[$type . $stage] as $id => $r) {
        if ($r == $rule) {
            unset($this->rules[$type . $stage][$id]);
            return true;
        }
    }
    return false;
}