Example #1
0
 /**
  * Return an array for passing to Zend\Loader\AutoloaderFactory.
  *
  * @return array
  */
 public function getAutoloaderConfig()
 {
     $namespace = $this->getInspector()->getNamespaceName();
     $path = $this->getInspector()->getFilePath();
     ApplicationFactory::getInstance()->registerNamespace($namespace, $path . '/src');
     return array('Zend\\Loader\\StandardAutoloader' => array('namespaces' => array($namespace => $namespace . '/src/' . $namespace)));
 }
Example #2
0
 /**
  *
  */
 public function run()
 {
     // load request
     $this->request = Request::createFromGlobals();
     $this->response = new Response('', 200);
     // register routes
     $this->registerRouteCollection();
     list($controller, $arguments) = $this->resolveController();
     $options = ApplicationFactory::getInstance()->getConfig();
     // if no controller found, force it to a Error controller defined in config
     if (null == $controller) {
         $controller = $this->assembleController($options['error404Controller']);
         $arguments = array();
         $this->response->setStatusCode(404);
     }
     $content = '';
     try {
         // try to run the default controller
         $content = call_user_func_array($controller, $arguments);
     } catch (\Exception $e) {
         // if any error/exception found, try to catch it and display it
         $this->request->attributes->add(array('e' => $e, 'isDev' => $this->isDev()));
         // Error controller defined in config
         $controller = $this->assembleController($options['error500Controller']);
         // cchange status code to 500
         $this->response->setStatusCode(500);
         // run the new controller
         $content = call_user_func_array($controller, $arguments);
     }
     if ($content instanceof Response) {
         $this->response = $content;
     } else {
         $this->response->setContent($content);
     }
     $this->response->send();
 }
 /**
  * @param $route
  * @param array $data
  * @throws Exception\InvalidRouteException
  */
 public function urlByRoute($route, $data = array())
 {
     $chunk = false;
     $options = ApplicationFactory::getInstance()->getConfig();
     foreach ($options['routes'] as $r) {
         if ($r[0] == $route) {
             $chunk = $r[1][0];
             if (!empty($r[1][1])) {
                 $data = Utils::arrayMergeRecursiveRight($r[1][1], $data);
             }
         }
     }
     if (false === $chunk) {
         throw new Exception\InvalidRouteException(sprintf('Could not load route by name \'%s\'. Please check if route exists.', $route));
     }
     preg_match_all('/\\{[^\\}]+\\}/i', $chunk, $keys);
     foreach ($keys[0] as $key) {
         $key = substr($key, 1, -1);
         if (isset($data[$key]) && $data[$key] !== NULL && $data[$key] !== '') {
             $regexp = $regexp = "/\\{{$key}\\}/i";
             $value = $data[$key];
         } else {
             $regexp = $regexp = "/\\/\\{{$key}\\}.*/i";
             $value = '';
         }
         $chunk = preg_replace($regexp, $value, $chunk);
     }
     return $this->url($chunk);
     return '';
 }
Example #4
0
 /**
  * Obtains a database adapter.
  *
  * @return \Athem\Db\AdapterInterface
  */
 public function getDbAdapter()
 {
     if (null === self::$dbAdapter) {
         $config = ApplicationFactory::getInstance()->getConfig();
         if (empty($config['db'])) {
             throw new DbException\InvalidConfigurationException('No configuration found for dbAdapter!');
         }
         if (empty($config['db']['connection'])) {
             throw new DbException\InvalidConfigurationException('No connection configuration found for dbAdapter!');
         }
         if ($config == 'zend') {
             throw new \Exception('This feature is not implemented yet.');
         } else {
             self::$dbAdapter = \Netis\Db\AdapterFactory::create(empty($config['db']['connection']['dsn']) ? $config['db']['connection'] : $config['db']['connection']['dsn'], empty($config['db']['options']) ? array() : $config['db']['options']);
         }
         self::$dbAdapter->getEventManager()->addEventSubscriber(new \Doctrine\DBAL\Event\Listeners\MysqlSessionInit('utf8', 'utf8_unicode_ci'));
     }
     return self::$dbAdapter;
 }