Exemplo n.º 1
0
/**
 *  Whatever Data is returned by Hanlder, should be an array will be rendered as array on response
 * 
 * @param AbstractUser $user
 * @param array $controllerInfo
 * @param String $handlerName
 */
function rx_interceptor_json($user, $controllerInfo, $handlerName)
{
    $user->validate();
    include_once RUDRA . "/core/handler/AbstractHandler.php";
    $handlerInfo = ClassUtil::getHandler($handlerName);
    if ($handlerInfo != NULL) {
        global $temp;
        include_once $handlerInfo["filePath"];
        $className = $handlerInfo["className"];
        $tempClass = new ReflectionClass($className);
        if ($tempClass->isInstantiable()) {
            $temp = $tempClass->newInstance();
        }
        if ($temp != NULL) {
            try {
                if ($tempClass->hasMethod("invokeHandler")) {
                    $resp = call_method_by_class($tempClass, $temp, 'invokeHandler', array('user' => $user, 'data' => new RequestData(get_request_param("data"))), $handlerInfo["requestParams"]);
                    if (isset($resp)) {
                        echo json_encode($resp);
                    }
                }
            } catch (Exception $e) {
                echo json_encode(array("error" => $e));
            }
        }
    }
}
Exemplo n.º 2
0
 public static function getSessionUserClass()
 {
     $UserClassInfo = ClassUtil::getModel("sessionUser");
     include_once "model/AbstractUser.php";
     if ($UserClassInfo != NULL) {
         include_once $UserClassInfo["filePath"];
         return $UserClassInfo["className"];
     } else {
         return "app\\model\\DefaultUser";
     }
 }
Exemplo n.º 3
0
Arquivo: RX.php Projeto: rudraks/boot
 public static function handler($handle_name)
 {
     $CloudinaryClassInfo = \ClassUtil::getHandler($handle_name);
     if ($CloudinaryClassInfo != NULL) {
         include_once $CloudinaryClassInfo["filePath"];
         $CloudinaryClassInstance = new $CloudinaryClassInfo["className"]();
         $CloudinaryClassInstance->populateParams();
         return $CloudinaryClassInstance;
     }
     return null;
 }
Exemplo n.º 4
0
 public static function go($string)
 {
     preg_match("/{((.*?)::(.*?))}/s", $string, $match);
     if (sizeof($match) > 0) {
         if (is_callable($match[1], false, $callable_name)) {
             $result = call_user_func($match[1]);
         } else {
             $result = ClassUtil::getStaticVal($match[2], $match[3]);
         }
     }
     return $string = str_replace($match[0], $result, $string);
 }
Exemplo n.º 5
0
 protected function getFirstAncestorOfType($className)
 {
     $result = null;
     $current = $this;
     while (!ClassUtil::isSubclassOf(get_class($current), $className)) {
         $parent = $current->getParent();
         if (get_class($parent) === "View" && $className !== "View") {
             throw new NoSuchAnchestorComponentException(get_class($this), $className);
         }
         $current = $parent;
     }
     return $current;
 }
