Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
setSessionHandler.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 
7 $usage = new ApiUsage();
8 $usage->setDefinitionText("add session handler");
9 $handlerName = $usage->addRequiredParameter("handlerClass", "class name of session handler to use - set to SessionHandler to use php system handler");
10 $usage->verify();
11 /*
12  * @var Action $action
13  */
15 if ($handlerName != "SessionHandler") {
16 
17  if (!class_exists($handlerName)) {
18  $action->exitError(sprintf("class handler %s not found", $handlerName));
19  }
20  $ref = new ReflectionClass($handlerName);
21  $filePath = $ref->getFileName();
22 
23  if (strpos($filePath, DEFAULT_PUBDIR) == 0) {
24  $basefilePath = substr($filePath, strlen(DEFAULT_PUBDIR) + 1);
25  if (file_exists($basefilePath)) {
26  $filePath = $basefilePath;
27  }
28  }
29  $h = new $handlerName();
30  if (interface_exists("SessionHandlerInterface", false) && is_a($h, "SessionHandlerInterface")) {
31  // PHP 5.4 method used
32  $handlerCode = sprintf('<?php require_once("%s");$handler = new %s();session_set_save_handler($handler, true);', $filePath, $handlerName);
33  } else {
34  // Old method compatible PHP 5.3
35  if ($ref->hasMethod("open") && $ref->hasMethod("close") && $ref->hasMethod("read") && $ref->hasMethod("write") && $ref->hasMethod("destroy") && $ref->hasMethod("gc")) {
36  // PHP 5.3 mode
37  $handlerCode = sprintf('<?php require_once("%s");$handler = new %s();session_set_save_handler(array($handler, "open"), array($handler, "close"),array($handler, "read"),array($handler, "write"),array($handler, "destroy"),array($handler, "gc"));register_shutdown_function("session_write_close");', $filePath, $handlerName);
38  } else {
39  $action->exitError(sprintf('class "%s" incompatible with session handler', $handlerName));
40  }
41  }
42  file_put_contents("config/sessionHandler.php", $handlerCode);
43  printf("Write config/sessionHandler.php Done.\n");
44 } else {
45  $handlerCode = '';
46  file_put_contents("config/sessionHandler.php", $handlerCode);
47  printf("Reset config/sessionHandler.php Done.\n");
48 }
49 
global $action
$handlerCode
const DEFAULT_PUBDIR
Definition: Lib.Prefix.php:28
$handlerName
Verify arguments for wsh programs.
← centre documentaire © anakeen