public static function getField($name) { $config = Config::setup(); if (!is_null($config) && is_array($config->config)) { if (isset($config->config[$name])) { return $config->config[$name]; } } return null; }
* /support Twig files for the admin support of the framework * /vendor If you are using composer then it puts stuff in here. * * The .htaccess file directs * anything in /assets to be served by Apache unless you are usin gthe Assets class to improve caching * anything beginning "ajax" to be called directly i.e. ajax.php (this may or may not be useful - remove it if not) * everything else gets passed into this script where it treats the URL thus: * / => /home and then * /action/r/e/st/ => Broken down in Context class. An action and an array of parameters. * * Query strings and/or post fields are in the $_ arrays as normal but please use the access functions provided * to get at the values whenever appropriate! */ include 'class/support/framework.php'; Framework::initialise(); Config::setup(); # add default headers etc. - anything that the user choses to add to the code. $local = Local::getinstance()->setup(__DIR__, FALSE, TRUE, TRUE, TRUE); # Not Ajax, debug on, load twig, load RB $context = Context::getinstance()->setup(); $mfl = $local->makebasepath('maintenance'); # maintenance mode indicator file if (file_exists($mfl) && !$context->hasadmin()) { # only let administrators in as we are doing maintenance. Could have a similar feature for other roles $context->web()->sendtemplate('support/maintenance.twig', StatusCodes::HTTP_OK, 'text/html', ['msg' => file_get_contents($mfl)]); exit; } $action = $context->action(); if ($action === '') { # default to home if there is nothing $action = 'home';
/** * Function to start the whole gini framework. **/ public static function start() { error_reporting(E_ALL & ~E_NOTICE); spl_autoload_register('\\Gini\\Core::autoload'); register_shutdown_function('\\Gini\\Core::shutdown'); set_exception_handler('\\Gini\\Core::exception'); set_error_handler('\\Gini\\Core::error', E_ALL & ~E_NOTICE); assert_options(ASSERT_ACTIVE, 1); assert_options(ASSERT_WARNING, 0); assert_options(ASSERT_QUIET_EVAL, 1); assert_options(ASSERT_CALLBACK, '\\Gini\\Core::assertion'); mb_internal_encoding('utf-8'); mb_language('uni'); define('CLASS_DIR', 'class'); define('VIEW_DIR', 'view'); define('RAW_DIR', 'raw'); define('DATA_DIR', 'data'); define('CACHE_DIR', 'cache'); $info = self::import(SYS_PATH); if (isset($_SERVER['GINI_APP_PATH'])) { $app_path = $_SERVER['GINI_APP_PATH']; define('APP_PATH', $app_path); $info = self::import(APP_PATH); } else { define('APP_PATH', SYS_PATH); } define('APP_ID', $info->id); // load composer if detected $composer_path = APP_PATH . '/vendor/autoload.php'; if (file_exists($composer_path)) { require_once $composer_path; } Config::setup(); Event::setup(); !method_exists('\\Gini\\Application', 'setup') or \Gini\Application::setup(); // 生成一个 APP_HASH 用于做版本唯一说明 define('APP_HASH', sha1(array_reduce(self::$MODULE_INFO, function ($str, $info) { return $str . ':' . $info->id . '/' . $info->version; }, ''))); // module setup won't be run before CLASS cache if (isset($GLOBALS['gini.class_map'])) { foreach (self::$MODULE_INFO as $name => $info) { $class = '\\Gini\\Module\\' . strtr($name, ['-' => '', '_' => '', '/' => '']); if (!$info->error && method_exists($class, 'setup')) { call_user_func($class . '::setup'); } } } global $argv; !method_exists('\\Gini\\Application', 'main') or \Gini\Application::main($argv); }
/** * The evergreen autoloader class that loads in an evergreen class using the evergreen naming convention. * * @access public * @static * @param string $class_name The name of the class that is to be loaded */ public static function evergreenLoader($className) { // if class already exists then dont continue if (class_exists($className, false) || interface_exists($className, false)) { return true; } // setup the config if (!class_exists('Config', false)) { include dirname(__FILE__) . '/config.class.php'; Config::setup(); } // parse the incoming class name and assign the resulting array to $class $class = self::parseClassName($className); // run through $class and find what needs to be loaded if (isset($class['type'])) { $basePath = Reg::get("Path.physical") . (!empty($class['branch']) ? '/branches/' . $class['branch'] : ''); if ($class['type'] == 'controller' && file_exists($basePath . '/controllers/' . $class['class'] . '.php')) { //controller include include_once $basePath . '/controllers/' . $class['class'] . '.php'; } else { if ($class['type'] == 'model' && file_exists($basePath . '/models/' . $class['class'] . '.php')) { // model include include_once $basePath . '/models/' . $class['class'] . '.php'; } else { if ($class['type'] == 'helper' && file_exists($basePath . '/helpers/' . $class['class'] . '.php')) { // helper include include_once $basePath . '/helpers/' . $class['class'] . '.php'; } else { if ($class['type'] == 'plugin' && file_exists($basePath . '/plugins/' . $class['class'] . '.php')) { // plugin include include_once $basePath . '/plugins/' . $class['class'] . '.php'; } else { if ($class['type'] == 'driver') { // model driver include if (isset($class['specificDriver'])) { // check if driver needs to be loaded from a branch if (!empty($class['branch'])) { $branchDriverPath = Reg::get("Path.physical") . '/branches/' . $class['branch'] . '/config/drivers/' . strtolower(str_replace('_', '.', $class['original'])) . '.class.php'; if (file_exists($branchDriverPath)) { include_once $branchDriverPath; } unset($branchDriverPath); } // load main driver if not loading from a branch $mainDriverPath = Reg::get("Path.physical") . '/config/drivers/' . strtolower(str_replace('_', '.', $class['original'])) . '.class.php'; if (!class_exists($class['original'], false) && file_exists($mainDriverPath)) { include_once $mainDriverPath; } unset($mainDriverPath); } else { // other db class includes if (file_exists(Reg::get("Path.physical") . '/lib/' . strtolower(str_replace('_', '.', $class['original'])) . '.class.php')) { include_once Reg::get("Path.physical") . '/lib/' . strtolower(str_replace('_', '.', $class['original'])) . '.class.php'; } } } } } } } unset($basePath); } else { // lib file includes if (file_exists(Reg::get("Path.physical") . '/lib/' . $class['class'] . '.class.php')) { include_once Reg::get("Path.physical") . '/lib/' . $class['class'] . '.class.php'; } } // after running through all the loads if the desired class now still doesnÕt exist then create a dummy class that will throw an error if (class_exists($class['original'], false) || interface_exists($class['original'], false)) { // if the db class was called then run setup if (strtolower($class['original']) == 'db') { DB::setup(); } // if the class has a type and it is a helper or a plugin check for versioning and mode requirements if (isset($class['type']) && in_array($class['type'], array('helper', 'plugin'))) { $classVars = get_class_vars($class['original']); if (isset($classVars['requiredSystemMode']) && $classVars['requiredSystemMode'] != Reg::get("System.mode")) { // The system does not have the required mode so don't load the object throw new EvergreenException("REQUIRED_SYSTEM_MODE", array('messageArgs' => array('name' => $class['original'], 'type' => ucwords($class['type']), 'class-required-mode' => $classVars['requiredSystemMode']))); } if (isset($classVars['minimumSystemVersion']) && !version_compare(Reg::get("System.version"), $classVars['minimumSystemVersion'], ">=")) { // The system version is lower than the object's required minimum so don't load the object throw new EvergreenException("MINIMUM_SYSTEM_VERSION", array('messageArgs' => array('name' => ', ' . $class['original'] . ',', 'type' => ucwords($class['type']), 'class-required-version' => $classVars['minimumSystemVersion']))); } if (isset($classVars['maximumSystemVersion']) && !version_compare(Reg::get("System.version"), $classVars['maximumSystemVersion'], "<=")) { // The system version is higher than the object's required maximum so don't load the object throw new EvergreenException("MAXIMUM_SYSTEM_VERSION", array('messageArgs' => array('name' => ', ' . $class['original'] . ',', 'type' => ucwords($class['type']), 'class-required-version' => $classVars['maximumSystemVersion']))); } unset($classVars); } } unset($class); }