Exemplo n.º 6
0
function rx_interceptor_page($user, $info, $handlerName)
{
    $user->validate();
    include_once RUDRA . "/core/handler/AbstractHandler.php";
    $handlerInfo = ClassUtil::getHandler($handlerName);
    if ($handlerInfo != NULL) {
        global $temp;
        include_once $handlerInfo["filePath"];
        $className = $handlerInfo["className"];
        $tempClass = new ReflectionClass($className);
        if ($tempClass->isInstantiable()) {
            $temp = $tempClass->newInstance();
        }
        if ($temp != NULL) {
            if ($tempClass->hasMethod("invokeHandler")) {
                $tpl = new Smarty();
                call_user_func(rx_function("rx_set_smarty_paths"), $tpl);
                $tpl->debugging = RX_SMARTY_DEBUG;
                $header = new Header($tpl);
                $page = new Page();
                $view = call_method_by_class($tempClass, $temp, 'invokeHandler', array('tpl' => $tpl, 'viewModel' => $tpl, 'user' => $user, 'header' => $header, 'page' => $page, 'dataModel' => $page->data, 'data' => new RequestData(get_request_param("data"))), $handlerInfo["requestParams"]);
                if (!isset($view)) {
                    $view = $handlerName;
                }
                $tpl->assign('user', $user);
                $tpl->assign('page', $page);
                $tpl->assign('header', $header);
                $tpl->assign('CONTEXT_PATH', CONTEXT_PATH);
                $tpl->assign('RESOURCE_PATH', RESOURCE_PATH);
                $tpl->assign('METAS', $header->metas);
                $tpl->assign('TITLE', $header->title);
                $view_path = $view . TEMP_EXT;
                if (!file_exists($view_path)) {
                    $tpl->setTemplateDir(RUDRA . "/core/view");
                    //$view_path = get_include_path () . RUDRA . "/core/view/".$view.TEMP_EXT;
                    //$view_path = get_include_path () . RUDRA . "../view/".$view.TEMP_EXT;
                }
                $tpl->assign('BODY_FILES', $view_path);
                $tpl->assign('page_json', json_encode($page->data->data));
                $tpl->display(RUDRA . "/core/view/full.tpl");
                Browser::log("header", $header->css, $header->scripts);
                Browser::printlogs();
            }
        }
    }
}
Exemplo n.º 7
0
function rx_interceptor_template($user, $info, $handlerName)
{
    $user->validate();
    include_once RUDRA . "/core/handler/AbstractHandler.php";
    $handlerInfo = ClassUtil::getHandler($handlerName);
    if ($handlerInfo != NULL) {
        global $temp;
        include_once $handlerInfo["filePath"];
        $className = $handlerInfo["className"];
        $tempClass = new ReflectionClass($className);
        if ($tempClass->isInstantiable()) {
            $temp = $tempClass->newInstance();
        }
        if ($temp != NULL) {
            if ($tempClass->hasMethod("invokeHandler")) {
                $tpl = new Smarty();
                call_user_func(rx_function("rx_set_smarty_paths"), $tpl);
                $tpl->debugging = RX_SMARTY_DEBUG;
                $page = new Page();
                $view = call_method_by_class($tempClass, $temp, 'invokeHandler', array('tpl' => $tpl, 'viewModel' => $tpl, 'user' => $user, 'page' => $page, 'dataModel' => $page->data, 'data' => new RequestData(get_request_param("data"))), $handlerInfo["requestParams"]);
                if (!isset($view)) {
                    $view = $handlerName;
                }
                $tpl->assign('user', $user);
                $tpl->assign('CONTEXT_PATH', CONTEXT_PATH);
                $tpl->assign('RESOURCE_PATH', RESOURCE_PATH);
                if (isset($tpl->repeatData)) {
                    foreach ($tpl->repeatData as $key => $value) {
                        $tpl->assign($value['key'], $value['value']);
                        $tpl->display($this->getViewPath() . $view . Config::get('TEMP_EXT'));
                    }
                } else {
                    $tpl->display($this->getViewPath() . $view . Config::get('TEMP_EXT'));
                }
                echo TEMP_DELIMITER;
                Browser::printlogs();
                echo TEMP_DELIMITER . json_encode($page->data->data);
                Browser::printlogs();
            }
        }
    }
}
Exemplo n.º 8
0
 private function parseNode(XmlElement $node)
 {
     $className = ucfirst($node->getName());
     if (!ClassCache::exists($className)) {
         $instance = new HtmlComponent($node->getName(), $node->getText(), $node->getAttributes());
     } else {
         if (!ClassUtil::isSubclassOf($className, "Component")) {
             throw new ComponentNotExistsException($className);
         }
         $instance = new $className();
         foreach ($node->getAttributes() as $attrName => $attrValue) {
             $setterName = "set" . ucfirst($attrName);
             $setter = new ReflectionMethod($instance, $setterName);
             $setter->invoke($instance, (string) $attrValue);
         }
     }
     foreach ($node->getChildren() as $child) {
         $instance->addChild($this->parseNode($child));
     }
     return $instance;
 }
