public static function Start() { global $_SERVER; if (!phoxy_conf()["is_ajax_request"] && phoxy_conf()["api_csrf_prevent"]) { die("Request aborted due API direct CSRF warning"); } if (phoxy_conf()["buffered_output"]) { ob_start(); } global $_GET; $get_param = phoxy::Config()["get_api_param"]; $file = $_GET[$get_param]; unset($_GET[$get_param]); if ($file === 'htaccess') { exit('Rewrite engine work SUCCESS'); } try { include_once 'rpc_string_parser.php'; $parser = new \phoxy\rpc_string_parser(); global $_phoxy_process_obj; $_phoxy_process_obj = $obj = $parser->GetRpcObject($file, $_GET); $a = $obj['obj']; $method = $obj['method']; if (is_string($method)) { $method = [$method, []]; } $result = $a->APICall($method[0], $method[1]); } catch (phoxy_protected_call_error $e) { $result = new phoxy_return_worker($e->result); } $prepared = (string) $result; if (phoxy_conf()["buffered_output"]) { $buffered_output = ob_get_contents(); ob_end_clean(); } if (phoxy_conf()["debug_api"] && !phoxy_conf()["is_ajax_request"]) { echo "<h1>Result</h1>\n"; var_dump($result->obj); } else { header('Content-Type: application/json; charset=utf-8'); } if (phoxy_conf()["is_ajax_request"]) { echo $prepared; } else { if (phoxy_conf()["buffered_output"]) { echo "\n<hr><h1>Log</h1>\n{$buffered_output}"; } } }
private function DefaultCacheTiming() { $conf = phoxy::Config(); if (!isset($this->obj['cache'])) { $this->obj['cache'] = []; } $cache = $this->obj['cache']; //var_dump($this->obj); if (isset($cache['no'])) { if (in_array("all", $cache['no'])) { return; } } $dictionary = ["global", "session", "local"]; foreach ($dictionary as $scope) { if (!isset($cache[$scope]) && !is_null($conf["cache_{$scope}"])) { if (!isset($cache['no']) || !in_array($scope, $cache['no'])) { $this->obj['cache'][$scope] = $conf["cache_{$scope}"]; } } } }
public function GetRpcObject($str, $get) { $t = $this->GetOrganizedTokens($str); $args = $this->ExplodeTokensToCallee($t); $try = $this->GetAllCallVariations($args); include_once 'include.php'; if (!count($try)) { die('Error at rpc resolve: All variations were invalid. Unable to resolve'); } foreach ($try as $t) { $target_dir = "."; if ($t['class'] === 'phoxy') { $target_dir = realpath(dirname(__FILE__)); $t["scope"] = str_replace(\phoxy::Config()["api_dir"], "", $t["scope"]); } $file_location = $target_dir . $t["scope"]; $obj = IncludeModule($file_location, $t["class"]); if (!is_null($obj)) { return ["original_str" => $str, "obj" => $obj, "method" => $t["method"]]; } } exit(json_encode(["error" => 'Module not found'])); }
public function __call($name, $arguments) { assert($this->json !== null, "API constuctor should be called"); $this->addons = $this->default_addons; $ret = $this->Call($name, $arguments); if (!is_array($ret)) { $ret = [$name => $ret]; $ret = array("data" => $ret); } $ret = array_merge_recursive($this->addons, $ret); $conf = phoxy::Config(); return new phoxy_return_worker($ret); }
<?php namespace phoxy; header('Lain: Hot'); if (strnatcmp(phpversion(), '5.5') < 0) { exit("PHP 5.5 or newer is required"); } include 'server/config.php'; include 'server/include.php'; LoadModule('phoxy/server', 'phoxy'); if (\phoxy::Config()['autostart']) { \phoxy::Start(); }