The Site class serves as the base class in Scriptor, providing convenient access to various Scriptor API classes and variables for interacting with the website and its content. Additionally, the Site class inherits all the methods and properties of the Module class.

To begin, obtain an instance of the Site class:

<?php
use Scriptor\Core\Scriptor;

$site = Scriptor::getSite();

Alternatively, you can directly access the methods and properties of the Site class. For example, to retrieve the path to the frontend theme from the configuration variable:

echo Scriptor::getSite()->config['theme_path'];

If you ever need the URL of the current website, you can retrieve it as follows:

echo Scriptor::getSite()->siteUrl;

To extend the default Site class and add new methods to it, you can use the Scriptor::setSite() and Scriptor::getSite() methods. Here's an example:

require dirname(__DIR__) . '/site/classes/SiteExtended.php';

Scriptor::setSite('Scriptor\Site\Classes\SiteExtended', true);

$site = Scriptor::getSite();

The setSite method takes two parameters. The first parameter is the name of the class that will be used instead of the Site class. The second parameter is an optional flag that tells Scriptor to initialize the class after creating the instance. In this example, we inject our SiteExtended class into Scriptor. The PHP file SiteExtended.php can be located in the site/classes/ directory (site/classes/SiteExtended.php) and can have the following content:

<?php // site/classes/SiteExtended.php
namespace Scriptor\Site\Classes;

use Scriptor\Core\Site;

class SiteExtended extends Site
{
    public function getClassName()
    {
        return __CLASS__;
    }
}

Now your class has a new method called getClassName():

echo $site->getClassName(); // Output: Scriptor\Site\Classes\SiteExtended

By leveraging the Site class and its extensibility, you can enhance the functionality of Scriptor according to your specific needs.