/**
  * Create a new file view loader instance.
  *
  * @param \DigitLab\AdaptiveView\Browser\Browser $browser
  * @param \Illuminate\Filesystem\Filesystem      $files
  * @param array                                  $paths
  * @param array                                  $extensions
  * @param array                                  $mobileExtensions
  */
 public function __construct(Browser $browser, Filesystem $files, array $paths, array $extensions = null, array $mobileExtensions = null)
 {
     parent::__construct($files, $paths, $extensions);
     $this->browser = $browser;
     if (isset($mobileExtensions)) {
         $this->mobileExtensions = $mobileExtensions;
     }
 }
 /**
  * Register Environment
  *
  * @return void
  */
 public function registerEnvironment()
 {
     $this->app['view'] = $this->app->share(function ($app) {
         $resolver = $app['view.engine.resolver'];
         $resource = 'view.';
         $engine = $app['config']->get($resource . 'engine');
         if (empty($engine)) {
             $resource = 'PhpTalView::';
         }
         $finder = new FileViewFinder($app['files'], array());
         $finder->addLocation($app['config']->get($resource . 'templateRepository'));
         $finder->addExtension($app['config']->get($resource . 'extension'));
         $env = new Environment($resolver, $finder, $app['events']);
         $env->addExtension($app['config']->get($resource . 'extension'), 'phptal');
         $env->setContainer($app);
         $env->share('app', $app);
         return $env;
     });
 }
 /**
  * Get the fully qualified location of the view.
  *
  * @param  string  $name
  * @return string
  */
 public function find($name)
 {
     //		Log::info('View Hook!! ' . $name);
     if (Agent::isMobile()) {
         try {
             return parent::find($name . '@phone');
         } catch (Exception $e) {
             Log::debug(__METHOD__ . ": not find {$name}@phone");
         }
     }
     return parent::find($name);
 }
 /**
  * Get the fullly qualified location of the view.
  *
  * @param  string  $name
  * @return string
  * @throws \InvalidArgumentException
  */
 public function find($name)
 {
     $name = str_replace('.', '/', $name);
     // If the theme bag instance has not been set, we will just let
     // the default handler take control of loading the views.
     if (!isset($this->themeBag)) {
         return parent::find($name);
     }
     // Parse the name
     $resolver = new NamespacedItemResolver();
     list($section, $view) = $resolver->parseKey($name);
     try {
         // If we have a package listed, let's just check firstly
         // if it's actually referring to a hard-coded namespace.
         // Namespaces override packages in Themes, as they do in views.
         if (isset($section)) {
             if (isset($this->hints[$section])) {
                 $sectionType = 'namespaces';
                 $paths = $this->themeBag->getCascadedNamespaceViewPaths($section);
             } else {
                 $sectionType = 'packages';
                 $paths = $this->themeBag->getCascadedPackageViewPaths($section);
             }
             $view = $this->findInPaths($view, $paths);
         } else {
             $paths = $this->themeBag->getCascadedViewPaths();
             $view = $this->findInPaths($view, $paths);
         }
     } catch (InvalidArgumentException $e) {
         // Let's fallback to the normal view system.
         try {
             return parent::find($name);
         } catch (InvalidArgumentException $e) {
             // Grab the relevent themes from the theme bag
             $active = $this->themeBag->getActive();
             $fallback = $this->themeBag->getFallback();
             // If we had a section, throw an Exception that's more aimed at
             // debugging why the package does not exist.
             if (isset($section)) {
                 $message = sprintf('Theme [%s] view [%s] could not be found in theme [%s]', $sectionType, $name, $active->getSlug());
             } else {
                 $message = sprintf('Theme view [%s] could not be found in theme [%s]', $name, $active->getSlug());
             }
             $message .= $active->getParentSlug() ? ' or any of it\'s parent themes' : '';
             $message .= ($fallback and $fallback != $active) ? " or the fallback theme [{$fallback->getSlug()}]." : '.';
             $message .= ' The standard view finder has also failed to find the view.';
             throw new InvalidArgumentException($message);
         }
     }
     return $view;
 }
 private function getApplication(array $paths = array(), array $hints = array())
 {
     $app = new Application();
     $app['env'] = 'testing';
     $app->instance('path', __DIR__ . '/../fixtures/Console/');
     // Storage path
     $app['path.storage'] = __DIR__;
     // Finder
     $finder = new FileViewFinder(new Filesystem(), $paths);
     if (count($hints) > 0) {
         foreach ($hints as $namespace => $namespace_paths) {
             $finder->addNamespace($namespace, $namespace_paths);
             $paths = array_merge($paths, $namespace_paths);
         }
     }
     // Total number of files across all paths
     $file_finder = new Finder();
     $file_finder->files()->in($paths)->name('*.twig');
     // View
     $view = m::mock('Illuminate\\View\\Environment');
     $view->shouldReceive('addExtension');
     $view->shouldReceive('getFinder')->andReturn($finder);
     $engine = m::mock('Illuminate\\View\\View');
     $engine->shouldReceive('render');
     $view->shouldReceive('make')->andReturn($engine);
     $app['view'] = $view;
     // Config
     $config = m::mock('Illuminate\\Container\\Container');
     $config->shouldReceive('get')->andReturnUsing(function ($x) {
         $args = func_get_args();
         if ($args[0] == 'twigbridge::extension') {
             return 'twig';
         }
         return array_pop($args);
     });
     $app['config'] = $config;
     return $app;
 }
 public function __construct(FileViewFinder $finder, $extension = 'twig')
 {
     $this->finder = $finder;
     $this->files = $finder->getFilesystem();
     $this->extension = $extension;
 }
