1 | <?php |
||
33 | class TemplatedShortcode extends Shortcode { |
||
34 | |||
35 | /** |
||
36 | * Template loader that allows a theme to override the shortcode's views. |
||
37 | * |
||
38 | * @var Gamajo_Template_Loader|null |
||
39 | */ |
||
40 | protected $template_loader; |
||
41 | |||
42 | /** |
||
43 | * Instantiate Basic Shortcode. |
||
44 | * |
||
45 | * @since 0.2.6 |
||
46 | * |
||
47 | * @param string $shortcode_tag Tag that identifies the |
||
48 | * shortcode. |
||
49 | * @param ConfigInterface $config Configuration settings. |
||
50 | * @param ShortcodeAttsParser $atts_parser Attributes parser and |
||
51 | * validator. |
||
52 | * @param DependencyManager|null $dependencies Optional. Dependencies of |
||
53 | * the shortcode. |
||
54 | * @throws RuntimeException If the config could not be processed. |
||
55 | */ |
||
56 | public function __construct( |
||
72 | |||
73 | /** |
||
74 | * Initialize the template loader class. |
||
75 | * |
||
76 | * @since 0.2.6 |
||
77 | * |
||
78 | * @return Gamajo_Template_Loader |
||
|
|||
79 | */ |
||
80 | public function init_template_loader() { |
||
81 | if ( ! $this->hasConfigKey( 'template' ) ) { |
||
82 | return null; |
||
83 | } |
||
84 | $loader_class = $this->hasConfigKey( 'template', 'custom_loader' ) |
||
85 | ? $this->getConfigKey( 'template', 'custom_loader' ) |
||
86 | : $this->get_default_template_loader_class(); |
||
87 | $filter_prefix = $this->hasConfigKey( 'template', 'filter_prefix' ) |
||
88 | ? $this->getConfigKey( 'template', 'filter_prefix' ) |
||
89 | : $this->get_default_filter_prefix(); |
||
90 | $template_dir = $this->hasConfigKey( 'template', 'template_directory' ) |
||
91 | ? $this->getConfigKey( 'template', 'template_directory' ) |
||
92 | : $this->get_default_template_directory(); |
||
93 | $view_dir = $this->hasConfigKey( 'view' ) |
||
94 | ? $this->get_directory_from_view( $this->getConfigKey( 'view' ) ) |
||
95 | : $this->get_default_view_directory(); |
||
96 | |||
97 | return new $loader_class( |
||
98 | $filter_prefix, |
||
99 | $template_dir, |
||
100 | $view_dir |
||
101 | ); |
||
102 | } |
||
103 | |||
104 | /** |
||
105 | * Get the default template loader class that is used when none is defined |
||
106 | * in the config file. |
||
107 | * |
||
108 | * @since 0.2.6 |
||
109 | * |
||
110 | * @return string The default template laoder class to use. |
||
111 | */ |
||
112 | protected function get_default_template_loader_class() { |
||
115 | |||
116 | /** |
||
117 | * Get the default filter prefix that is used when none is defined in the |
||
118 | * config file. |
||
119 | * |
||
120 | * Defaults to 'bn_shortcode.'. |
||
121 | * |
||
122 | * @since 0.2.6 |
||
123 | * |
||
124 | * @return string Default filter prefix to use. |
||
125 | */ |
||
126 | protected function get_default_filter_prefix() { |
||
129 | |||
130 | /** |
||
131 | * Get the default template directory that is used when none is defined in |
||
132 | * the config file. |
||
133 | * |
||
134 | * Defaults to 'bn_shortcode'. |
||
135 | * |
||
136 | * @since 0.2.6 |
||
137 | * |
||
138 | * @return string Default template directory to use. |
||
139 | */ |
||
140 | protected function get_default_template_directory() { |
||
143 | |||
144 | /** |
||
145 | * Get the directory for a given view file. |
||
146 | * |
||
147 | * @since 0.2.6 |
||
148 | * |
||
149 | * @param string $view View file to extract the directory from. |
||
150 | * @return string Directory that contains the given view. |
||
151 | */ |
||
152 | protected function get_directory_from_view( $view ) { |
||
155 | |||
156 | /** |
||
157 | * Get the default view directory that is used when none is defined in the |
||
158 | * config file. |
||
159 | * |
||
160 | * Defaults to 'views/shortcodes'. Will probably need to be changed into an |
||
161 | * absolute path if the shortcodes package is pulled in through Composer. |
||
162 | * |
||
163 | * @since 0.2.6 |
||
164 | * |
||
165 | * @return string Default view directory to use. |
||
166 | */ |
||
167 | protected function get_default_view_directory() { |
||
170 | |||
171 | /** |
||
172 | * Get the rendered HTML for a given view. |
||
173 | * |
||
174 | * @since 0.2.6 |
||
175 | * |
||
176 | * @param string $view The view to render. |
||
177 | * @return string HTML rendering of the view. |
||
178 | */ |
||
179 | protected function render_view( $view ) { |
||
188 | |||
189 | /** |
||
190 | * Get the slug for a given view. |
||
191 | * |
||
192 | * @since 0.2.6 |
||
193 | * |
||
194 | * @param string $view The view to get the slug for. |
||
195 | * @return string Slug that can be passed into `get_template_part()`. |
||
196 | */ |
||
197 | protected function get_view_slug( $view ) { |
||
200 | |||
201 | /** |
||
202 | * Strip the extension for a given view filename if it includes an |
||
203 | * extension. |
||
204 | * |
||
205 | * @since 0.2.6 |
||
206 | * |
||
207 | * @param string $view The view that maybe needs its extension stripped. |
||
208 | * @return string Extension-less view. |
||
209 | */ |
||
210 | protected function maybe_strip_extension( $view ) { |
||
213 | } |
||
214 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.