[PHP-WEBMASTER] [web-php] preview: Use ProjectGlobals::getBackendRoot to handle backend/ moving into public/.

Author: Mark Randall
Committer: Derick Rethans (derickr)
Date: 2026-06-18T16:05:07+01:00

Commit: Use ProjectGlobals::getBackendRoot to handle backend/ moving into pub… · php/web-php@c87291e · GitHub
Raw diff: https://github.com/php/web-php/commit/c87291e01d2c4ada3ef53b8d6a0bba87553384df.diff

Use ProjectGlobals::getBackendRoot to handle backend/ moving into public/.

Changed paths:
  M include/download-instructions/windows-downloads.php
  M include/manual-lookup.inc
  M include/shared-manual.inc
  M public/manual/vote-note.php
  M public/pre-release-builds.php
  M src/ProjectGlobals.php
  M tests/Unit/UserNotes/SorterTest.php

Diff:

diff --git a/include/download-instructions/windows-downloads.php b/include/download-instructions/windows-downloads.php
index 77e6445740..af19ad6a54 100644
--- a/include/download-instructions/windows-downloads.php
+++ b/include/download-instructions/windows-downloads.php
@@ -1,7 +1,10 @@
<?php
+
+use phpweb\ProjectGlobals;
+
$baseDownloads = 'Index of /~windows/releases/archives';

-$dataStr = @file_get_contents(__DIR__ . '/../../backend/win-releases.json');
+$dataStr = @file_get_contents(ProjectGlobals::getBackendRoot() . '/win-releases.json');
$releases = $dataStr ? json_decode($dataStr, true) : null;

if (!is_array($releases)) {
diff --git a/include/manual-lookup.inc b/include/manual-lookup.inc
index f12c9a3ce5..4fbc3cd949 100644
--- a/include/manual-lookup.inc
+++ b/include/manual-lookup.inc
@@ -110,9 +110,9 @@ function find_manual_page($lang, $keyword)
     $dbh = false;
     if (class_exists('PDO')) {
         if (in_array('sqlite', PDO::getAvailableDrivers(), true)) {
- if (file_exists(ProjectGlobals::getProjectRoot() . '/backend/manual-lookup.sqlite')) {
+ if (file_exists(ProjectGlobals::getBackendRoot() . '/manual-lookup.sqlite')) {
                 try {
- $dbh = new PDO( 'sqlite:' . ProjectGlobals::getProjectRoot() . '/backend/manual-lookup.sqlite', '', '', [PDO::ATTR_PERSISTENT => true, PDO::ATTR_EMULATE_PREPARES => true] );
+ $dbh = new PDO( 'sqlite:' . ProjectGlobals::getBackendRoot() . '/manual-lookup.sqlite', '', '', [PDO::ATTR_PERSISTENT => true, PDO::ATTR_EMULATE_PREPARES => true] );
                 } catch (PDOException $e) {
                     return find_manual_page_slow($lang, $keyword);
                 }
diff --git a/include/shared-manual.inc b/include/shared-manual.inc
index 2d88477b1b..f82d42d474 100644
--- a/include/shared-manual.inc
+++ b/include/shared-manual.inc
@@ -97,7 +97,7 @@ END_USERNOTE_HEADER;
function manual_notes_load(string $id): array
{
     $hash = substr(md5($id), 0, 16);
- $notes_file = ProjectGlobals::getPublicRoot() . "/backend/notes/" .
+ $notes_file = ProjectGlobals::getBackendRoot() . "/notes/" .
                   substr($hash, 0, 2) . "/$hash";

     // Open the note file for reading and get the data (12KB)
diff --git a/public/manual/vote-note.php b/public/manual/vote-note.php
index 59f5886bbf..72e5e6ef50 100644
--- a/public/manual/vote-note.php
+++ b/public/manual/vote-note.php
@@ -21,7 +21,7 @@
   if (isset($_SERVER['HTTP_X_JSON']) && $_SERVER['HTTP_X_JSON'] == 'On' && !empty($_REQUEST['id']) && !empty($_REQUEST['page']) && ($N = manual_notes_load($_REQUEST['page'])) && array_key_exists($_REQUEST['id'], $N) && !empty($_REQUEST['vote']) && ($_REQUEST['vote'] === 'up' || $_REQUEST['vote'] === 'down')) {
     $response = [];
     $hash = substr(md5($_REQUEST['page']), 0, 16);
- $notes_file = ProjectGlobals::getPublicRoot() . "/backend/notes/" . substr($hash, 0, 2) . "/$hash";
+ $notes_file = ProjectGlobals::getBackendRoot() . "/notes/" . substr($hash, 0, 2) . "/$hash";
     if (!file_exists($notes_file)) {
       $response["success"] = false;
       $response["msg"] = "Invalid request.";
@@ -61,7 +61,7 @@
       }
       else {
         $hash = substr(md5($_REQUEST['page']), 0, 16);
- $notes_file = ProjectGlobals::getPublicRoot(). "/backend/notes/" . substr($hash, 0, 2) . "/$hash";
+ $notes_file = ProjectGlobals::getBackendRoot(). "/notes/" . substr($hash, 0, 2) . "/$hash";
         if (file_exists($notes_file)) {
           $data = [
               "noteid" => $_REQUEST['id'],
diff --git a/public/pre-release-builds.php b/public/pre-release-builds.php
index e8368a64c4..f58c147042 100644
--- a/public/pre-release-builds.php
+++ b/public/pre-release-builds.php
@@ -1,4 +1,7 @@
<?php
+
+use phpweb\ProjectGlobals;
+
$_SERVER['BASE_PAGE'] = 'qa.php';
require_once __DIR__ . '/../include/prepend.inc';
require_once __DIR__ . '/../include/release-qa.php';
@@ -114,7 +117,7 @@

<h2 id="windows">Windows Builds</h2>
<?php
-$winQaFile = __DIR__ . '/backend/win-qa-releases.json';
+$winQaFile = ProjectGlobals::getBackendRoot() . '/win-qa-releases.json';
$winQaBase = 'Index of /~windows/qa';
$winQaMessage = '';
$winQaReleases = [];
diff --git a/src/ProjectGlobals.php b/src/ProjectGlobals.php
index c804c3eec0..0aad5e1c18 100644
--- a/src/ProjectGlobals.php
+++ b/src/ProjectGlobals.php
@@ -13,6 +13,11 @@ public static function getProjectRoot(): string
             ?: throw new Error('Unable to locate project root');
     }

+ public static function getBackendRoot(): string
+ {
+ return self::getProjectRoot() . '/public/backend';
+ }
+
     public static function getPublicRoot(): string
     {
         return realpath(__DIR__ . '/../public')
diff --git a/tests/Unit/UserNotes/SorterTest.php b/tests/Unit/UserNotes/SorterTest.php
index de9e9eef54..f98d07ae07 100644
--- a/tests/Unit/UserNotes/SorterTest.php
+++ b/tests/Unit/UserNotes/SorterTest.php
@@ -5,6 +5,7 @@
namespace phpweb\Test\Unit\UserNotes;

use PHPUnit\Framework;
+use phpweb\ProjectGlobals;
use phpweb\UserNotes\Sorter;
use phpweb\UserNotes\UserNote;

@@ -98,7 +99,7 @@ public function testSortSortsSomeNotes(): void

     public function testSortSortsFullNotes(): void
     {
- $file = file(__DIR__ . '/../../../public/backend/notes/d7/d7742c269d23ea86');
+ $file = file(ProjectGlobals::getBackendRoot() . '/notes/d7/d7742c269d23ea86');

         $notes = [];