Beispiel #1
0
 /**
  * Load application config
  *
  * @param  mixed $config
  * @throws \InvalidArgumentException
  * @return Application
  */
 public function loadConfig($config)
 {
     if (!is_array($config) && !$config instanceof \ArrayAccess && !$config instanceof \ArrayObject) {
         throw new \InvalidArgumentException('Error: The config must be either an array itself or implement ArrayAccess or extend ArrayObject.');
     }
     $this->config = $config;
     // If routes are set in the app config, register them with the application
     if (isset($this->config['routes']) && null !== $this->router) {
         $this->router->addRoutes($this->config['routes']);
     }
     // If services are set in the app config, register them with the application
     if (isset($this->config['services']) && null !== $this->services) {
         foreach ($this->config['services'] as $name => $service) {
             if (isset($service['call']) && isset($service['params'])) {
                 $this->setService($name, $service['call'], $service['params']);
             } else {
                 if (isset($service['call'])) {
                     $this->setService($name, $service['call']);
                 }
             }
         }
     }
     // If events are set in the app config, register them with the application
     if (isset($this->config['events']) && null !== $this->events) {
         foreach ($this->config['events'] as $event) {
             if (isset($event['name']) && isset($event['action'])) {
                 $this->on($event['name'], $event['action'], isset($event['priority']) ? $event['priority'] : 0);
             }
         }
     }
     return $this;
 }
Beispiel #2
0
 /**
  * Add routes
  *
  * @param  array $routes
  * @return Application
  */
 public function addRoutes(array $routes)
 {
     $this->router->addRoutes($routes);
     return $this;
 }