public static function get_instance()
 {
     if (self::$instance == NULL) {
         self::$instance = new SilkComponentManager();
     }
     return self::$instance;
 }
Example #2
0
 public function setup()
 {
     //Setup session stuff
     SilkSession::setup();
     //Load up the configuration file
     if (is_file(join_path(ROOT_DIR, 'config', 'setup.yml'))) {
         $config = SilkYaml::load(join_path(ROOT_DIR, 'config', 'setup.yml'));
     } else {
         die("Config file not found!");
     }
     //Add class path entries
     if (isset($config['class_autoload'])) {
         foreach ($config['class_autoload'] as $dir) {
             add_class_directory(join_path(ROOT_DIR, $dir));
         }
     }
     //Setup the database connection
     if (!isset($config['database']['dsn'])) {
         die("No database information found in the configuration file");
     }
     if (null == SilkDatabase::connect($config['database']['dsn'], $config['debug'], true, $config['database']['prefix'])) {
         die("Could not connect to the database");
     }
     silk()->set('config', $config);
     //Load components
     SilkComponentManager::load();
 }
Example #3
0
 /**
  * Automatically build routes for components.  This basically makes a
  * /:component/:controller/:action route for each component, or a
  * /:component/:action route if there is only one controller.
  *
  * @return void
  * @author Greg Froese
  **/
 public static function build_default_component_routes()
 {
     $components = SilkComponentManager::list_components();
     foreach ($components as $component => $controllers) {
         foreach ($controllers as $one_controller) {
             $class_name = str_replace("class.", "", str_replace(".php", "", str_replace("_controller", "", $one_controller)));
             if (count($controllers) > 1) {
                 $route = "/{$component}/{$class_name}/:action";
                 $params = array("component" => $component, "controller" => $class_name);
             } elseif (count($controllers) == 1 && $component == $class_name) {
                 $route = "/{$component}/:action";
                 $params = array("component" => $component, "controller" => $class_name);
             }
             SilkRoute::register_route($route, $params);
         }
     }
 }