PHP code example of previewtechs / website-utilities

1. Go to this page and download the library: Download previewtechs/website-utilities 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/ */

    

previewtechs / website-utilities example snippets



esOne = new \Previewtechs\WebsiteUtilities\RobotsDotTxtGenerator\RobotsDotTxtRules('*');
$rulesOne->allow('/test')
    ->allow('/me')
    ->disallow('/thanks');

$rulesTwo = new \Previewtechs\WebsiteUtilities\RobotsDotTxtGenerator\RobotsDotTxtRules('GoogleBot');
$rulesTwo->allow('/test')
    ->allow('/me')
    ->disallow('/thanks');

$robotGenerator = new \Previewtechs\WebsiteUtilities\RobotsDotTxtGenerator\RobotsDotTxtGenerator();
$robotGenerator->addRules($rulesOne);
$robotGenerator->addRules($rulesTwo);

//To print directly
echo $robotGenerator;

//To send response directly
return $robotGenerator->respondAsTextFile(\Psr\Http\Message\ResponseInterface $response);


s = [
    'https://site.com/test.php' => [
        'changefreq' => 'daily',
        'priority' => 1,
        'lastmod' => date('Y-m-d')
    ],
    'https://test.com/another_test.php' => [
        'changefreq' => 'daily',
        'priority' => 2,
        'lastmod' => date('Y-m-d')
    ],
];

$gen = new \Previewtechs\WebsiteUtilities\SitemapGenerator\SitemapGenerator();
$gen->loadUrls($urls);
//If you want to send xml response directly
return $gen->respondAsXML(\Psr\Http\Message\ResponseInterface $response);

//Or, if you want to just print the sitemap
echo $gen;


plication wide middleware
$oldAndNewPathMapping = [
    '/oldPath1' => 'newPath1',
    '/oldPath2' => 'newPath2'
];
$threeZeroOneRedirect = new ThreeZeroOneRedirectPsrMiddleware();
$threeZeroOneRedirect->setPaths($oldAndNewPathMapping);
$app->add($threeZeroOneRedirect);
//End of 301 redirect middleware