/**
  * 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;
 }
Example #2
0
 public function testManipulatingFallback()
 {
     $bag = new ThemeBag($filesystem = new Filesystem(), array(__DIR__));
     $fallback = m::mock('Cartalyst\\Themes\\ThemeInterface');
     $fallback->shouldReceive('getSlug')->times(3)->andReturn('foo/bar');
     $bag->setFallback($fallback);
     $this->assertEquals($fallback, $bag['foo/bar']);
     $this->assertEquals($fallback, $bag->getFallback());
 }