-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathComponentStarter.php
53 lines (45 loc) · 1.48 KB
/
ComponentStarter.php
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
<?php
/**
* Copyright (c) 2018. Alexandr Kosarev, @kosarev.by
*/
/**
* Created by PhpStorm.
* User: Alexandr
* Date: 03.02.2018
* Time: 12:22
*/
namespace Joomplace\X;
use Joomla\CMS\Factory;
use Joomla\CMS\Session\Session;
abstract class ComponentStarter
{
/**
* @param string $dispatcher Component dispatcher class name
* @param string|null $defaultController Name of the default controller to run
* @param string|null $migrationsPath Path to migrations folder to run if any
*
* @since 1.0
*/
public static function startup(string $dispatcher, $defaultController = null, $migrationsPath = null){
Factory::getDocument()->setMetaData('api-token',Session::getFormToken());
$input = Factory::getApplication()->input;
$jsonInput = json_decode(file_get_contents('php://input'));
if($jsonInput){
foreach ($jsonInput as $k => $v){
$input->def($k,$v);
}
}
$task = $input->get('task');
if(strpos($task,'.')!==false){
$task = explode('.',$task);
$controller = array_shift($task);
$task = implode('.',$task);
$input->set('task',$task);
$input->def('controller',$controller);
}
if($migrationsPath){
$dispatcher::migrate($migrationsPath);
}
echo $dispatcher::getInstance($input->get('controller',$defaultController))->execute($input->get('task'));
}
}