1 | <?php |
||
19 | final class Browscap |
||
20 | { |
||
21 | /** |
||
22 | * Parser to use |
||
23 | * |
||
24 | * @var \BrowscapPHP\Parser\ParserInterface|null |
||
25 | */ |
||
26 | private $parser; |
||
27 | |||
28 | /** |
||
29 | * Formatter to use |
||
30 | * |
||
31 | * @var \BrowscapPHP\Formatter\FormatterInterface|null |
||
32 | */ |
||
33 | private $formatter; |
||
34 | |||
35 | /** |
||
36 | * The cache instance |
||
37 | * |
||
38 | * @var \BrowscapPHP\Cache\BrowscapCacheInterface|null |
||
39 | */ |
||
40 | private $cache; |
||
41 | |||
42 | /** |
||
43 | * @var \Psr\Log\LoggerInterface|null |
||
44 | */ |
||
45 | private $logger; |
||
46 | |||
47 | /** |
||
48 | * Set theformatter instance to use for the getBrowser() result |
||
49 | * |
||
50 | * @param \BrowscapPHP\Formatter\FormatterInterface $formatter |
||
51 | * |
||
52 | * @return \BrowscapPHP\Browscap |
||
53 | */ |
||
54 | 6 | public function setFormatter(Formatter\FormatterInterface $formatter) : self |
|
60 | |||
61 | /** |
||
62 | * @return \BrowscapPHP\Formatter\FormatterInterface |
||
63 | */ |
||
64 | 4 | public function getFormatter() : FormatterInterface |
|
72 | |||
73 | /** |
||
74 | * Gets a cache instance |
||
75 | * |
||
76 | * @return \BrowscapPHP\Cache\BrowscapCacheInterface |
||
77 | */ |
||
78 | 9 | public function getCache() : BrowscapCacheInterface |
|
92 | |||
93 | /** |
||
94 | * Sets a cache instance |
||
95 | * |
||
96 | * @param \BrowscapPHP\Cache\BrowscapCacheInterface|\WurflCache\Adapter\AdapterInterface $cache |
||
97 | * |
||
98 | * @throws \BrowscapPHP\Exception |
||
99 | * @return \BrowscapPHP\Browscap |
||
100 | */ |
||
101 | 7 | public function setCache($cache) : self |
|
102 | { |
||
103 | 7 | if ($cache instanceof BrowscapCacheInterface) { |
|
104 | 5 | $this->cache = $cache; |
|
105 | 2 | } elseif ($cache instanceof AdapterInterface) { |
|
106 | 1 | $this->cache = new BrowscapCache($cache); |
|
107 | } else { |
||
108 | 1 | throw new Exception( |
|
109 | 'the cache has to be an instance of \BrowscapPHP\Cache\BrowscapCacheInterface or ' |
||
110 | 1 | . 'an instanceof of \WurflCache\Adapter\AdapterInterface', |
|
111 | 1 | Exception::CACHE_INCOMPATIBLE |
|
112 | ); |
||
113 | } |
||
114 | |||
115 | 6 | return $this; |
|
116 | } |
||
117 | |||
118 | /** |
||
119 | * Sets the parser instance to use |
||
120 | * |
||
121 | * @param \BrowscapPHP\Parser\ParserInterface $parser |
||
122 | * |
||
123 | * @return \BrowscapPHP\Browscap |
||
124 | */ |
||
125 | 4 | public function setParser(ParserInterface $parser) : self |
|
131 | |||
132 | /** |
||
133 | * returns an instance of the used parser class |
||
134 | * |
||
135 | * @return \BrowscapPHP\Parser\ParserInterface |
||
136 | */ |
||
137 | 6 | public function getParser() : ParserInterface |
|
152 | |||
153 | /** |
||
154 | * Sets a logger instance |
||
155 | * |
||
156 | * @param \Psr\Log\LoggerInterface $logger |
||
157 | * |
||
158 | * @return \BrowscapPHP\Browscap |
||
159 | */ |
||
160 | 2 | public function setLogger(LoggerInterface $logger) : self |
|
166 | |||
167 | /** |
||
168 | * returns a logger instance |
||
169 | * |
||
170 | * @return \Psr\Log\LoggerInterface |
||
171 | */ |
||
172 | 4 | public function getLogger() : LoggerInterface |
|
180 | |||
181 | /** |
||
182 | * parses the given user agent to get the information about the browser |
||
183 | * |
||
184 | * if no user agent is given, it uses {@see \BrowscapPHP\Helper\Support} to get it |
||
185 | * |
||
186 | * @param string $userAgent the user agent string |
||
187 | * |
||
188 | * @throws \BrowscapPHP\Exception |
||
189 | * @return \stdClass the object containing the browsers details. Array if |
||
190 | * $return_array is set to true. |
||
191 | */ |
||
192 | 5 | public function getBrowser(string $userAgent = null) : ?\stdClass |
|
216 | } |
||
217 |