Completed
Push — master ( 0cbd7a...258693 )
by Jan-Petter
04:51
created

Cache::debug()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
/**
3
 * vipnytt/RobotsTxtParser
4
 *
5
 * @link https://github.com/VIPnytt/RobotsTxtParser
6
 * @license https://github.com/VIPnytt/RobotsTxtParser/blob/master/LICENSE The MIT License (MIT)
7
 */
8
9
namespace vipnytt\RobotsTxtParser;
10
11
use PDO;
12
use vipnytt\RobotsTxtParser\Client\Cache\ManagerInterface;
13
use vipnytt\RobotsTxtParser\Exceptions\ClientException;
14
use vipnytt\RobotsTxtParser\Handler\DatabaseHandler;
15
use vipnytt\RobotsTxtParser\Parser\UriParser;
16
17
/**
18
 * Class Cache
19
 *
20
 * @see https://github.com/VIPnytt/RobotsTxtParser/blob/master/docs/methods/Cache.md for documentation
21
 * @package vipnytt\RobotsTxtParser
22
 */
23
class Cache implements RobotsTxtInterface
24
{
25
    /**
26
     * Handler
27
     * @var ManagerInterface
28
     */
29
    private $handler;
30
31
    /**
32
     * Cache constructor.
33
     *
34
     * @param PDO $pdo
35
     * @param array $curlOptions
36
     * @param int|null $byteLimit
37
     */
38
    public function __construct(PDO $pdo, array $curlOptions = [], $byteLimit = self::BYTE_LIMIT)
39
    {
40
        $handler = new DatabaseHandler($pdo);
41
        $this->handler = $handler->cacheManager($curlOptions, $byteLimit);
42
    }
43
44
    /**
45
     * Parser client
46
     *
47
     * @param string $baseUri
48
     * @return TxtClient
49
     * @throws ClientException
50
     */
51
    public function client($baseUri)
52
    {
53
        $parser = new UriParser($baseUri);
54
        return $this->handler->client($parser->base());
55
    }
56
57
    /**
58
     * Process the update queue
59
     *
60
     * @param float|int|null $timeLimit
61
     * @param int|null $workerID
62
     * @return string[]
63
     */
64
    public function cron($timeLimit = null, $workerID = null)
65
    {
66
        return $this->handler->cron($timeLimit, $workerID);
67
    }
68
69
    /**
70
     * Clean the cache table
71
     *
72
     * @param int $delay - in seconds
73
     * @return bool
74
     */
75
    public function clean($delay = 3600)
76
    {
77
        return $this->handler->clean($delay);
78
    }
79
80
    /**
81
     * Get the RAW data
82
     *
83
     * @param string $baseUri
84
     * @return array
85
     */
86
    public function debug($baseUri)
87
    {
88
        $parser = new UriParser($baseUri);
89
        return $this->handler->debug($parser->base());
90
    }
91
92
    /**
93
     * Invalidate cache
94
     *
95
     * @param $baseUri
96
     * @return bool
97
     * @throws ClientException
98
     */
99
    public function invalidate($baseUri)
100
    {
101
        $parser = new UriParser($baseUri);
102
        return $this->handler->invalidate($parser->base());
103
    }
104
}
105