示例#1
0
文件: Pop.php 项目: popphp/popcorn
 /**
  * Constructor
  *
  * Instantiate an application object
  *
  * Optional parameters are a service locator instance, a router instance,
  * an event manager instance or a configuration object or array
  */
 public function __construct()
 {
     $args = func_get_args();
     foreach ($args as $i => $arg) {
         if (is_array($arg) && isset($arg['routes'])) {
             // Check for combined route matches
             foreach ($arg['routes'] as $key => $value) {
                 if (strpos($key, ',') !== false) {
                     foreach ($arg['routes'][$key] as $route => $controller) {
                         $this->setRoutes($key, $route, $controller);
                     }
                     unset($arg['routes'][$key]);
                 }
             }
             // Check for direct route method matches
             $routeKeys = array_keys($this->routes);
             foreach ($routeKeys as $key) {
                 if (isset($arg['routes'][$key])) {
                     foreach ($arg['routes'][$key] as $route => $controller) {
                         $this->setRoute($key, $route, $controller);
                     }
                     unset($arg['routes'][$key]);
                 }
             }
             if (count($arg['routes']) == 0) {
                 unset($args[$i]['routes']);
             }
         }
     }
     switch (count($args)) {
         case 1:
             parent::__construct($args[0]);
             break;
         case 2:
             parent::__construct($args[0], $args[1]);
             break;
         case 3:
             parent::__construct($args[0], $args[1], $args[2]);
             break;
         case 4:
             parent::__construct($args[0], $args[1], $args[2], $args[3]);
             break;
         case 5:
             parent::__construct($args[0], $args[1], $args[2], $args[3], $args[4]);
             break;
         default:
             parent::__construct();
     }
 }