1 | <?php |
||
30 | class TemplatedShortcode extends Shortcode { |
||
31 | |||
32 | /** |
||
33 | * Template loader that allows a theme to override the shortcode's views. |
||
34 | * |
||
35 | * @var Gamajo_Template_Loader|null |
||
36 | */ |
||
37 | protected $template_loader; |
||
38 | |||
39 | /** |
||
40 | * Instantiate Basic Shortcode. |
||
41 | * |
||
42 | * @since 0.2.6 |
||
43 | * |
||
44 | * @param string $shortcode_tag Tag that identifies the |
||
45 | * shortcode. |
||
46 | * @param Config $config Configuration settings. |
||
47 | * @param ShortcodeAttsParser $atts_parser Attributes parser and |
||
48 | * validator. |
||
49 | * @param DependencyManager|null $dependencies Optional. Dependencies of |
||
50 | * the shortcode. |
||
51 | * @throws RuntimeException If the config could not be processed. |
||
52 | */ |
||
53 | public function __construct( |
||
69 | |||
70 | /** |
||
71 | * Initialize the template loader class. |
||
72 | * |
||
73 | * @since 0.2.6 |
||
74 | * |
||
75 | * @return Gamajo_Template_Loader |
||
76 | */ |
||
77 | public function init_template_loader() { |
||
97 | |||
98 | /** |
||
99 | * Get the default template loader class that is used when none is defined |
||
100 | * in the config file. |
||
101 | * |
||
102 | * @since 0.2.6 |
||
103 | * |
||
104 | * @return string The default template laoder class to use. |
||
105 | */ |
||
106 | protected function get_default_template_loader_class() { |
||
109 | |||
110 | /** |
||
111 | * Get the default filter prefix that is used when none is defined in the |
||
112 | * config file. |
||
113 | * |
||
114 | * Defaults to 'bn_shortcode.'. |
||
115 | * |
||
116 | * @since 0.2.6 |
||
117 | * |
||
118 | * @return string Default filter prefix to use. |
||
119 | */ |
||
120 | protected function get_default_filter_prefix() { |
||
123 | |||
124 | /** |
||
125 | * Get the default template directory that is used when none is defined in |
||
126 | * the config file. |
||
127 | * |
||
128 | * Defaults to 'bn_shortcode'. |
||
129 | * |
||
130 | * @since 0.2.6 |
||
131 | * |
||
132 | * @return string Default template directory to use. |
||
133 | */ |
||
134 | protected function get_default_template_directory() { |
||
137 | |||
138 | /** |
||
139 | * Get the directory for a given view file. |
||
140 | * |
||
141 | * @since 0.2.6 |
||
142 | * |
||
143 | * @param string $view View file to extract the directory from. |
||
144 | * @return string Directory that contains the given view. |
||
145 | */ |
||
146 | protected function get_directory_from_view( $view ) { |
||
149 | |||
150 | /** |
||
151 | * Get the default view directory that is used when none is defined in the |
||
152 | * config file. |
||
153 | * |
||
154 | * Defaults to 'views/shortcodes'. Will probably need to be changed into an |
||
155 | * absolute path if the shortcodes package is pulled in through Composer. |
||
156 | * |
||
157 | * @since 0.2.6 |
||
158 | * |
||
159 | * @return string Default view directory to use. |
||
160 | */ |
||
161 | protected function get_default_view_directory() { |
||
164 | |||
165 | /** |
||
166 | * Get the rendered HTML for a given view. |
||
167 | * |
||
168 | * @since 0.2.6 |
||
169 | * |
||
170 | * @param string $view The view to render. |
||
171 | * @param mixed $context The context to pass through to the view. |
||
172 | * @param array $atts The shortcode attribute values to pass |
||
173 | * through to the view. |
||
174 | * @param string|null $content Optional. The inner content of the shortcode. |
||
175 | * @return string HTML rendering of the view. |
||
176 | */ |
||
177 | protected function render_view( $view, $context, $atts, $content = null ) { |
||
190 | |||
191 | /** |
||
192 | * Get the slug for a given view. |
||
193 | * |
||
194 | * @since 0.2.6 |
||
195 | * |
||
196 | * @param string $view The view to get the slug for. |
||
197 | * @return string Slug that can be passed into `get_template_part()`. |
||
198 | */ |
||
199 | protected function get_view_slug( $view ) { |
||
202 | |||
203 | /** |
||
204 | * Strip the extension for a given view filename if it includes an |
||
205 | * extension. |
||
206 | * |
||
207 | * @since 0.2.6 |
||
208 | * |
||
209 | * @param string $view The view that maybe needs its extension stripped. |
||
210 | * @return string Extension-less view. |
||
211 | */ |
||
212 | protected function maybe_strip_extension( $view ) { |
||
215 | } |
||
216 |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: