Blame view

framework/core/manifest/TemplateLoader.php 1.9 KB
0084d336   Administrator   Importers CRUD
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
  <?php
  /**
   * Handles finding templates from a stack of template manifest objects.
   *
   * @package framework
   * @subpackage manifest
   */
  class SS_TemplateLoader {
  
  	/**
  	 * @var SS_TemplateLoader
  	 */
  	private static $instance;
  
  	/**
  	 * @var SS_TemplateManifest[]
  	 */
  	protected $manifests = array();
  
  	/**
  	 * @return SS_TemplateLoader
  	 */
  	public static function instance() {
  		return self::$instance ? self::$instance : self::$instance = new self();
  	}
  
  	/**
  	 * Returns the currently active template manifest instance.
  	 *
  	 * @return SS_TemplateManifest
  	 */
  	public function getManifest() {
  		return $this->manifests[count($this->manifests) - 1];
  	}
  
  	/**
  	 * @param SS_TemplateManifest $manifest
  	 */
  	public function pushManifest(SS_TemplateManifest $manifest) {
  		$this->manifests[] = $manifest;
  	}
  
  	/**
  	 * @return SS_TemplateManifest
  	 */
  	public function popManifest() {
  		return array_pop($this->manifests);
  	}
  
  	/**
  	 * Attempts to find possible candidate templates from a set of template
  	 * names from modules, current theme directory and finally the application
  	 * folder.
  	 *
  	 * The template names can be passed in as plain strings, or be in the
  	 * format "type/name", where type is the type of template to search for
  	 * (e.g. Includes, Layout).
  	 *
  	 * @param  string|array $templates
  	 * @param  string $theme
  	 *
  	 * @return array
  	 */
  	public function findTemplates($templates, $theme = null) {
  		$result = array();
  		$project = project();
  		
  		foreach ((array) $templates as $template) {
  			$found = false;
  			
  			if (strpos($template, '/')) {
  				list($type, $template) = explode('/', $template, 2);
  			} else {
  				$type = null;
  			}
  			
  			if ($found = $this->getManifest()->getCandidateTemplate($template, $theme)) {
  					if ($type && isset($found[$type])) {
  						$found = array(
  							'main' => $found[$type]
  						);
  					}
  					$result = array_merge($found, $result);
  				}
  			}
  			
  		return $result;
  	}
  
  }