PHP code example of lightship-core / lightship-php

1. Go to this page and download the library: Download lightship-core/lightship-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

lightship-core / lightship-php example snippets




use Lightship\Lightship;

$lightship = new Lightship();

$lightship->domain("https://news.google.com")
  ->route("/foryou")
  ->route("/topstories")
  ->route("/my/searches", ["hl" => "fr", "gl" => "FR"]);
  ->analyse();

file_put_contents("report.json", $lightship->toPrettyJson());



use Lightship\Lightship;

$lightship = new Lightship();

$lightship->config(__DIR__ . "/lightship.json");
  ->analyse();

file_put_contents("report.json", $lightship->toPrettyJson());

use Lightship\Lightship;

ip();

$lightship->route("https://example.com")
  ->route("https://northerwind.com")
  ->onReportedRoute(function (Route $route, Report $report): void {
    echo "{$route->path()}: {$report->score(RuleType::Security)}" . PHP_EOL;

    foreach ($report->results as $result) {
      echo "  {$result->name} {$result->passes}";
    }
  })
  ->analyse();

use Lightship\Lightship;
use Lightship\Rules\Seo\LangPresent;
use Lightship\Rules\Performance\FastResponseTime;

$lightship = new Lightship();

$lightship->route("https://example.com")
  ->route("https://google.com")
  ->analyse();

assert($lightship->rulePassed(["https://example.com"], LangPresent::class) === true);

assert($lightship->allRulesPassed(["https://google.com"]) === true);

assert($lightship->someRulesPassed(["https://google.com"], [LangPresent::class, FastResponseTime::class]) === true);