Autodoc
  • Namespace
  • Class
  • Tree

Namespaces

  • BlueTihi
    • Context
  • Brickrouge
    • Element
      • Nodes
    • Renderer
    • Widget
  • ICanBoogie
    • ActiveRecord
    • AutoConfig
    • CLDR
    • Composer
    • Core
    • Event
    • Exception
    • HTTP
      • Dispatcher
      • Request
    • I18n
      • Translator
    • Mailer
    • Modules
      • Taxonomy
        • Support
      • Thumbnailer
        • Versions
    • Object
    • Operation
      • Dispatcher
    • Prototype
    • Routes
    • Routing
      • Dispatcher
    • Session
  • Icybee
    • ActiveRecord
      • Model
    • ConfigOperation
    • Document
    • EditBlock
    • Element
      • ActionbarContextual
      • ActionbarSearch
      • ActionbarToolbar
    • FormBlock
    • Installer
    • ManageBlock
    • Modules
      • Articles
      • Cache
        • Collection
        • ManageBlock
      • Comments
        • ManageBlock
      • Contents
        • ManageBlock
      • Dashboard
      • Editor
        • Collection
      • Files
        • File
        • ManageBlock
      • Forms
        • Form
        • ManageBlock
      • I18n
      • Images
        • ManageBlock
      • Members
      • Modules
        • ManageBlock
      • Nodes
        • ManageBlock
        • Module
      • Pages
        • BreadcrumbElement
        • LanguagesElement
        • ManageBlock
        • NavigationBranchElement
        • NavigationElement
        • Page
        • PageController
      • Registry
      • Search
      • Seo
      • Sites
        • ManageBlock
      • Taxonomy
        • Terms
          • ManageBlock
        • Vocabulary
          • ManageBlock
      • Users
        • ManageBlock
        • NonceLogin
        • Roles
      • Views
        • ActiveRecordProvider
        • Collection
        • View
    • Operation
      • ActiveRecord
      • Constructor
      • Module
      • Widget
    • Rendering
  • None
  • Patron
  • PHP

Classes

  • ActiveRecordProvider
  • CacheManager
  • Collection
  • Hooks
  • Module
  • Provider
  • TemplateResolver
  • View
  • ViewEditor
  • ViewEditorElement
  • ViewOptions
  1 <?php
  2 
  3 /*
  4  * This file is part of the Icybee package.
  5  *
  6  * (c) Olivier Laviale <olivier.laviale@gmail.com>
  7  *
  8  * For the full copyright and license information, please view the LICENSE
  9  * file that was distributed with this source code.
 10  */
 11 
 12 namespace Icybee\Modules\Views;
 13 
 14 /**
 15  * @property-read array $templates Possible templates.
 16  */
 17 class TemplateResolver extends \ICanBoogie\Object
 18 {
 19     /**
 20      * View identifier.
 21      *
 22      * @var string
 23      */
 24     protected $id;
 25 
 26     /**
 27      * Views type, one of "home", "list", "view"...
 28      *
 29      * @var string
 30      */
 31     protected $type;
 32 
 33     /**
 34      * Identifier of the module for which a view is created.
 35      *
 36      * @var string
 37      */
 38     protected $module_id;
 39 
 40     public function __construct($id, $type, $module_id)
 41     {
 42         $this->id = $id;
 43         $this->type = $type;
 44         $this->module_id = $module_id;
 45     }
 46 
 47     protected function lazy_get_templates()
 48     {
 49         global $core;
 50 
 51         $id = $this->id;
 52         $type = $this->type;
 53         $templates = array();
 54 
 55         $templates_base = array();
 56 
 57         $parts = explode('/', $id);
 58         $module_id = array_shift($parts);
 59         $type = array_pop($parts);
 60 
 61         while (count($parts))
 62         {
 63             $templates_base[] = implode('--', $parts) . '--' . $type;
 64 
 65             array_pop($parts);
 66         }
 67 
 68         $templates_base[] = $type;
 69 
 70         $templates_base = array_unique($templates_base);
 71 
 72         $descriptors = $core->modules->descriptors;
 73         $descriptor = $descriptors[$this->module_id];
 74 
 75         while ($descriptor)
 76         {
 77             foreach ($templates_base as $template)
 78             {
 79                 $pathname = \ICanBoogie\DOCUMENT_ROOT . 'protected/all/templates/views/' . \ICanBoogie\normalize($descriptor[Module::T_ID]) . '--' . $template;
 80                 $templates[] = $pathname;
 81 
 82                 $pathname = $descriptor[Module::T_PATH] . 'views/' . $template;
 83                 $templates[] = $pathname;
 84             }
 85 
 86             $descriptor = $descriptor[Module::T_EXTENDS] ? $descriptors[$descriptor[Module::T_EXTENDS]] : null;
 87         }
 88 
 89         foreach ($templates_base as $template)
 90         {
 91             $pathname = \ICanBoogie\DOCUMENT_ROOT . 'protected/all/templates/views/' . $template;
 92             $templates[] = $pathname;
 93         }
 94 
 95         return $templates;
 96     }
 97 
 98     public function __invoke()
 99     {
100         $templates = $this->templates;
101 
102         $handled = array('php', 'html');
103 
104         foreach ($templates as $template)
105         {
106             foreach ($handled as $extension)
107             {
108                 $pathname = $template . '.' . $extension;
109 
110 //              \ICanBoogie\log("tryed: $pathname");
111 
112                 if (file_exists($pathname))
113                 {
114                     return $pathname;
115                 }
116             }
117         }
118     }
119 }
Autodoc API documentation generated by ApiGen 2.8.0