Elgg  Version 6.1
Paths.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Project;
4 
8 class Paths {
9 
13  const SETTINGS_PHP = 'settings.php';
14 
18  const PATH_TO_CONFIG = 'elgg-config';
19 
25  public static function project(): string {
26  static $path;
27  if ($path === null) {
28  $path = self::elgg();
29 
30  // Assumes composer vendor location hasn't been customized...
31  if (!is_file("{$path}vendor/autoload.php")) {
32  $path = dirname($path, 3) . DIRECTORY_SEPARATOR;
33  }
34  }
35 
36  return $path;
37  }
38 
44  public static function elgg(): string {
45  return dirname(__DIR__, 4) . DIRECTORY_SEPARATOR;
46  }
47 
53  public static function projectConfig(): string {
54  return self::project() . self::PATH_TO_CONFIG . DIRECTORY_SEPARATOR;
55  }
56 
64  public static function settingsFile($file = self::SETTINGS_PHP): string {
65  return self::projectConfig() . $file;
66  }
67 
76  public static function sanitize($path, $append_slash = true): string {
77  $path = (string) $path;
78 
79  // Convert to correct UNIX paths
80  $path = str_replace('\\', '/', $path);
81  // replace ./ to / to prevent directory traversal
82  $path = preg_replace('/[.]+\//', '/', $path);
83  // replace // with / except when preceeded by :
84  $path = preg_replace('/([^:])[\/]{2,}/', '$1/', $path);
85 
86  // Sort trailing slash
87  $path = trim($path);
88  // rtrim defaults plus /
89  $path = rtrim($path, " \n\t\0\x0B/");
90 
91  if ($append_slash) {
92  $path = $path . '/';
93  }
94 
95  return $path;
96  }
97 }
elgg
Definition: install.js:27
static project()
Get the project root (where composer is installed) path with "/".
Definition: Paths.php:25
static elgg()
Get the Elgg codebase path with "/".
Definition: Paths.php:44
static projectConfig()
Get the project&#39;s elgg-config/ path.
Definition: Paths.php:53
static settingsFile($file=self::SETTINGS_PHP)
Get path of the Elgg settings file.
Definition: Paths.php:64
string project
Definition: conf.py:49
$path
Definition: details.php:70
const PATH_TO_CONFIG
Path from project root to config folder.
Definition: Paths.php:18
static sanitize($path, $append_slash=true)
Sanitize file paths ensuring that they begin and end with slashes etc.
Definition: Paths.php:76
Find Elgg and project paths.
Definition: Paths.php:8
const SETTINGS_PHP
Default settings filename.
Definition: Paths.php:13