7
7
8
8
namespace Hubzero \Component ;
9
9
10
+ use Hubzero \Component \Router \DefaultRouter ;
10
11
use Hubzero \Component \Router \Legacy ;
11
12
use Hubzero \Container \Container ;
12
13
use Hubzero \Config \Registry ;
@@ -210,6 +211,7 @@ public function render($option, $params = array())
210
211
{
211
212
$ found = true ;
212
213
$ path = $ namespace ;
214
+ $ type = 'bootstrap ' ;
213
215
214
216
// Infer the appropriate language path and load from there
215
217
$ file = with (new \ReflectionClass ($ namespace ))->getFileName ();
@@ -222,6 +224,7 @@ public function render($option, $params = array())
222
224
else if (is_file ($ path ))
223
225
{
224
226
$ found = true ;
227
+ $ type = 'path ' ;
225
228
226
229
// Load local language files
227
230
$ lang ->load ($ option , PATH_COMPONENT , null , false , true );
@@ -230,6 +233,16 @@ public function render($option, $params = array())
230
233
{
231
234
$ found = true ;
232
235
$ path = $ react_path ;
236
+ $ ype = 'react ' ;
237
+
238
+ // Load local language files
239
+ $ lang ->load ($ option , PATH_COMPONENT , null , false , true );
240
+ }
241
+ else if (is_dir (PATH_COMPONENT ))
242
+ {
243
+ $ found = true ;
244
+ $ path = $ option ;
245
+ $ type = 'default ' ;
233
246
234
247
// Load local language files
235
248
$ lang ->load ($ option , PATH_COMPONENT , null , false , true );
@@ -249,7 +262,7 @@ public function render($option, $params = array())
249
262
$ contents = null ;
250
263
251
264
// Execute the component.
252
- $ contents = $ this ->execute ($ path );
265
+ $ contents = $ this ->execute ($ path, $ type );
253
266
254
267
// Revert the scope
255
268
$ this ->app ->forget ('scope ' );
@@ -264,19 +277,23 @@ public function render($option, $params = array())
264
277
* @param string $path The component path.
265
278
* @return string The component output
266
279
*/
267
- protected function execute ($ path )
280
+ protected function execute ($ path, $ type = ' path ' )
268
281
{
269
282
ob_start ();
270
283
271
- if (is_file ( $ path) )
284
+ if ($ type == ' path ' )
272
285
{
273
286
$ this ->executePath ($ path );
274
287
}
275
- else if (is_dir ( $ path ) )
288
+ else if ($ type == ' react ' )
276
289
{
277
290
$ this ->executeReactApp ($ path );
278
291
}
279
- else
292
+ else if ($ type == 'default ' )
293
+ {
294
+ $ this ->executeDefault ($ path );
295
+ }
296
+ else if ($ type == 'bootstrap ' )
280
297
{
281
298
$ this ->executeBootstrap ($ path );
282
299
}
@@ -298,6 +315,55 @@ protected function executePath($path)
298
315
require_once $ path ;
299
316
}
300
317
318
+ /**
319
+ * Start component without explicit entrypoint file
320
+ *
321
+ * @param string $namespace The namespace of the component to start
322
+ * @return void
323
+ */
324
+ private function executeDefault ($ option = '' )
325
+ {
326
+ $ option = (string ) $ option ;
327
+
328
+ if (substr ($ option , 0 , 4 ) == 'com_ ' )
329
+ {
330
+ $ component = substr ($ option , 4 );
331
+ }
332
+ else
333
+ {
334
+ $ component = $ option ;
335
+ }
336
+
337
+ if ( preg_match ("/^[a-zA-Z_ \x80- \xff][a-zA-Z0-9_ \x80- \xff]*$/ " , $ component ) !== 1 )
338
+ {
339
+ throw new \InvalidArgumentException (sprintf ('Invalid component name [%s] requested ' , htmlspecialchars ($ component , ENT_HTML5 )), 404 );
340
+ }
341
+
342
+ $ controller = \Request::getCmd ('controller ' , $ component );
343
+
344
+ if ( preg_match ("/^[a-zA-Z_ \x80- \xff][a-zA-Z0-9_ \x80- \xff]*$/ " , $ controller ) !== 1 )
345
+ {
346
+ throw new \InvalidArgumentException (sprintf ('Invalid controller name [%s] requested ' , htmlspecialchars ($ controller , ENT_HTML5 )), 404 );
347
+ }
348
+
349
+ $ path = PATH_COMPONENT ;
350
+
351
+ $ config = array ('base_path ' => PATH_COMPONENT );
352
+ $ namespace = 'Components \\' . ucfirst ($ component ) . '\Site\Controllers ' ;
353
+ $ class = ucfirst ($ controller );
354
+
355
+ if (file_exists ($ path . "/controllers/ {$ controller }.php " ))
356
+ {
357
+ require_once ($ path . "/controllers/ {$ controller }.php " );
358
+ }
359
+ else
360
+ {
361
+ eval ("namespace {$ namespace }; class {$ class } extends \\Hubzero \\Component \\DefaultSiteController \n{ \n} \n" );
362
+ }
363
+
364
+ (new ($ namespace .'\\' .$ class )($ config ))->execute ();
365
+ }
366
+
301
367
/**
302
368
* Execute the component from a new bootstrapped component
303
369
*
@@ -460,7 +526,17 @@ public function router($option, $client = null, $version = null)
460
526
461
527
if (!isset (self ::$ routers [$ key ]))
462
528
{
463
- self ::$ routers [$ key ] = new Legacy ($ compname );
529
+ $ path = $ this ->path ($ option );
530
+ $ name = substr ($ option , 4 );
531
+
532
+ if (!is_file ("{$ path }/ {$ name }.php " ) && !is_file ("{$ path }/controllers/ {$ name }.php " ))
533
+ {
534
+ self ::$ routers [$ key ] = new DefaultRouter ($ compname );
535
+ }
536
+ else
537
+ {
538
+ self ::$ routers [$ key ] = new Legacy ($ compname );
539
+ }
464
540
}
465
541
}
466
542
0 commit comments