t1gor/Robots.txt-Parser-Class

View on GitHub
source/Parser/DirectiveProcessors/AbstractDirectiveProcessor.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php declare(strict_types=1);

namespace t1gor\RobotsTxtParser\Parser\DirectiveProcessors;

use Psr\Log\LoggerInterface;
use t1gor\RobotsTxtParser\Directive;
use t1gor\RobotsTxtParser\LogsIfAvailableTrait;

abstract class AbstractDirectiveProcessor implements DirectiveProcessorInterface {

    use LogsIfAvailableTrait;

    public function __construct(?LoggerInterface $logger = null) {
        $this->logger = $logger;
    }

    public function getLogger(): ?LoggerInterface {
        return $this->logger;
    }

    public function matches(string $line): bool {
        return (bool) preg_match('/^' . $this->getDirectiveName() . '\s*:\s+/isu', $line);
    }
}