spatie / mixed-content-scanner

Scan a HTTPS-site for mixed content
https://spatie.be/open-source
MIT License
98 stars 16 forks source link

demo #25

Closed MathiasReker closed 4 years ago

MathiasReker commented 4 years ago

Hello

Can you provide a demo for how to use it?

MathiasReker commented 4 years ago

Putting this in a file did not work for me, I guess I need to do something more?

require_once __DIR__ . '/vendor/autoload.php';

use Spatie\MixedContentScanner\MixedContentScanner;

$logger = new MixedContentLogger();

$scanner = new MixedContentScanner($logger);

$scanner->scan('https://example.com');
SamuelNitsche commented 4 years ago

Please read the usage section.

MathiasReker commented 4 years ago

I did, and I just tried again.

Can you make an example of what content to write in witch file?

SamuelNitsche commented 4 years ago

Create a class that extends the MixedContentObserver

use Psr\Http\Message\UriInterface;
use Spatie\MixedContentScanner\MixedContent;
use Spatie\MixedContentScanner\MixedContentObserver;

class MixedContentLogger extends MixedContentObserver
{
    /**
     * Will be called when mixed content was found.
     * 
     * @param \Spatie\MixedContentScanner\MixedContent $mixedContent
     */
    public function mixedContentFound(MixedContent $mixedContent)
    {
    }

    /**
     * Will be called when no mixed content was found on the given url.
     * 
     * @param \Psr\Http\Message\UriInterface $crawledUrl
     */
    public function noMixedContentFound(UriInterface $crawledUrl)
    {
    }

    /**
     * Will be called when the scanner has finished crawling.
     */
    public function finishedCrawling()
    {
    }
}

Use it when instantiating the MixedContentScanner.

use Spatie\MixedContentScanner\MixedContentScanner

$logger = new MixedContentLogger();

$scanner = new MixedContentScanner($logger);

$scanner->scan('https://example.com');

Of course, you have to set the correct namespaces and import all classes.

MathiasReker commented 4 years ago

Thanks, I got it.