<commit_before><?php
/**
 * Yeswiki is a great wiki
 * This file loads the autoload file only once and loads the wiki as singleton
 * Created to allow tests without running YesWiki but in the same state as production
 *
 * @category Wiki
 * @package  YesWiki
 * @license  AGPL version 3
 * @link     https://yeswiki.net
 */

namespace YesWiki\Core;

use Doctrine\Common\Annotations\AnnotationRegistry;
use Throwable;
use YesWiki\Wiki;

class YesWikiLoader
{
    // singleton
    private static $wiki;

    protected function __construct()
    {
    } // prevent public usage
    protected function __clone()
    {
    } // prevent public usage

    public static function getWiki(bool $test = false): Wiki
    {
        if (is_null(self::$wiki)) {
            require_once 'includes/autoload.inc.php';
            try {
                $loader = require_once 'vendor/autoload.php';
            } catch (Throwable $th) {
                $message = "";
                if (!file_exists('vendor/autoload.php')) {
                    $message .= "ERROR ! : Folder `vendor/` seems not to be entirely copied ! (Maybe a YesWiki update aborted before its end !)<br/><strong>Could you manually copy the folder `vendor/` on your server by ftp ?</strong><br/>";
                }
                $message .= $th->getMessage();
                // echo message directly because TemplateEngine not ready here
                echo "<div style=\"border:1px red solid;background-color: #FFCCCC;margin:3px;padding:5px;border-radius:5px;\">$message</div>";
                exit();
            }
            if ($loader !== true) { // not true if not already included
                AnnotationRegistry::registerLoader([$loader, 'loadClass']);
            }

            $loadedWiki = require_once 'includes/YesWiki.php';
            if ($loadedWiki !== true || is_null(self::$wiki)) {
                // params to succeed to instanciate wiki for tests
                if ($test) {
                    $_SERVER['REQUEST_URI'] = $_SERVER['REQUEST_URI'] ?? '';
                    $_SERVER['HTTP_HOST'] = $_SERVER['HTTP_HOST'] ?? 'localhost';
                    $_SERVER['REMOTE_ADDR'] = $_SERVER['REMOTE_ADDR'] ?? '127.0.0.1';
                    $_SESSION = $_SESSION ?? [];
                    $_REQUEST['wiki'] = 'TesT';
                }

                self::$wiki = new Wiki();
            }
        }
        return self::$wiki;
    }<commit_msg>fix(YesWikiLoader): better catch error if file not existing (otherwise catching depends on php.ini)<commit_after><?php
/**
 * Yeswiki is a great wiki
 * This file loads the autoload file only once and loads the wiki as singleton
 * Created to allow tests without running YesWiki but in the same state as production
 *
 * @category Wiki
 * @package  YesWiki
 * @license  AGPL version 3
 * @link     https://yeswiki.net
 */

namespace YesWiki\Core;

use Doctrine\Common\Annotations\AnnotationRegistry;
use Exception;
use Throwable;
use YesWiki\Wiki;

class YesWikiLoader
{
    // singleton
    private static $wiki;

    protected function __construct()
    {
    } // prevent public usage
    protected function __clone()
    {
    } // prevent public usage

    public static function getWiki(bool $test = false): Wiki
    {
        if (is_null(self::$wiki)) {
            require_once 'includes/autoload.inc.php';
            try {
                if (!file_exists('vendor/autoload.php')) {
                    throw new Exception("ERROR ! : Folder `vendor/` seems not to be entirely copied ! (Maybe a YesWiki update aborted before its end !)<br/><strong>Could you manually copy the folder `vendor/` on your server by ftp ?</strong><br/>");
                }
                $loader = require_once 'vendor/autoload.php';
            } catch (Throwable $th) {
                $message = $th->getMessage();
                // echo message directly because TemplateEngine not ready here
                echo "<div style=\"border:1px red solid;background-color: #FFCCCC;margin:3px;padding:5px;border-radius:5px;\">$message</div>";
                exit();
            }
            if ($loader !== true) { // not true if not already included
                AnnotationRegistry::registerLoader([$loader, 'loadClass']);
            }

            $loadedWiki = require_once 'includes/YesWiki.php';
            if ($loadedWiki !== true || is_null(self::$wiki)) {
                // params to succeed to instanciate wiki for tests
                if ($test) {
                    $_SERVER['REQUEST_URI'] = $_SERVER['REQUEST_URI'] ?? '';
                    $_SERVER['HTTP_HOST'] = $_SERVER['HTTP_HOST'] ?? 'localhost';
                    $_SERVER['REMOTE_ADDR'] = $_SERVER['REMOTE_ADDR'] ?? '127.0.0.1';
                    $_SESSION = $_SESSION ?? [];
                    $_REQUEST['wiki'] = 'TesT';
                }

                self::$wiki = new Wiki();
            }
        }
        return self::$wiki;
    }
{'fraction_non_alphanumeric': 0.12292761827739587, 'fraction_numerical': 0.004448038819247877, 'mean_word_length': 2.0331085223789085, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '89951', 'n_tokens_mistral': 1380, 'n_tokens_neox': 1306, 'n_words': 382}