ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
 

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 $error, $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  }
$error
Definition: Error.php:17
$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:

◆ 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  // remove trailing slashes
126  $base = rtrim($base, '/');
127 
128  // check for absolute path
129  if (substr($path, 0, 1) === '/') {
130  // absolute path. */
131  $ret = '/';
132  } else {
133  // path relative to base
134  $ret = $base;
135  }
136 
137  $path = explode('/', $path);
138  foreach ($path as $d) {
139  if ($d === '.') {
140  continue;
141  } elseif ($d === '..') {
142  $ret = dirname($ret);
143  } else {
144  if (substr($ret, -1) !== '/') {
145  $ret .= '/';
146  }
147  $ret .= $d;
148  }
149  }
150 
151  return $ret;
152  }
$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 176 of file System.php.

References $data, $error, $filename, and $res.

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

177  {
178  if (!is_string($filename) || !is_string($data) || !is_numeric($mode)) {
179  throw new \InvalidArgumentException('Invalid input parameters');
180  }
181 
182  $tmpFile = self::getTempDir().DIRECTORY_SEPARATOR.rand();
183 
184  $res = @file_put_contents($tmpFile, $data);
185  if ($res === false) {
186  $error = error_get_last();
187  throw new \SimpleSAML_Error_Exception(
188  'Error saving file "'.$tmpFile.'": '.
189  (is_array($error) ? $error['message'] : 'no error available')
190  );
191  }
192 
193  if (self::getOS() !== self::WINDOWS) {
194  if (!chmod($tmpFile, $mode)) {
195  unlink($tmpFile);
196  $error = error_get_last();
197  //$error = (is_array($error) ? $error['message'] : 'no error available');
198  throw new \SimpleSAML_Error_Exception(
199  'Error changing file mode of "'.$tmpFile.'": '.
200  (is_array($error) ? $error['message'] : 'no error available')
201  );
202  }
203  }
204 
205  if (!rename($tmpFile, $filename)) {
206  unlink($tmpFile);
207  $error = error_get_last();
208  throw new \SimpleSAML_Error_Exception(
209  'Error moving "'.$tmpFile.'" to "'.$filename.'": '.
210  (is_array($error) ? $error['message'] : 'no error available')
211  );
212  }
213 
214  if (function_exists('opcache_invalidate')) {
215  opcache_invalidate($filename);
216  }
217  }
$error
Definition: Error.php:17
foreach($_POST as $key=> $value) $res
+ 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: