ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
SimpleSAML\Utils\System Class Reference
+ Collaboration diagram for SimpleSAML\Utils\System:

Static Public Member Functions

static getOS ()
 This function returns the Operating System we are running on. More...
 
static getTempDir ()
 This function retrieves the path to a directory where temporary files can be saved. More...
 
static resolvePath ($path, $base=null)
 Resolve a (possibly) relative path from the given base path. More...
 
static writeFile ($filename, $data, $mode=0600)
 Atomically write a file. More...
 

Data Fields

const WINDOWS = 1
 
const LINUX = 2
 
const OSX = 3
 
const HPUX = 4
 
const UNIX = 5
 
const BSD = 6
 
const IRIX = 7
 
const SUNOS = 8
 

Static Private Member Functions

static pathContainsDriveLetter ($path)
 Check if the supplied path contains a Windows-style drive letter. More...
 

Detailed Description

Definition at line 9 of file System.php.

Member Function Documentation

◆ getOS()

static SimpleSAML\Utils\System::getOS ( )
static

This function returns the Operating System we are running on.

Returns
mixed A predefined constant identifying the OS we are running on. False if we are unable to determine it.
Author
Jaime Perez, UNINETT AS jaime.nosp@m..per.nosp@m.ez@un.nosp@m.inet.nosp@m.t.no

Definition at line 29 of file System.php.

Referenced by SimpleSAML_Utilities\isWindowsOS().

30  {
31  if (stristr(PHP_OS, 'LINUX')) {
32  return self::LINUX;
33  }
34  if (stristr(PHP_OS, 'DARWIN')) {
35  return self::OSX;
36  }
37  if (stristr(PHP_OS, 'WIN')) {
38  return self::WINDOWS;
39  }
40  if (stristr(PHP_OS, 'BSD')) {
41  return self::BSD;
42  }
43  if (stristr(PHP_OS, 'UNIX')) {
44  return self::UNIX;
45  }
46  if (stristr(PHP_OS, 'HP-UX')) {
47  return self::HPUX;
48  }
49  if (stristr(PHP_OS, 'IRIX')) {
50  return self::IRIX;
51  }
52  if (stristr(PHP_OS, 'SUNOS')) {
53  return self::SUNOS;
54  }
55  return false;
56  }
+ Here is the caller graph for this function:

◆ getTempDir()

static SimpleSAML\Utils\System::getTempDir ( )
static

This function retrieves the path to a directory where temporary files can be saved.

Returns
string Path to a temporary directory, without a trailing directory separator.
Exceptions

Definition at line 70 of file System.php.

References $globalConfig, and SimpleSAML_Configuration\getInstance().

Referenced by SimpleSAML\Bindings\Shib13\Artifact\extractResponse(), and SimpleSAML_Utilities\getTempDir().

71  {
73 
74  $tempDir = rtrim(
75  $globalConfig->getString(
76  'tempdir',
77  sys_get_temp_dir().DIRECTORY_SEPARATOR.'simplesaml'
78  ),
79  DIRECTORY_SEPARATOR
80  );
81 
82  if (!is_dir($tempDir)) {
83  if (!mkdir($tempDir, 0700, true)) {
84  $error = error_get_last();
85  throw new \SimpleSAML_Error_Exception(
86  'Error creating temporary directory "'.$tempDir.'": '.
87  (is_array($error) ? $error['message'] : 'no error available')
88  );
89  }
90  } elseif (function_exists('posix_getuid')) {
91  // check that the owner of the temp directory is the current user
92  $stat = lstat($tempDir);
93  if ($stat['uid'] !== posix_getuid()) {
94  throw new \SimpleSAML_Error_Exception(
95  'Temporary directory "'.$tempDir.'" does not belong to the current user.'
96  );
97  }
98  }
99 
100  return $tempDir;
101  }
$globalConfig
static getInstance($instancename='simplesaml')
Get a configuration file by its instance name.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pathContainsDriveLetter()

static SimpleSAML\Utils\System::pathContainsDriveLetter (   $path)
staticprivate

Check if the supplied path contains a Windows-style drive letter.

Parameters
string$path
Returns
bool

Definition at line 233 of file System.php.

References $path.

234  {
235  $letterAsciiValue = ord(strtoupper(substr($path, 0, 1)));
236  return substr($path, 1, 1) === ':'
237  && $letterAsciiValue >= 65 && $letterAsciiValue <= 90;
238  }
$path
Definition: aliased.php:25

◆ resolvePath()

static SimpleSAML\Utils\System::resolvePath (   $path,
  $base = null 
)
static

Resolve a (possibly) relative path from the given base path.

A path which starts with a '/' is assumed to be absolute, all others are assumed to be relative. The default base path is the root of the SimpleSAMLphp installation.

Parameters
string$pathThe path we should resolve.
string | null$baseThe base path, where we should search for $path from. Default value is the root of the SimpleSAMLphp installation.
Returns
string An absolute path referring to $path.
Author
Olav Morken, UNINETT AS olav..nosp@m.mork.nosp@m.en@un.nosp@m.inet.nosp@m.t.no

