예제 #1
0
파일: yaml.php 프로젝트: uwitec/mgoa
 public static function load($file, $cache = 3600)
 {
     if ($cache > 0 && RUN_MODE == 'deploy') {
         import('system/bin/cache');
         $cache_instance = CacheBackend::get_instance();
         $cache_id = 'yaml_' . str_replace(array('/', '.'), '_', $file);
         if ($cache_instance->is_cached($cache_id)) {
             return $cache_instance->get($cache_id);
         } else {
             if (!is_file($file)) {
                 $file = Package::get_file($file);
                 if (!is_file($file)) {
                     return array();
                 }
             }
             import('system/vendors/spyc/spyc');
             $info = spyc_load_file($file);
             $cache_instance->set($cache_id, $info);
             return $info;
         }
     }
     if (!is_file($file)) {
         $file = Package::get_file($file);
         if (!is_file($file)) {
             return array();
         }
     }
     import('system/vendors/spyc/spyc');
     $info = spyc_load_file($file);
     return $info;
 }
예제 #2
0
파일: statics.php 프로젝트: uwitec/mgoa
 public static function load($path, $type = 'js', $extra = null)
 {
     $media_url = ini('base/MEDIA_URL');
     $file = Package::get_file('statics/' . $path, $type);
     if (is_file($file)) {
         return sprintf(self::$elements[$type], $media_url . $path, $extra);
     }
 }
예제 #3
0
 public function __construct($code = '', $message = '', $previous = '')
 {
     BaseConfig::load(Package::get_file('system/config/exception.yml'));
     $this->exception_messages = ini('exception/messages');
     if ($this->exception_messages[$code]) {
         $message = '(' . $code . ') ' . sprintf(_($this->exception_messages[$code]), $message);
     }
     $this->message = $message;
     $this->code = $code;
 }
예제 #4
0
파일: application.php 프로젝트: uwitec/mgoa
 protected function __load__mongo_model__($model)
 {
     import('system/bin/mongo');
     list($model_path, $model_name) = explode('.', $model);
     import('applications/' . $model_path . '/mongo_models/' . $model_name);
     BaseConfig::load(Package::get_file('etc/conf.d/database.yml'));
     $dbinfo = ini('database/mongo_' . RUN_MODE);
     call_user_func(array($model_name, 'setup'), $dbinfo);
     //        $model_name::setup($dbinfo);
 }
예제 #5
0
파일: doctrine.php 프로젝트: uwitec/mgoa
 public static function syncdb($apps = null, $drop_database = false, $append = true)
 {
     if (!self::$inited || !self::$connections) {
         self::init();
     }
     if (!$apps) {
         $apps = ini('base/INSTALLED_APPS');
     }
     if (!$apps) {
         return true;
     }
     if ($drop_database) {
         Doctrine_Core::dropDatabases();
         Doctrine_Core::createDatabases();
     }
     foreach ((array) $apps as $k => $app) {
         $app = str_replace('.', '/', $app);
         try {
             /*
              * Generate the models
              */
             if (isset($_GET['use_yaml'])) {
                 $schemas = Package::get_file(sprintf('applications/%s/%s', $app, 'schemas.yml'));
                 if (!is_file($schemas)) {
                     continue;
                 }
                 Doctrine_Core::generateModelsFromYaml($schemas, Package::get_folder(sprintf('applications/%s/models', $app)), self::$_generate_options);
             } else {
                 try {
                     import(sprintf('applications/%s/models/generated/*', $app));
                 } catch (DoesNotExistsException $e) {
                     continue;
                 }
             }
             /*
              * syncdb
              */
             Doctrine_Core::createTablesFromModels(Package::get_folder(sprintf('applications/%s/models', $app)), self::$_generate_options);
             /*
              * Insert test data
              */
             $dir = Package::get_folder(sprintf('applications/%s/fixtures', $app));
             if (is_dir($dir)) {
                 Doctrine_Core::loadData($dir, $append);
             }
         } catch (PDOException $e) {
             continue;
         }
     }
 }
예제 #6
0
파일: base.php 프로젝트: uwitec/mgoa
 public static function get_apps_config($apps)
 {
     foreach ($apps as $app) {
         $file = Package::get_file(sprintf('applications/%s/config.yml', $app));
         if (!is_file($file)) {
             continue;
         }
         /*
          * get the applications's config
          */
         $app_config = self::$config['apps_configs'][$app];
         if (!$app_config) {
             $app_config = YamlBackend::load($file);
             self::$config['apps_configs'][$app] = $app_config;
         }
     }
     return self::$config['apps_configs'];
 }
예제 #7
0
파일: base.php 프로젝트: uwitec/mgoa
 public static function trigger()
 {
     if (!self::$inited and ini('runtime/application_instance') instanceof BaseApplication) {
         self::init(ini('runtime/application_instance'));
     }
     list($hook_name, $params) = func_get_args();
     $params = (array) $params;
     if (!$hook_name || !key_exists($hook_name, self::$hooks)) {
         return false;
     }
     if ($hook_name == 'before_template_render') {
     }
     foreach ((array) self::$hooks[$hook_name] as $k => $v) {
         if (!is_callable(array($v['class'], $v['method']))) {
             $file = Package::get_file($v['file']);
             if (!is_file($file)) {
                 continue;
             }
             import($file);
         }
         array_unshift($params, self::$application);
         if (is_callable(array($v['class'], $v['method']))) {
             $result = call_user_func_array(array($v['class'], $v['method']), $params);
             /*
              * Call the callback function
              */
             if ($params['callback']) {
                 $result = call_user_func_array($params['callback'], (array) $result);
             }
         }
     }
 }
예제 #8
0
파일: base.php 프로젝트: uwitec/mgoa
 public static function dispatch($app, $view_action, array $params = null)
 {
     $view_action = $view_action ? $view_action : 'index';
     import('system/bin/application');
     import('system/bin/cache');
     /*
      * application's url pattern mapping
      */
     $app_map_array = YamlBackend::load('etc/conf.d/urls.yml');
     if ($app_map_array['map'][$app]) {
         $app = $app_map_array['map'][$app];
     } else {
         if (array_keys($app_map_array['map'], $app)) {
             throw new DispatchException(1011, $app . '/' . $view_action);
         }
     }
     /*
      * Cache all INSTALLED APPS urls pattern
      */
     $cache_id = 'URLS_MAP';
     $url_name_map_cache_id = 'URL_NAME_MAP';
     $app_map_array_flip_cache_id = 'URL_APP_MAP_ARRAY_FLIP';
     $cache_instance = CacheBackend::get_instance();
     if ($cache_instance->is_cached($cache_id) && RUN_MODE == 'deploy' && false) {
         self::$url_patterns = $cache_instance->get($cache_id);
         self::$url_name_map = $cache_instance->get($url_name_map_cache_id);
         $app_map_array_flip = $cache_instance->get($app_map_array_flip_cache_id);
     } else {
         $installed_apps = ini('base/INSTALLED_APPS');
         $app_map_array_flip = array_flip($app_map_array['map']);
         foreach ($installed_apps as $installed_app) {
             $urlpattern = YamlBackend::load(sprintf('applications/%s/urls.yml', $installed_app));
             if ($app_map_array_flip[$installed_app]) {
                 $installed_app = $app_map_array_flip[$installed_app];
             }
             /*
              * The url-name map to view action
              * like: url name='auth_login' => auth.AuthController.login
              */
             if ($urlpattern) {
                 foreach ($urlpattern as $key => $value) {
                     if ($value['name']) {
                         self::$url_name_map[$value['name']] = $installed_app . '/' . $key;
                     }
                 }
             }
             self::$url_patterns[$installed_app] = $urlpattern;
         }
         $cache_instance->set($cache_id, self::$url_patterns);
         if (self::$url_name_map) {
             $cache_instance->set($url_name_map_cache_id, self::$url_name_map);
         }
         $cache_instance->set($app_map_array_flip_cache_id, $app_map_array_flip);
     }
     $app_map_name = array_key_exists($app, $app_map_array_flip) ? $app_map_array_flip[$app] : $app;
     $urlpattern = self::$url_patterns[$app_map_name];
     try {
         /*
          * does not set the action key
          */
         if (!$urlpattern[$view_action]['action']) {
             $_c = ucfirst($app) . 'Controller';
             try {
                 import(Package::get_file(sprintf('applications/%s/%s', $app, $_c)));
                 $urlpattern[$view_action]['action'] = $_c . '.' . $view_action;
             } catch (DoesNotExistsException $e) {
                 throw new DispatchException(1011, $app . '/' . $view_action);
             }
         }
         list($controller, $method) = explode('.', $urlpattern[$view_action]['action']);
         import(sprintf('applications/%s/%s', $app, $controller));
         if (!is_callable(array($controller, $method))) {
             throw new DispatchException(1011, $app . '/' . $view_action);
         }
         /*
          * Set current application and action
          */
         RuntimeConfig::set('runtime/application', $app);
         RuntimeConfig::set('runtime/action', $view_action);
         RuntimeConfig::set('runtime/view_action', $app . '/' . $view_action);
         BaseConfig::load_application_config($app);
         try {
             $controller = new $controller($params);
             RuntimeConfig::set('runtime/application_instance', $controller);
             /*
              * Re-init the plugins with the application implements
              */
             Pluggable::init($controller);
             /*
              * Trigger the plugins in before_application_run
              */
             Pluggable::trigger('before_application_run');
             /*
              * Call the view-action method
              */
             call_user_func_array(array($controller, $method), (array) $params);
             /*
              * Dependence exception
              */
         } catch (DependenceException $e) {
             //pass
         }
         /*
          * When the DispatchException catched
          * Return the 404
          */
     } catch (DispatchException $e) {
         $app = new BaseApplication();
         Pluggable::init($app);
         Pluggable::trigger('before_application_run');
         $app->load('smarty')->display('404');
     }
 }
예제 #9
0
파일: smarty.php 프로젝트: uwitec/mgoa
 public function get_template_real_path($template)
 {
     $installed_apps = ini('base/INSTALLED_APPS');
     $tpl = Package::get_file('applications/' . ini('runtime/application') . '/templates/' . $template, 'tpl');
     if (!is_file($tpl)) {
         foreach ($installed_apps as $app) {
             $file = Package::get_file(sprintf('applications/%s/templates/%s', $app, $template), 'tpl');
             if (is_file($file)) {
                 $finded = true;
                 $tpl = $file;
                 break;
             }
         }
         if (!$finded) {
             $tpl = Package::get_file('var/templates/' . $template, 'tpl');
         }
     }
     if (!is_file($tpl)) {
         throw new DoesNotExistsException(1008, $tpl);
     }
     return $tpl;
 }
예제 #10
0
파일: filesystem.php 프로젝트: uwitec/mgoa
 public static function write($path, $content, $ext = 'php')
 {
     $path = Package::get_file($path, $ext);
     return @file_put_contents($path, $content);
 }