1 | <?php |
||
2 | |||
3 | namespace PhpTek\Exodus\Tool; |
||
4 | |||
5 | use SilverStripe\Core\Config\Configurable; |
||
6 | use SilverStripe\Core\Injector\Injectable; |
||
7 | use PhpTek\Exodus\Crawl\StaticSiteCrawler; |
||
8 | |||
9 | /** |
||
10 | * Exodus utility methods. |
||
11 | * |
||
12 | * @package phptek/silverstripe-exodus |
||
13 | * @author Russell Michell <[email protected]> |
||
14 | */ |
||
15 | class StaticSiteUtils |
||
16 | { |
||
17 | use Injectable; |
||
18 | use Configurable; |
||
19 | |||
20 | /** |
||
21 | * Log a message if the logging has been setup according to docs |
||
22 | * |
||
23 | * @param string $message |
||
24 | * @param string $_args Unused so that we need not have to update calling logic: |
||
25 | * @return void |
||
26 | */ |
||
27 | public function log(string $message, ...$_args): void |
||
0 ignored issues
–
show
|
|||
28 | { |
||
29 | $logFile = $this->config()->get('log_file'); |
||
30 | |||
31 | if ($logFile) { |
||
32 | file_put_contents($logFile, $message . PHP_EOL, FILE_APPEND); |
||
33 | } |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * If operating in a specific environment, set some proxy options for it for passing to curl and |
||
38 | * to phpCrawler (if set in config). |
||
39 | * |
||
40 | * @param boolean $set e.g. !Director::isDev() |
||
41 | * @param StaticSiteCrawler $crawler (Warning: Pass by reference) |
||
42 | * @return array Returns an array of the config options in a format consumable by curl. |
||
43 | */ |
||
44 | public function defineProxyOpts(bool $set, StaticSiteCrawler &$crawler = null): array |
||
45 | { |
||
46 | if ($set && is_bool($set) && $set !== false) { |
||
47 | $proxyOpts = StaticSiteContentExtractor::config()->get('curl_opts_proxy'); |
||
48 | |||
49 | if (!$proxyOpts || !is_array($proxyOpts) || !count($proxyOpts) > 0) { |
||
50 | return []; |
||
51 | } |
||
52 | |||
53 | if ($crawler) { |
||
54 | $crawler->setProxy($proxyOpts['hostname'], $proxyOpts['port']); |
||
55 | } |
||
56 | |||
57 | return [ |
||
58 | CURLOPT_PROXY => $proxyOpts['hostname'], |
||
59 | CURLOPT_PROXYPORT => $proxyOpts['port'] |
||
60 | ]; |
||
61 | } |
||
62 | |||
63 | return []; |
||
64 | } |
||
65 | } |
||
66 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.