PHP code example of particle-academy / fancy-x-files

1. Go to this page and download the library: Download particle-academy/fancy-x-files 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/ */

    

particle-academy / fancy-x-files example snippets


use ParticleAcademy\XFiles\Registry;
use ParticleAcademy\XFiles\Files\{RobotsTxt, SecurityTxt, LlmsTxt};

$registry = new Registry;

$registry->add(
    RobotsTxt::make()
        ->userAgent('*')->disallow('/')->allowAll()
        ->userAgent('GPTBot')->allow('/')        // be generous to the AI bot…
        ->protect('/admin', '/internal')         // …but /admin can NEVER leak
        ->sitemap('https://example.com/sitemap.xml')
);

$registry->add(
    SecurityTxt::make()
        ->contact('mailto:[email protected]')
        ->expires(new DateTimeImmutable('+1 year'))   // 

use ParticleAcademy\XFiles\Robots\RobotsPolicy;
use ParticleAcademy\XFiles\Laravel\HonorsRobots;

$policy = RobotsPolicy::parse($targetRobotsTxt);
if ($policy->allowed('/some/page', 'MyCrawler')) {
    // fetch it
}

// one-shot guard, framework-free:
HonorsRobots::allows($targetRobotsTxt, '/some/page', 'MyCrawler'); // bool

'files' => static function (Registry $registry): void {
    $registry->add(
        RobotsTxt::make()->userAgent('*')->disallow('/')->allowAll()
            ->protect('/admin')
            ->sitemap(config('app.url').'/sitemap.xml')
    );
    // …security.txt, llms.txt, sitemap.xml, etc.
},
bash
php artisan vendor:publish --tag=x-files-config