Exemplo n.º 9
0
 public function scrape_CFG()
 {
     /*preg_match_all('/<!--<seperate((?: {|{)(?:.*?)})(.*?)<!--<\/seperate>-->/s', $content, $matches);
     		//---------------------------------------------------------
     		if (sizeof($matches[0]) > 0) {
     			$this->css_CFG(NULL, $matches[2][0], json_decode($matches[1][0], true));
     			//-----------------------------------------------------
     			$content = str_replace($matches[0][0], "", $content);
     			//-----------------------------------------------------
     		}*/
     $this->tags = array();
     //---------------------------------------------------------
     $output_updated = $this->output_markup = Compiler::markUp_CHK($this->output, array("ignore" => true, "replace" => true));
     //$output_updated = StringUtil::removeAllHtmlComments($output_updated);
     //---------------------------------------------------------
     preg_match_all($this->regex, $output_updated, $matches, PREG_SET_ORDER);
     //---------------------------------------------------------
     $this->matches = $matches;
     //---------------------------------------------------------
     foreach ($matches as $key => $match) {
         $save_dir = $this->save_dir;
         //-----------------------------------------------------
         $prop = array("forceDownload" => $this->forceDownload, "compileType" => $this->compileType, "compilePath" => $this->compilePath, "compilerGlobal" => $this->compilerGlobal, "minify" => $this->minify, "save_dir" => $save_dir, "defaultSavePath" => $this->defaultSavePath, "output" => $this->output_updated, "match" => $match, "imagesProp" => $this->imagesProp, "index" => $key, "onRemoveMatch" => $this->onRemoveMatch, "src_path" => $this->src_path);
         //-----------------------------------------------------
         $newMatch = ClassUtil::classFromString($this->matchClass, array(ArrayUtil::array_replace_recursive($prop, $this->matchProp)));
         $newMatch->init();
         //-----------------------------------------------------
         $this->output_updated = $newMatch->output_updated;
         //-----------------------------------------------------
         if (!is_null($newMatch->link)) {
             if ($this->saveasphp) {
                 $this->mergedCode .= $newMatch->content_updated;
             } else {
                 //$this->extLinks .= $newMatch->link;
             }
         } else {
             //if (is_null($this->compilerGlobal->mergedCode)) $this->compilerGlobal->mergedCode = "";
             if (!is_null($newMatch->content_updated)) {
                 if ($newMatch->tagType != "tmpl") {
                     $this->mergedCode_noTag .= PHP_EOL . $newMatch->content_updated;
                     $this->mergedCode .= "<" . $newMatch->tagType . ">" . PHP_EOL . $newMatch->content_updated . "</" . $newMatch->tagType . ">";
                 } else {
                     $this->mergedCode .= PHP_EOL . $newMatch->content_updated;
                 }
             }
         }
         //-----------------------------------------------------
         $this->tags[] = $newMatch;
     }
     //---------------------------------------------------------
     //$this->output_updated = $output_updated;
 }
Exemplo n.º 10
0
 public function loadSession()
 {
     $UserClass = ClassUtil::getSessionUserClass();
     $this->user = new $UserClass();
 }
Exemplo n.º 11
0
 public static function hostConnect($database = "{database}")
 {
     //----------------------------------------------------------
     //init var
     //----------------------------------------------------------
     $class = "Constants";
     //----------------------------------------------------------
     $chk = self::constCHK($database);
     //----------------------------------------------------------
     if (!$chk['bool']) {
         return $chk;
     } else {
         $database = $chk;
     }
     //----------------------------------------------------------
     if (is_null(Constants::$mysqli) || !($chk = Constants::$mysqli->select_db($database))) {
         //------------------------------------------------------
         if (is_null($mysqli)) {
             $mysqli = new mysqli(ClassUtil::getStaticVal($class, "host"), ClassUtil::getStaticVal($class, "user"), ClassUtil::getStaticVal($class, "pass"));
         }
         //------------------------------------------------------
         if ($mysqli->connect_error != null || $mysqli->host_info == null) {
             $chk = array("result" => $mysqli, "error" => true, "bool" => false, "host_info" => !Constants::$debug ? NULL : $mysqli->host_info, "message" => $mysqli->connect_error);
             if (!Constants::$debug) {
                 $chk["loginInfo"] = array("host" => ClassUtil::getStaticVal($class, "host"));
             }
             return $chk;
         }
         //------------------------------------------------------
         Constants::$mysqli = $mysqli;
     }
     //----------------------------------------------------------
     Constants::$mysqli->select_db($database);
     //----------------------------------------------------------
     if (Constants::$mysqli->error != null) {
         $chk = array("result" => Constants::$mysqli, "error" => true, "bool" => false, "message" => Constants::$mysqli->error);
         if (!Constants::$debug) {
             $chk["loginInfo"] = array("host" => ClassUtil::getStaticVal($class, "host"));
         }
         return $chk;
     }
     //----------------------------------------------------------
     return Constants::$mysqli;
 }
