Пример #1
0
 public static function make($name, array $data = array(), $engine = self::ENGINE_AUTO)
 {
     is_null(self::$TWIG_OPTION_DEBUG) && (self::$TWIG_OPTION_DEBUG = env("TWIG_OPTION_DEBUG", 0));
     is_null(self::$TWIG_OPTION_AUTO_RELOAD) && (self::$TWIG_OPTION_AUTO_RELOAD = env("TWIG_OPTION_AUTO_RELOAD", 1));
     is_null(self::$TWIG_OPTION_CHARSET) && (self::$TWIG_OPTION_CHARSET = env("TWIG_OPTION_CHARSET", "UTF-8"));
     if ($engine == self::ENGINE_AUTO) {
         $name_ext = substr($name, strrpos($name, '.'));
         switch ($name_ext) {
             case ".php":
                 $engine = self::ENGINE_SYMFONY;
                 break;
             case ".twig":
             default:
                 $engine = self::ENGINE_TWIG;
                 break;
         }
     }
     $content = "";
     is_null(self::$VIEWS_DIR) && (self::$VIEWS_DIR = resources_path("views"));
     switch ($engine) {
         case self::ENGINE_SYMFONY:
             $loader = new FilesystemLoader(self::$VIEWS_DIR . DIRECTORY_SEPARATOR . "%name%");
             $templating = new PhpEngine(new TemplateNameParser(), $loader);
             $content = $templating->render($name, $data);
             break;
         case self::ENGINE_TWIG:
             $loader = new \Twig_Loader_Filesystem(self::$VIEWS_DIR);
             $twig = new \Twig_Environment($loader, array('cache' => self::$CACHE_VIEWS_DIR ?: storage_path("cache" . DIRECTORY_SEPARATOR . "views"), 'auto_reload' => self::$TWIG_OPTION_AUTO_RELOAD, 'debug' => self::$TWIG_OPTION_DEBUG, 'charset' => self::$TWIG_OPTION_CHARSET));
             $content = $twig->render($name, $data);
             break;
     }
     return $content;
 }
 protected function registerViewPaths()
 {
     $view = $this->app->make('view');
     foreach ($this->fs->directories(resources_path('views')) as $dir) {
         $ns = Path::getDirectoryName($dir);
         $view->addNamespace($ns, $dir);
     }
 }
Пример #3
0
 public static function get($parameters, $dir = '', $default = null)
 {
     if (is_null(self::$dir)) {
         $dir = resources_path('lang') . DIRECTORY_SEPARATOR . $dir;
         self::$dir = is_dir($dir) ? $dir : resources_path('lang');
     }
     $value = parent::_get(self::$dir, $parameters);
     return !is_null($value) ? $value : parent::_value($default);
 }
Пример #4
0
 /**
  * @return string
  */
 public function randomAttribution()
 {
     if (!ini_get('auto_detect_line_endings')) {
         ini_set('auto_detect_line_endings', '1');
     }
     $famousPeople = Reader::createFromPath(resources_path('quotes/famous-people.txt'));
     $res = $famousPeople->fetchAssoc(['code', 'name']);
     $resToArray = iterator_to_array($res, false);
     return $resToArray[array_rand($resToArray, 1)]['name'];
 }