Elgg  Version 3.0
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() {
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(dirname(dirname($path))) . DIRECTORY_SEPARATOR;
33  }
34  }
35 
36  return $path;
37  }
38 
44  public static function elgg() {
45  return dirname(dirname(dirname(dirname(__DIR__)))) . DIRECTORY_SEPARATOR;
46  }
47 
53  public static function projectConfig() {
54  return self::project() . self::PATH_TO_CONFIG . DIRECTORY_SEPARATOR;
55  }
56 
64  public static function settingsFile($file = self::SETTINGS_PHP) {
65  return self::projectConfig() . $file;
66  }
67 
76  public static function sanitize($path, $append_slash = true) {
77  // Convert to correct UNIX paths
78  $path = str_replace('\\', '/', $path);
79  $path = str_replace('../', '/', $path);
80  // replace // with / except when preceeded by :
81  $path = preg_replace("/([^:])\/\//", "$1/", $path);
82 
83  // Sort trailing slash
84  $path = trim($path);
85  // rtrim defaults plus /
86  $path = rtrim($path, " \n\t\0\x0B/");
87 
88  if ($append_slash) {
89  $path = $path . '/';
90  }
91 
92  return $path;
93  }
94 }
static project()
Get the project root (where composer is installed) path with "/".
Definition: Paths.php:25
if(!array_key_exists($filename, $text_files)) $file
static elgg()
Get the Elgg codebase path with "/".
Definition: Paths.php:44
$path
Definition: details.php:89
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:46
const PATH_TO_CONFIG
Path from project root to config folder.
Definition: Paths.php:18
static sanitize($path, $append_slash=true)
Sanitise 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
var elgg
Definition: elgglib.js:4