Exemplo n.º 12
0
 public static function invoke($_conf = array())
 {
     try {
         Browser::time("invoked");
         $global_config = array_merge(array('CONTROLLER' => 'web.php', 'DEFAULT_DB' => 'DB1', 'CONSOLE_FUN' => 'console.log', 'RX_MODE_DEBUG' => FALSE, 'PROJECT_ROOT_DIR' => "./"), $_conf);
         // Loads all the Constants
         define('PROJECT_ROOT_DIR', $global_config['PROJECT_ROOT_DIR']);
         define('PROJECT_ID', md5(PROJECT_ROOT_DIR . $global_config['CONTROLLER']));
         FileUtil::$PROJECT_ROOT_DIR = PROJECT_ROOT_DIR;
         include_once 'constants.php';
         ob_start();
         session_start();
         Config::load(PROJECT_ROOT_DIR . "app/meta/project.properties", PROJECT_ROOT_DIR . "config/project.properties", $global_config);
         // Initialze Rudrax
         self::init();
         Browser::time("After Init");
         $config = Config::getSection("GLOBAL");
         $db_connect = false;
         Browser::time("Before DB Connect");
         /**
          * NOTE:- NO need to connect DB automatically, it should be connecte donly when required;
          */
         // if (isset ( $config ["DEFAULT_DB"] )) {
         // $RDb = self::getDB ( $config ["DEFAULT_DB"] );
         // $db_connect = true;
         // }
         Browser::time("Before-First Reload");
         // Define Custom Request Plugs
         if (FIRST_RELOAD) {
             ClassUtil::scan();
         }
         self::findAndExecuteController();
         self::invokeController();
         return null;
         Browser::time("Before Saving");
         Config::save();
         Browser::time("Invoked:Ends");
     } catch (Exception $e) {
         print_line($e->getMessage());
         print_line($e->getTraceAsString());
     }
 }
