slartibax/testtask-sitemap-php-pkg

1.0.0 2024-09-08 17:48 UTC

This package is not auto-updated.

Last update: 2024-09-23 16:16:40 UTC


README

License: AGPL v3 Latest Version on Packagist

为 Пиробайт 准备的测试任务。

  • 库只支持从 urlset 数组中提取的 url 标签

测试脚本

<?php

use Slartibax\TesttaskSitemapPhpPkg\Facades\Sitemap;
use Slartibax\TesttaskSitemapPhpPkg\Tags\Url;

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

// Example data
$testData = [
    ["loc" => "https://site.ru/about", "lastmod" => "2020-12-07", "priority" => "0.1", "changefreq" => "weekly"],
    ["loc" => "https://site.ru/about", "lastmod" => "2020-12-07", "priority" => "0.1", "changefreq" => "weekly"],
    ["loc" => "https://site.ru/about", "lastmod" => "2020-12-07", "priority" => "0.1", "changefreq" => "weekly"],
];

// Use facade to configure and start object
$sitemap = Sitemap::make()
    ->filePath(__DIR__ . '/testdir/sitemap.json')
    ->xml()
//    ->json()
//    ->csv()
    ->start();

// Pass tag object for each item
foreach ($testData as $data) {
    $sitemap->addTag(
        new Url($data)
    );
}

// Call complete to finalize generation
$sitemap->complete();