Esempio n. 1
0
 function app($service = \null)
 {
     $container = SharedContainer::getInstance();
     if ($container === \null) {
         throw new \RuntimeException('There is no container in SharedContainer', 500);
     }
     if ($service !== \null) {
         return $container->get($service);
     }
     return $container->get('app');
 }
Esempio n. 2
0
 public function translate($key, $code = \null)
 {
     $container = SharedContainer::getInstance();
     if ($code === \null && $container->has('language') && ($language = $container->get('language')) instanceof LanguageInterface) {
         $code = $language->getCode();
     } else {
         $code = $container->get('config')->get('language.default');
     }
     if ($code === \null) {
         return $key;
     }
     if (!isset($this->translations[$code])) {
         $this->loadTranslations($code);
     }
     if (isset($this->translations[$code][$key])) {
         return $this->translations[$code][$key];
     }
     return $key;
 }
Esempio n. 3
0
 /**
  * Initialize database adapter.
  *
  * @return void
  * @throws \Micro\Database\Table\Exception
  */
 protected function _setupDatabaseAdapter()
 {
     if (!$this->_db) {
         $this->_db = self::getDefaultAdapter();
         if ($this->_db === \null) {
             try {
                 SharedContainer::getInstance()->get('db');
                 $this->_db = self::getDefaultAdapter();
             } catch (\Exception $e) {
             }
         }
         if (!$this->_db instanceof AdapterAbstract) {
             throw new Exception('No adapter found for ' . get_class($this));
         }
     }
 }