Skip to content

Commit

Permalink
API support is implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
rsanjoseo committed Jul 9, 2020
1 parent 601ec3b commit d761ad6
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 2 deletions.
3 changes: 2 additions & 1 deletion composer.json
Expand Up @@ -38,7 +38,8 @@
},
"autoload": {
"psr-4": {
"Alxarafe\\": "src/Alxarafe"
"Alxarafe\\": "src/Alxarafe",
"Modules\\": "src/Modules"
},
"files": [
"src/Alxarafe/Core/Functions.php"
Expand Down
38 changes: 37 additions & 1 deletion src/Alxarafe/Core/BootStrap.php
Expand Up @@ -250,7 +250,17 @@ public function init(): void
if (isset($this->database) && null !== $this->database->getDbEngine()) {
ModuleManager::getInstance()::initializeModules();
}
$this->run();
$task = $this->request->query->get('task');
switch ($task) {
case 'cron':
break;
case'api':
$this->api();
break;
default:
$this->run();
break;
}
}

/**
Expand Down Expand Up @@ -318,4 +328,30 @@ public function run(): void
}
$this->response->send();
}

/**
* Call to API module, if exists.
*
* @return bool
*/
public function api()
{
$apiCodePath = $this->basePath . '/src/Modules/xapi/Core/AppApi.php';
if (!file_exists($apiCodePath)) {
die(json_encode(['error' => 'Please, install xapi module']));
}
include $apiCodePath;
$api = new \Modules\xapi\Core\AppApi([
'basePath' => $this->basePath,
'router' => $this->router,
'database' => $this->database,
'configData' => $this->configData,
'request' => $this->request,
'response' => $this->response,
'log' => $this->log,
'regionalInfo' => $this->regionalInfo,
]);
$api->run();
die($api->render());
}
}
24 changes: 24 additions & 0 deletions src/Alxarafe/Core/Functions.php
Expand Up @@ -65,3 +65,27 @@ function baseUrl(string $url = ''): string
return empty($url) ? $baseUrl : $baseUrl . '/' . trim($url, '/');
}
}

if (!function_exists('randomString')) {
/**
* Create a randomString
*
* @param int $length
*
* @return string
*/
function randomString(int $length)
{
$random = '';
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
while (strlen($random) < $length) {
try {
$pos = random_int(0, strlen($characters));
} catch (Exception $e) {
$pos = mt_rand(0, strlen($characters));
}
$random .= $characters[$pos];
}
return str_shuffle($random);
}
}
2 changes: 2 additions & 0 deletions src/Alxarafe/Core/Languages/en.yaml
Expand Up @@ -43,6 +43,7 @@ col-decimals: Decimals
col-description: Description
col-email: Email
col-enabled: Enabled
col-from-date: From
col-icon: Icon
col-id: Id.
col-id_page: 'Page Id.'
Expand All @@ -64,6 +65,7 @@ col-plugin: Plugin
col-register_date: 'Registered at'
col-tablename: 'Table name'
col-title: Title
col-to-date: To
col-unicode: Unicode
col-updated_date: 'Updated at'
col-username: 'User name'
Expand Down
7 changes: 7 additions & 0 deletions xapi.php
@@ -0,0 +1,7 @@
<?php
/*
* This file is part of XFS.Cloud
* Copyright (C) 2019-2020 X-Net Digital <soporte@x-netdigital.com>
*/
$_GET['task']='api';
include 'index.php';

0 comments on commit d761ad6

Please sign in to comment.