Issues (106)

src/Application/CLI/testExternLink.php (2 issues)

Severity
1
<?php
2
/*
3
 * This file is part of dispositif/wikibot application (@github)
4
 * 2019-2023 © Philippe M./Irønie  <[email protected]>
5
 * For the full copyright and MIT license information, view the license file.
6
 */
7
8
declare(strict_types=1);
9
10
namespace App\Application\CLI;
11
12
use App\Domain\ExternLink\ExternRefTransformer;
13
use App\Domain\Models\Summary;
14
use App\Domain\Publisher\ExternMapper;
15
use App\Infrastructure\InternetArchiveAdapter;
16
use App\Infrastructure\InternetDomainParser;
17
use App\Infrastructure\Monitor\ConsoleLogger;
18
use App\Infrastructure\ServiceFactory;
19
use App\Infrastructure\WikiwixAdapter;
20
use Codedungeon\PHPCliColors\Color;
21
use Exception;
22
23
require_once __DIR__.'/../myBootstrap.php';
24
25
$url = $argv[1];
26
if (empty($url)) {
27
    die("php testPress.php 'http://...'\n");
28
}
29
30
echo Color::BG_LIGHT_RED.$url.Color::NORMAL."\n";
31
32
$logger = new ConsoleLogger();
33
$logger->debug = true;
34
$logger->verbose = true;
35
$logger->colorMode = true;
36
$summary = new Summary('test');
37
38
// todo command --tor --wikiwix --internetarchive
39
$torEnabled = false;
40
echo "TOR enabled : ".($torEnabled ? "oui" : "non"). "\n";
0 ignored issues
show
The condition $torEnabled is always false.
Loading history...
41
42
$client = ServiceFactory::getHttpClient();
43
$wikiwix = new WikiwixAdapter($client, $logger);
44
$internetArchive = new InternetArchiveAdapter($client, $logger);
45
46
$trans = new ExternRefTransformer(
47
    new ExternMapper($logger),
48
    $torEnabled ? ServiceFactory::getHttpClient($torEnabled) : $client,
0 ignored issues
show
The condition $torEnabled is always false.
Loading history...
49
    new InternetDomainParser(),
50
    $logger,
51
    [$wikiwix, $internetArchive]
52
);
53
$trans->skipSiteBlacklisted = false;
54
$trans->skipRobotNoIndex = false;
55
try {
56
    // Attention : pas de post-processing (sanitize title, etc.)
57
    $result = $trans->process($url, $summary);
58
} catch (Exception $e) {
59
    $result = "EXCEPTION ". $e->getMessage().$e->getFile().$e->getLine();
60
}
61
62
echo '>>> '. $result."\n";
63
64
65
66
67
68