Esempio n. 1
0
 /**
  * Push an application
  *
  * @param mixed  $uApplicationConfig the application configuration
  * @param string $uWritablePath      writable output folder
  *
  * @return void
  */
 public function pushApplication($uApplicationConfig, $uWritablePath)
 {
     // MD create application directory if it does not exist
     if (!file_exists($uWritablePath)) {
         mkdir($uWritablePath, 0777, true);
     }
     // MD push framework variables to undo application's own variable definitions
     $this->pushSourcePaths($uApplicationConfig);
     // MD include compilation file for the application
     // FIXME is it needed to be loaded before Core and ApplicationBase?
     if (file_exists($tFile = "{$uWritablePath}/compiled.php")) {
         require $tFile;
     } else {
         $tGeneratorRegistry = new GeneratorRegistry($uApplicationConfig, $uWritablePath);
         $tGeneratorRegistry->execute();
     }
     // MD add configuration entries too
     $uApplicationConfig += (require "{$uWritablePath}/unified-config.php");
     // MD construct the application class
     $this->runningApplications[] = [ApplicationBase::$current, $this->variables];
     $tApplicationType = $uApplicationConfig["type"];
     $tApplication = new $tApplicationType($uApplicationConfig, $uWritablePath);
     ApplicationBase::$current = $tApplication;
 }
Esempio n. 2
0
 /**
  * Initializes an application
  *
  * @param mixed  $uConfig        application config
  * @param string $uWritablePath  writable output folder
  *
  * @return Application
  */
 public function __construct($uConfig, $uWritablePath)
 {
     parent::__construct($uConfig, $uWritablePath);
 }
Esempio n. 3
0
 /**
  * Initializes an application
  *
  * @param mixed  $uConfig       application config
  * @param string $uWritablePath writable output folder
  *
  * @return Application
  */
 public function __construct($uConfig, $uWritablePath)
 {
     parent::__construct($uConfig, $uWritablePath);
     // remote host
     if (isset($_SERVER["HTTP_CLIENT_IP"])) {
         Core::$instance->variables["http-remotehost"] = $_SERVER["HTTP_CLIENT_IP"];
     } elseif (isset($_SERVER["REMOTE_ADDR"])) {
         Core::$instance->variables["http-remotehost"] = $_SERVER["REMOTE_ADDR"];
     } elseif (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) {
         Core::$instance->variables["http-remotehost"] = $_SERVER["HTTP_X_FORWARDED_FOR"];
     } else {
         Core::$instance->variables["http-remotehost"] = "0.0.0.0";
     }
     // http method
     if (isset($_SERVER["X-HTTP-METHOD-OVERRIDE"])) {
         Core::$instance->variables["http-method"] = strtolower($_SERVER["X-HTTP-METHOD-OVERRIDE"]);
     } elseif (isset($_POST["_method"])) {
         Core::$instance->variables["http-method"] = strtolower($_POST["_method"]);
     } elseif (isset($_SERVER["REQUEST_METHOD"])) {
         Core::$instance->variables["http-method"] = strtolower($_SERVER["REQUEST_METHOD"]);
     } else {
         Core::$instance->variables["http-method"] = "GET";
     }
     // http requested with
     if (isset($_SERVER["HTTP_X_REQUESTED_WITH"])) {
         Core::$instance->variables["http-requested-with"] = strtolower($_SERVER["HTTP_X_REQUESTED_WITH"]);
     } else {
         Core::$instance->variables["http-requested-with"] = null;
     }
     // http accept language
     // TODO not implemented
     // http accept content-types
     // TODO not implemented
     // http original url
     if (isset($_SERVER["X_ORIGINAL_URL"])) {
         Core::$instance->variables["http-request-uri"] = $_SERVER["X_ORIGINAL_URL"];
     } elseif (isset($_SERVER["X_REWRITE_URL"])) {
         Core::$instance->variables["http-request-uri"] = $_SERVER["X_REWRITE_URL"];
     } elseif (isset($_SERVER["HTTP_X_REWRITE_URL"])) {
         Core::$instance->variables["http-request-uri"] = $_SERVER["HTTP_X_REWRITE_URL"];
     } elseif (isset($_SERVER["IIS_WasUrlRewritten"]) && (string) $_SERVER["IIS_WasUrlRewritten"] === "1" && isset($_SERVER["UNENCODED_URL"])) {
         Core::$instance->variables["http-request-uri"] = $_SERVER["UNENCODED_URL"];
     } elseif (isset($_SERVER["REQUEST_URI"])) {
         if (strncmp($_SERVER["REQUEST_URI"], Core::$instance->variables["host"], $tHostLength = strlen(Core::$instance->variables["host"])) === 0) {
             Core::$instance->variables["http-request-uri"] = substr($_SERVER["REQUEST_URI"], $tHostLength);
         } else {
             Core::$instance->variables["http-request-uri"] = $_SERVER["REQUEST_URI"];
         }
     } elseif (isset($_SERVER["ORIG_PATH_INFO"])) {
         Core::$instance->variables["http-request-uri"] = $_SERVER["ORIG_PATH_INFO"];
         if (isset($_SERVER["QUERY_STRING"]) && strlen($_SERVER["QUERY_STRING"]) > 0) {
             Core::$instance->variables["http-request-uri"] .= "?" . $_SERVER["QUERY_STRING"];
         }
     } else {
         Core::$instance->variables["http-request-uri"] = "";
     }
     // http pathroot
     if (!isset(Core::$instance->variables["http-pathroot"])) {
         Core::$instance->variables["http-pathroot"] = pathinfo($_SERVER["SCRIPT_NAME"], PATHINFO_DIRNAME);
     }
     Core::$instance->variables["http-pathroot"] = trim(str_replace("\\", "/", Core::$instance->variables["http-pathroot"]), "/");
     if (strlen(Core::$instance->variables["http-pathroot"]) > 0) {
         Core::$instance->variables["http-pathroot"] = "/" . Core::$instance->variables["http-pathroot"];
     }
     // http pathinfo
     if (($tPos = strpos(Core::$instance->variables["http-request-uri"], "?")) !== false) {
         $tBaseUriPath = substr(Core::$instance->variables["http-request-uri"], 0, $tPos);
     } else {
         $tBaseUriPath = Core::$instance->variables["http-request-uri"];
     }
     Core::$instance->variables["http-pathinfo"] = substr($tBaseUriPath, strlen(Core::$instance->variables["http-pathroot"]));
     Core::$instance->updateVariablesCache();
     $this->events->invoke("applicationInit");
 }