for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Limonte;
class AdblockParser
{
private $rules;
public function __construct($rules = [])
$this->rules = [];
$this->addRules($rules);
}
/**
* @param string[] $rules
*/
public function addRules($rules)
foreach ($rules as $rule) {
try {
$this->rules[] = new AdblockRule($rule);
} catch (InvalidRuleException $e) {
// Sort rules, eceptions first
usort($this->rules, function ($a, $b) {
return (int)$a->isException() < (int)$b->isException();
});
* @param string|array $path
public function loadRules($path)
// single resource
if (is_string($path)) {
$content = @file_get_contents($path);
if ($content) {
$rules = preg_split("/(\r\n|\n|\r)/", $content);
// array of resources
} elseif (is_array($path)) {
foreach ($path as $item) {
$this->loadRules($item);
* @return []
[]
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.
public function getRules()
return $this->rules;
* @param string $url
*
* @return boolean
public function shouldBlock($url)
foreach ($this->rules as $rule) {
if ($rule->isComment() || $rule->isHtml()) {
continue;
if ($rule->matchUrl($url)) {
if ($rule->isException()) {
return false;
return true;
public function shouldNotBlock($url)
return !$this->shouldBlock($url);