123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- <?php
- namespace RTP\Module;
- class AutomaticallyModule
- {
- private static $path;
- private static $groupName;
- private static $controllerName;
- private static $moduleName;
- private static $operationName;
- private static $daoName;
- private static $modelName;
- public static function start()
- {
-
- spl_autoload_register('self::autoloadUserController');
- spl_autoload_register('self::autoloadUserModule');
- spl_autoload_register('self::autoloadUserDao');
- spl_autoload_register('self::autoloadRTPModule');
-
- if (file_exists(PATH_FW . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'eo_config.php')) {
- quickRequire(PATH_FW . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'eo_config.php');
- }
-
- if (file_exists(PATH_FW . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'version.php')) {
- quickRequire(PATH_FW . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'version.php');
- }
- self::$groupName = cleanFormat($_GET['g']);
- self::$controllerName = cleanFormat($_GET['c']);
- self::$moduleName = cleanFormat($_GET['c']);
- self::$operationName = cleanFormat($_GET['o']);
-
- if (!isset(self::$groupName))
- throw new ExceptionModule(11002, 'error in lack of groupName');
- else
- if (!isset(self::$controllerName))
- throw new ExceptionModule(11003, 'error in lack of controllerName');
- else
- if (!isset(self::$operationName))
- throw new ExceptionModule(11004, 'error in lack of operationName');
-
- $class = new \ReflectionClass(self::$controllerName . DIR_CONTROLLER);
-
- $php_magic_methods = array(
- '__construct',
- '__destruct',
- '__call',
- '__callstatic',
- '__get',
- '__set',
- '__isset',
- '__unset',
- '__sleep',
- '__wakeup',
- '__tostring',
- '__invoke',
- '__set_state',
- '__clone',
- '__debugInfo'
- );
-
- if (!in_array(strtolower(self::$operationName), $php_magic_methods) && $class->hasMethod(self::$operationName)) {
-
- $method = $class->getMethod(self::$operationName);
-
- if ($method->isPublic()) {
-
- if ($method->isStatic()) {
- $method->invoke(NULL);
- } else {
- $method->invoke($class->newInstance());
- }
- } else {
-
- throw new ExceptionModule(11005, 'operation isn\'t a public function');
- }
- } else {
-
- throw new ExceptionModule(11006, 'undefined operation or illegal operation name');
- }
- }
-
- public static function autoloadUserController($className)
- {
- $path = realpath(PATH_APP . DIRECTORY_SEPARATOR . self::$groupName . DIRECTORY_SEPARATOR . DIR_CONTROLLER . DIRECTORY_SEPARATOR . self::$controllerName . DIR_CONTROLLER . '.class.php');
- quickRequire($path);
-
- spl_autoload_unregister('self::autoloadUserController');
- }
-
- public static function autoloadUserModule($className)
- {
- $path = realpath(PATH_APP . DIRECTORY_SEPARATOR . self::$groupName . DIRECTORY_SEPARATOR . DIR_MODULE . DIRECTORY_SEPARATOR . $className . '.class.php');
- quickRequire($path);
- }
-
- public static function autoloadUserDao($className)
- {
- $path = realpath(PATH_APP . DIRECTORY_SEPARATOR . self::$groupName . DIRECTORY_SEPARATOR . DIR_DAO . DIRECTORY_SEPARATOR . $className . '.class.php');
- quickRequire($path);
- }
-
- public static function autoloadRTPModule($className)
- {
- $path = realpath(PATH_FW . PATH_MODULE) . DIRECTORY_SEPARATOR . str_replace('RTP\Module\\', '', $className) . '.class.php';
- quickRequire($path);
- }
- }
- ?>
|