예제 #1
0
파일: Email.php 프로젝트: madoka8/ice-base
 /**
  * Get email template and load view with params
  *
  * @param string $name View name to load
  * @param array $params Params to send to the view
  * @return string
  */
 public function getTemplate($name, $params = [])
 {
     // Prepare view service
     $view = new View();
     $view->setViewsDir(__ROOT__ . '/app/views/');
     $view->setMainView('email');
     // Options for Sleet template engine
     $sleet = new Sleet($view, Di::fetch());
     $sleet->setOptions(['compileDir' => __ROOT__ . '/app/tmp/sleet/', 'trimPath' => __ROOT__, 'compile' => Compiler::IF_CHANGE]);
     // Set template engines
     $view->setEngines(['.sleet' => $sleet, '.phtml' => 'Ice\\Mvc\\View\\Engine\\Php']);
     $view->setContent($view->render($name, $params));
     return $view->layout();
 }
예제 #2
0
파일: Base.php 프로젝트: madoka8/ice-base
 /**
  * Register services in the dependency injector
  *
  * @return void
  */
 public function registerServices()
 {
     $config = $this->config;
     $this->di->config = $config;
     $this->di->dump = new Dump(true);
     $this->di->crypt = new Crypt($config->crypt->key);
     $this->di->filter = new Filter();
     $this->di->session = new Session();
     $this->di->request = new Request();
     $this->di->cookies = new Cookies($config->cookie->salt);
     $this->di->response = new Response();
     $this->di->i18n = new I18n($config->i18n->toArray());
     $this->di->auth = new Auth($config->auth->toArray());
     // Set the url service
     $this->di->set('url', function () use($config) {
         $url = new Url();
         $url->setBaseUri($config->app->base_uri);
         $url->setStaticUri($config->app->static_uri);
         return $url;
     });
     $this->di->tag = new Tag();
     $this->di->flash = new Flash();
     // Set the assets service
     $this->di->set('assets', function () use($config) {
         $assets = new Assets();
         $assets->setOptions(['source' => __ROOT__ . '/public/', 'target' => 'min/', 'minify' => $config->env->assets->minify]);
         return $assets;
     });
     // Set the dispatcher service
     $this->di->set('dispatcher', function () use($config) {
         $dispatcher = new Dispatcher();
         $dispatcher->setSilent($config->env->silent->dispatcher);
         return $dispatcher;
     });
     // Set the router service
     $this->di->set('router', function () use($config) {
         $router = new Router();
         $router->setDefaultModule($config->modules->application->default);
         $router->setSilent($config->env->silent->router);
         $router->setRoutes((new Routes())->universal());
         return $router;
     });
     // Set the db service
     $this->di->set('db', function () use($config) {
         $db = new Db($config->database->type, $config->database->host, $config->database->port, $config->database->name, $config->database->user, $config->database->password);
         if ($config->database->type !== "mongodb" && $config->app->env == "development") {
             $db->getDriver()->getClient()->setAttribute(\Pdo::ATTR_ERRMODE, \Pdo::ERRMODE_EXCEPTION);
         }
         return $db;
     });
     // Set the view service
     $this->di->set('view', function () use($config) {
         $view = new View();
         $view->setViewsDir(__ROOT__ . '/app/views/');
         // Options for Sleet template engine
         $sleet = new Sleet($view, $this->di);
         $sleet->setOptions(['compileDir' => __ROOT__ . '/app/tmp/sleet/', 'trimPath' => __ROOT__, 'compile' => $config->env->sleet->compile]);
         // Set template engines
         $view->setEngines(['.md' => 'App\\Libraries\\Markdown', '.sleet' => $sleet, '.phtml' => 'Ice\\Mvc\\View\\Engine\\Php']);
         return $view;
     });
 }
예제 #3
0
 /**
  * Register services in the dependency injector
  *
  * @return void
  */
 public function registerServices()
 {
     $config = $this->config;
     $this->di->config = $config;
     $this->di->i18n = new I18n($config->i18n->toArray());
     // Set the url service
     $this->di->set('url', function () use($config) {
         $url = new Url();
         $url->setBaseUri($config->app->base_uri);
         $url->setStaticUri($config->app->static_uri);
         return $url;
     });
     $this->di->tag = new Tag();
     $this->di->dispatcher = new Dispatcher();
     $this->di->set('router', function () {
         $router = new Router();
         $router->setDefaultModule('shell');
         return $router;
     });
     // Set the db service
     $this->di->set('db', function () use($config) {
         $db = new Db($config->database->type, $config->database->host, $config->database->port, $config->database->name, $config->database->user, $config->database->password);
         if ($config->database->type !== "mongodb" && $config->app->env == "development") {
             $db->getDriver()->getClient()->setAttribute(\Pdo::ATTR_ERRMODE, \Pdo::ERRMODE_EXCEPTION);
         }
         return $db;
     });
     // Set the view service
     $this->di->set('view', function () {
         $view = new View();
         $view->setViewsDir(__ROOT__ . '/app/views/');
         // Options for Sleet template engine
         $sleet = new Sleet($view, $this->di);
         $sleet->setOptions(['compileDir' => __ROOT__ . '/app/tmp/sleet/', 'trimPath' => __ROOT__, 'compile' => Compiler::IF_CHANGE]);
         // Set template engines
         $view->setEngines(['.md' => 'App\\Libraries\\Markdown', '.sleet' => $sleet, '.phtml' => 'Ice\\Mvc\\View\\Engine\\Php']);
         return $view;
     });
 }