1 file_example_session_streams.inc protected &FileExampleSessionStreamWrapper::uri_to_session_key($uri, $create = TRUE)

Return a reference to the correct $_SESSION key.

Parameters

string $uri: The uri: session://something

bool $create: If TRUE, create the key

Return value

array|bool: A reference to the array at the end of the key-path, or FALSE if the path doesn't map to a key-path (and $create is FALSE).

File

modules/examples/file_example/file_example_session_streams.inc, line 256
Provides a demonstration session:// stream-wrapper.

Class

FileExampleSessionStreamWrapper
Example stream wrapper class to handle session:// streams.

Code

protected function &uri_to_session_key($uri, $create = TRUE) {
  // Since our uri_to_session_key() method returns a reference, we
  // have to set up a failure flag variable.
  $fail = FALSE;
  $path = $this->getLocalPath($uri);
  $path_components = explode('/', $path);
  // Set up a reference to the root session:// 'directory.'
  $var = &$_SESSION['file_example'];
  // Handle case of just session://.
  if (count($path_components) < 1) {
    return $var;
  }
  // Walk through the path components and create keys in $_SESSION,
  // unless we're told not to create them.
  foreach ($path_components as $component) {
    if ($create || isset($var[$component])) {
      $var = &$var[$component];
    }
    else {
      // This path doesn't exist as keys, either because the
      // key doesn't exist, or because we're told not to create it.
      return $fail;
    }
  }

  return $var;
}