Definition at line 118 of file System.php.

References $base, $config, $d, $path, $ret, and SimpleSAML_Configuration\getInstance().

Referenced by SimpleSAML\Utils\Config\getCertPath().

119  {
120  if ($base === null) {
122  $base = $config->getBaseDir();
123  }
124 
125  // normalise directory separator
126  $base = str_replace('\\', '/', $base);
127  $path = str_replace('\\', '/', $path);
128 
129  // remove trailing slashes
130  $base = rtrim($base, '/');
131  $path = rtrim($path, '/');
132 
133  // check for absolute path
134  if (substr($path, 0, 1) === '/') {
135  // absolute path. */
136  $ret = '/';
137  } elseif (static::pathContainsDriveLetter($path)) {
138  $ret = '';
139  } else {
140  // path relative to base
141  $ret = $base;
142  }
143 
144  $path = explode('/', $path);
145  foreach ($path as $d) {
146  if ($d === '.') {
147  continue;
148  } elseif ($d === '..') {
149  $ret = dirname($ret);
150  } else {
151  if ($ret && substr($ret, -1) !== '/') {
152  $ret .= '/';
153  }
154  $ret .= $d;
155  }
156  }
157 
158  return $ret;
159  }
$path
Definition: aliased.php:25
$config
Definition: bootstrap.php:15
$base
Definition: index.php:4
$ret
Definition: parser.php:6
static getInstance($instancename='simplesaml')
Get a configuration file by its instance name.
for($i=6; $i< 13; $i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ writeFile()

static SimpleSAML\Utils\System::writeFile (   $filename,
  $data,
  $mode = 0600 
)
static

Atomically write a file.

This is a helper function for writing data atomically to a file. It does this by writing the file data to a temporary file, then renaming it to the required file name.

Parameters
string$filenameThe path to the file we want to write to.
string$dataThe data we should write to the file.
int$modeThe permissions to apply to the file. Defaults to 0600.
Exceptions

Definition at line 183 of file System.php.

References $data, $filename, and $res.

Referenced by SimpleSAML\Bindings\Shib13\Artifact\extractResponse(), SimpleSAML_Utilities\writeFile(), and sspmod_metarefresh_MetaLoader\writeState().

184  {
185  if (!is_string($filename) || !is_string($data) || !is_numeric($mode)) {
186  throw new \InvalidArgumentException('Invalid input parameters');
187  }
188 
189  $tmpFile = self::getTempDir().DIRECTORY_SEPARATOR.rand();
190 
191  $res = @file_put_contents($tmpFile, $data);
192  if ($res === false) {
193  $error = error_get_last();
194  throw new \SimpleSAML_Error_Exception(
195  'Error saving file "'.$tmpFile.'": '.
196  (is_array($error) ? $error['message'] : 'no error available')
197  );
198  }
199 
200  if (self::getOS() !== self::WINDOWS) {
201  if (!chmod($tmpFile, $mode)) {
202  unlink($tmpFile);
203  $error = error_get_last();
204  //$error = (is_array($error) ? $error['message'] : 'no error available');
205  throw new \SimpleSAML_Error_Exception(
206  'Error changing file mode of "'.$tmpFile.'": '.
207  (is_array($error) ? $error['message'] : 'no error available')
208  );
209  }
210  }
211 
212  if (!rename($tmpFile, $filename)) {
213  unlink($tmpFile);
214  $error = error_get_last();
215  throw new \SimpleSAML_Error_Exception(
216  'Error moving "'.$tmpFile.'" to "'.$filename.'": '.
217  (is_array($error) ? $error['message'] : 'no error available')
218  );
219  }
220 
221  if (function_exists('opcache_invalidate')) {
222  opcache_invalidate($filename);
223  }
224  }
foreach($_POST as $key=> $value) $res
$filename
Definition: buildRTE.php:89
$data
Definition: bench.php:6
+ Here is the caller graph for this function:

Field Documentation

◆ BSD

const SimpleSAML\Utils\System::BSD = 6

Definition at line 17 of file System.php.

◆ HPUX

const SimpleSAML\Utils\System::HPUX = 4

Definition at line 15 of file System.php.

◆ IRIX

const SimpleSAML\Utils\System::IRIX = 7

Definition at line 18 of file System.php.

◆ LINUX

const SimpleSAML\Utils\System::LINUX = 2

Definition at line 13 of file System.php.

◆ OSX

const SimpleSAML\Utils\System::OSX = 3

Definition at line 14 of file System.php.

◆ SUNOS

const SimpleSAML\Utils\System::SUNOS = 8

Definition at line 19 of file System.php.

◆ UNIX

const SimpleSAML\Utils\System::UNIX = 5

Definition at line 16 of file System.php.

◆ WINDOWS

const SimpleSAML\Utils\System::WINDOWS = 1

Definition at line 12 of file System.php.

Referenced by SimpleSAML_Utilities\isWindowsOS().


The documentation for this class was generated from the following file: