Beispiel #1
0
 public function __construct($form, $application, array $data = null)
 {
     $application = $application ? $application : ini('runtime/application');
     $this->fields = YamlBackend::load(sprintf('applications/%s/forms/%s.yml', $application, $form));
     if ($data) {
         $this->data = $data;
         $this->is_bound = true;
     }
     $this->clean();
 }
Beispiel #2
0
 public static function load_plugins($_application = null, $_plugin_name = null, $_position = null)
 {
     /*
      * the global plugins
      */
     $plugins = YamlBackend::load('etc/conf.d/plugins.yml');
     if ($plugins) {
         foreach ((array) $plugins as $hook_name => $plugin) {
             if (!$plugin) {
                 continue;
             }
             foreach ((array) $plugin as $plugin_name => $plugin_action) {
                 self::register($hook_name, $plugin_name, $plugin_action);
             }
         }
     }
     /*
      * load the single application's plugins
      */
     if ($_application) {
         $installed_apps = array($_application);
     } else {
         $installed_apps = ini('base/INSTALLED_APPS');
     }
     $installed_apps_config = BaseConfig::get_apps_config($installed_apps);
     foreach ((array) $installed_apps_config as $app_config) {
         foreach ((array) $app_config['plugins'] as $hook_name => $ps) {
             if (!$ps) {
                 continue;
             }
             /*
              * load the decided plugin
              */
             if ($_plugin_name && $ps[$_plugin_name]) {
                 self::register($hook_name, $_plugin_name, $ps[$_plugin_name]);
                 return;
             }
             foreach ((array) $ps as $name => $plugin) {
                 self::register($hook_name, $name, $plugin);
             }
         }
     }
 }
Beispiel #3
0
 /**
  * loadData
  *
  * Load and parse data from a yml file
  *
  * @throws Doctrine_Parser_Exception parsing error
  * @param  string  $path  Path to load yaml data from
  * @return array   $array Array of parsed yaml data
  */
 public function loadData($path)
 {
     try {
         /*
          * I still use the doLoad method even if sfYaml can load yml from a file
          * since this way Doctrine can handle file on it own.
          */
         return YamlBackend::load($path);
         /*
                   $contents = $this->doLoad($path);
         
                   $array = sfYaml::load($contents);
         
                   return $array;
         * 
         */
     } catch (InvalidArgumentException $e) {
         // rethrow the exceptions
         $rethrowed_exception = new Doctrine_Parser_Exception($e->getMessage(), $e->getCode());
         throw $rethrowed_exception;
     }
 }
Beispiel #4
0
 public static function __init__($run_mode)
 {
     self::$config['runtime'] = YamlBackend::load('etc/environment.d/' . $run_mode . '.yml');
 }
Beispiel #5
0
 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'];
 }
Beispiel #6
0
 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');
     }
 }