Esempio n. 7
0
 public function __construct(Filesystem $files, array $paths, array $extensions = null, $themeEngine)
 {
     $this->themeEngine = $themeEngine;
     parent::__construct($files, $paths, $extensions);
 }
Esempio n. 8
0
 public function configView()
 {
     $engineResolver = new EngineResolver();
     $engineResolver->register('php', function () {
         return new PhpEngine();
     });
     $this->app->singleton('blade.compiler', function ($app) {
         $cachePath = $this->basePath . "/storage/framework/views";
         return new BladeCompiler(new Filesystem(), $cachePath);
     });
     $engineResolver->register('blade', function () {
         return new CompilerEngine($this->app['blade.compiler']);
     });
     $fileViewFinder = new FileViewFinder(new Filesystem(), [], null);
     $this->viewFactory = new Factory($engineResolver, $fileViewFinder, new Dispatcher());
     $fileViewFinder->addLocation($this->basePath . "/resources/views");
 }
Esempio n. 9
0
 public static function blade(array $data, $debug = true)
 {
     $resolver = new EngineResolver();
     $files = new Filesystem();
     $compiler = new BladeCompiler($files, static::$cacheDirectory);
     $engine = new CompilerEngine($compiler);
     $resolver->register('blade', function () use($engine) {
         return $engine;
     });
     /** @var Restler $restler */
     $restler = Scope::get('Restler');
     //Lets expose shortcuts for our classes
     spl_autoload_register(function ($className) use($restler) {
         if (isset($restler->apiMethodInfo->metadata['scope'][$className])) {
             return class_alias($restler->apiMethodInfo->metadata['scope'][$className], $className);
         }
         if (isset(Scope::$classAliases[$className])) {
             return class_alias(Scope::$classAliases[$className], $className);
         }
         return false;
     }, true, true);
     $viewFinder = new FileViewFinder($files, array(static::$viewPath));
     $factory = new Factory($resolver, $viewFinder, new Dispatcher());
     $path = $viewFinder->find(self::$view);
     $view = new View($factory, $engine, self::$view, $path, $data);
     $factory->callCreator($view);
     return $view->render();
 }
 /**
  * Creates a new FileViewFinder, copying the current contents
  *
  * @param FileViewFinder $finder
  * @param array          $paths
  *
  * @return FileViewFinder
  */
 protected function createViewFinder(FileViewFinder $finder, array $paths = [])
 {
     $new = new FileViewFinder(app('files'), $paths, $finder->getExtensions());
     foreach ($finder->getHints() as $namespace => $hints) {
         $new->addNamespace($namespace, $hints);
     }
     return $new;
 }
Esempio n. 11
0
 /**
  * Find the given view in the list of paths.
  *
  * @param  string  $name
  * @param  array   $paths
  * @return string
  *
  * @throws \InvalidArgumentException
  */
 protected function findInPaths($name, $paths)
 {
     try {
         return parent::findInPaths($name, $paths);
     } catch (InvalidArgumentException $e) {
         $name = $this->deviceView ? "{$this->deviceView}.{$name}" : $name;
         throw new InvalidArgumentException("View [{$name}] not found.");
     }
 }
Esempio n. 12
0
 public function __construct(ThemeConfigContract $themeConfig, Filesystem $files, array $paths, array $extensions = null)
 {
     parent::__construct($files, $paths, $extensions);
     $this->themeConfig = $themeConfig;
 }
Esempio n. 13
0
 /**
  * Copy a FileViewFinder to a FallbackFileViewFinder
  *
  * @param \Illuminate\View\FileViewFinder $otherFinder
  * @return static
  **/
 public static function fromOther(FileViewFinder $otherFinder)
 {
     $copy = new static($otherFinder->getFilesystem(), $otherFinder->getPaths(), $otherFinder->getExtensions());
     if ($otherFinder instanceof FallbackFileViewFinder) {
         $copy->setFallbackDir($otherFinder->getFallbackDir());
     }
     return $copy;
 }