Exemplo n.º 13
0
$class = explode("/", $class[sizeof($class) - 2]);
//----------------------------------------------------------
$class = end($class);
//----------------------------------------------------------
require_once $classPath;
//----------------------------------------------------------
if (isset($_OBJ['staticClass']) && $_OBJ['staticClass'] == "true" && is_null(Constants::$conn)) {
    GenFun::hostConnect();
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//init
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//----------------------------------------------------------
$object = !isset($_OBJ['staticClass']) ? ClassUtil::classFromString($class) : $class;
//----------------------------------------------------------
$object = SetPublicProp::findObj($object, $_OBJ['functionName']);
//----------------------------------------------------------
$orig_functionName = $_OBJ['functionName'];
//----------------------------------------------------------
$_OBJ['functionName'] = $object['string'];
//----------------------------------------------------------
$object = $object['class'];
//----------------------------------------------------------
//if (!file_exists($classPath) && is_null($object)) die($classPath." does not exist!!!!");
//----------------------------------------------------------
if (isset($_OBJ['prop'])) {
    SetPublicProp::go($object, $_OBJ['prop']);
}
//----------------------------------------------------------
Exemplo n.º 14
0
 public static function isApplicationBean($className)
 {
     return ClassUtil::isSubclassOf($className, "ApplicationBean");
 }
Exemplo n.º 15
0
function rx_scan_dir($annotations, $dir)
{
    $allController = ClassUtil::getControllerArray();
    $dir_iterator = new RecursiveDirectoryIterator($dir);
    $iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST);
    // could use CHILD_FIRST if you so wish
    foreach ($iterator as $filename => $file) {
        if ($file->isFile()) {
            if (fnmatch("*/handler/*.php", $file->getPathname()) || fnmatch("*\\\\handler\\\\*.php", $file->getPathname())) {
                require_once $file->getPathname();
                $className = str_replace(".php", "", $file->getFilename());
                $scan = true;
                if (ClassUtil::getMTime($className) >= $file->getMTime()) {
                    $scan = false;
                }
                if ($scan && class_exists($className)) {
                    $result = $annotations->getClassAnnotations($className);
                    if (isset($result["Handler"]) && isset($result["Handler"][0]) && !empty($result["Handler"][0])) {
                        ClassUtil::setHandler($result["Handler"][0], array("className" => $className, "filePath" => $file->getPathname(), "mtime" => $file->getMTime(), "requestParams" => isset($result["RequestParams"])));
                        Browser::warn("HandleScanned::", ClassUtil::getHandler($result["Handler"][0]));
                        ClassUtil::setMTime($className, $file->getMTime());
                    }
                }
            } else {
                if (fnmatch("*/controller/*.php", $file->getPathname()) || fnmatch("*\\\\controller\\\\*.php", $file->getPathname())) {
                    require_once $file->getPathname();
                    $className = str_replace(".php", "", $file->getFilename());
                    $scan = true;
                    if (ClassUtil::getMTime($className) >= $file->getMTime()) {
                        $scan = false;
                    }
                    if ($scan && class_exists($className)) {
                        $methods = get_class_methods($className);
                        foreach ($methods as $method) {
                            $result = $annotations->getMethodAnnotations($className, $method);
                            Browser::error("ControllerScanned::", $result);
                            if (isset($result["RequestMapping"]) && isset($result["RequestMapping"][0]) && isset($result["RequestMapping"][0]["url"])) {
                                $allController[] = array("className" => $className, "method" => $method, "filePath" => $file->getPathname(), "mtime" => $file->getMTime(), "mappingUrl" => $result["RequestMapping"][0]["url"], "requestParams" => isset($result["RequestParams"]), "cache" => isset($result["RequestMapping"][0]["cache"]) ? $result["RequestMapping"][0]["cache"] : FALSE, "type" => isset($result["RequestMapping"][0]["type"]) ? $result["RequestMapping"][0]["type"] : NULL, "requestMethod" => isset($result["RequestMapping"][0]["method"]) ? strtoupper($result["RequestMapping"][0]["method"]) : NULL);
                            }
                        }
                        Browser::warn("ControllerScanned::", $allController[$result["RequestMapping"][0]["url"]]);
                        ClassUtil::setMTime($className, $file->getMTime());
                    }
                } else {
                    if (fnmatch("*/model/*.php", $file->getPathname()) || fnmatch("*\\\\model\\\\*.php", $file->getPathname())) {
                        require_once $file->getPathname();
                        $className = str_replace(".php", "", $file->getFilename());
                        $scan = true;
                        if (ClassUtil::getMTime($className) >= $file->getMTime()) {
                            $scan = false;
                        }
                        if ($scan && class_exists($className)) {
                            $result = $annotations->getClassAnnotations($className);
                            if (isset($result["Model"]) && isset($result["Model"][0]) && !empty($result["Model"][0])) {
                                ClassUtil::setModel($result["Model"][0], array("className" => $className, "filePath" => $file->getPathname(), "mtime" => $file->getMTime(), "type" => $result["Model"][0]));
                                Browser::warn("ModelScanned::", ClassUtil::getModel($result["Model"][0]));
                                ClassUtil::setMTime($className, $file->getMTime());
                            }
                        }
                    }
                }
            }
        }
    }
    ClassUtil::setControllerArray($allController);
}
Exemplo n.º 16
0
 public static function invoke($_conf = array())
 {
     Browser::time("invoked");
     $global_config = array_merge(array('CONTROLLER' => 'web.php', 'DEFAULT_DB' => 'DB1', 'CONSOLE_FUN' => 'console.log', 'RX_MODE_DEBUG' => FALSE, 'PROJECT_ROOT_DIR' => "../"), $_conf);
     // Loads all the Constants
     define('PROJECT_ROOT_DIR', $global_config['PROJECT_ROOT_DIR']);
     define('PROJECT_ID', md5(PROJECT_ROOT_DIR . $global_config['CONTROLLER']));
     FileUtil::$PROJECT_ROOT_DIR = PROJECT_ROOT_DIR;
     include_once 'constants.php';
     ob_start();
     session_start();
     Config::load(PROJECT_ROOT_DIR . "app/meta/project.properties", PROJECT_ROOT_DIR . "config/project.properties", $global_config);
     // Initialze Rudrax
     self::init();
     Browser::time("After Init");
     $config = Config::getSection("GLOBAL");
     $db_connect = false;
     Browser::time("Before DB Connect");
     /**
      * NOTE:- NO need to connect DB automatically, it should be connecte donly when required;
      */
     // if (isset ( $config ["DEFAULT_DB"] )) {
     // $RDb = self::getDB ( $config ["DEFAULT_DB"] );
     // $db_connect = true;
     // }
     Browser::time("Before-First Reload");
     // Define Custom Request Plugs
     if (FIRST_RELOAD) {
         ClassUtil::scan();
     }
     self::findAndExecuteController();
     self::invokeController();
     DBService::close();
     Browser::time("Before Saving");
     Config::save();
     Browser::time("After Saving");
     $clientConfig = Config::get("CLIENT_CONST");
     /*
      * $RX_ENCRYPT_PATH is applicable only if either MINFY or MERGE, this variable ise used by .htaccess file
      */
     $RX_ENCRYPT_PATH = !RX_MODE_DEBUG && ($clientConfig["RX_JS_MIN"] || $clientConfig["RX_JS_MERGE"]);
     Browser::header(RX_MODE_DEBUG . "." . $clientConfig["RX_JS_MIN"] . "." . $clientConfig["RX_JS_MERGE"]);
     if ($RX_ENCRYPT_PATH) {
         setcookie('RX-ENCRYPT-PATH', "TRUE", 0, "/");
         define("RX_ENCRYPT_PATH", true);
     } else {
         removecookie('RX-ENCRYPT-PATH');
         define("RX_ENCRYPT_PATH", false);
     }
     Browser::time("Invoked:Ends");
 }