Skip to content

Commit 9aba571

Browse files
committed
!548 - Changed system to basepackage for apis category type. Fix location for apis that will be in apps directory. Location will be either basepackages or apptype.
1 parent 4243013 commit 9aba571

File tree

8 files changed

+63
-34
lines changed

8 files changed

+63
-34
lines changed

system/Base/Installer/Packages/Setup/Register/Basepackages/ApiClientServices/Apis/Repos.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function register($db, $ff)
2525
'in_use' => 1,
2626
'used_by' => json_encode(['modules']),
2727
'setup' => 4,
28-
'location' => 'system'
28+
'location' => 'basepackages'
2929
];
3030

3131
$modulesRepo =
@@ -47,7 +47,7 @@ public function register($db, $ff)
4747
'in_use' => 1,
4848
'used_by' => json_encode(['modules']),
4949
'setup' => 4,
50-
'location' => 'system'
50+
'location' => 'basepackages'
5151
];
5252

5353
$githubModulesRepo =
@@ -69,7 +69,7 @@ public function register($db, $ff)
6969
'in_use' => 1,
7070
'used_by' => json_encode(['modules']),
7171
'setup' => 4,
72-
'location' => 'system'
72+
'location' => 'basepackages'
7373
];
7474

7575
if ($db) {

system/Base/Installer/Packages/Setup/Register/Modules/Packages/Basepackages/ApiClientServices/Apis/Repos/Gitea/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description" : "Package for connecting to Repository Gitea using API",
55
"module_type" : "packages",
66
"app_type" : "core",
7-
"category" : "basepackages_apis",
7+
"category" : "basepackagesApis",
88
"version" : "0.0.0",
99
"repo" : "https://.../",
1010
"class" : "System\\Base\\Providers\\BasepackagesServiceProvider\\Packages\\ApiClientServices\\Apis\\Repos\\Gitea\\ApisReposGitea",

system/Base/Installer/Packages/Setup/Register/Modules/Packages/Basepackages/ApiClientServices/Apis/Repos/Github/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description" : "Package for connecting to Repository Github using API",
55
"module_type" : "packages",
66
"app_type" : "core",
7-
"category" : "basepackages_apis",
7+
"category" : "basepackagesApis",
88
"version" : "0.0.0",
99
"repo" : "https://.../",
1010
"class" : "System\\Base\\Providers\\BasepackagesServiceProvider\\Packages\\ApiClientServices\\Apis\\Repos\\Github\\ApisReposGithub",

system/Base/Providers/BasepackagesServiceProvider/Packages/ApiClientServices/ApiClientServices.php

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ protected function registerApiCategories()
7474
{
7575
$this->apiCategories = [];
7676

77-
$basepackagesApis = $this->modules->packages->getPackagesForCategory('basepackages_apis');
78-
$apis = $this->modules->packages->getPackagesForCategory('apis');
77+
$basepackagesApis = $this->modules->packages->getPackagesForCategory('basepackagesApis');
78+
$apis = $this->modules->packages->getPackagesForCategory('appsApis');
7979

8080
$apis = array_merge($basepackagesApis, $apis);
8181

@@ -107,33 +107,39 @@ protected function registerApiLocations()
107107
{
108108
$this->apiLocations =
109109
[
110-
'system' =>
110+
'basepackages' =>
111111
[
112-
'id' => 'system',
113-
'name' => 'System'
112+
'id' => 'basepackages',
113+
'name' => 'Base Packages'
114114
],
115-
'apps' =>
116-
[
117-
'id' => 'apps',
118-
'name' => 'Apps'
119-
]
120115
];
116+
117+
$appTypes = $this->apps->types->types;
118+
119+
foreach ($appTypes as $type) {
120+
$this->apiLocations[$type['app_type']]['id'] = $type['app_type'];
121+
$this->apiLocations[$type['app_type']]['name'] = $type['name'];
122+
}
121123
}
122124

123125
protected function switchApiModel($api = null)
124126
{
125127
if ($api) {
126-
if ($api['location'] === 'system') {
127-
$modelClass = 'System\\Base\\Providers\\BasepackagesServiceProvider\\Packages\\Model\\ApiClientServices\\Apis\\' . ucfirst($api['category']) . '\\';
128+
$api['location'] = ucfirst($api['location']);
129+
$api['category'] = ucfirst($api['category']);
130+
$api['provider'] = ucfirst($api['provider']);
131+
132+
if ($api['location'] === 'Basepackages') {
133+
$modelClass = 'System\\Base\\Providers\\BasepackagesServiceProvider\\Packages\\Model\\ApiClientServices\\Apis\\' . $api['category'] . '\\';
128134

129-
$this->setModelToUse($modelClass . 'BasepackagesApiClientServicesApis' . ucfirst($api['category']) . ucfirst($api['provider']));
130-
} else if ($api['location'] === 'apps') {
131-
$modelClass = 'Apps\\Core\\Packages\\System\\ApiClientServices\\Apis\\' . ucfirst($api['category']) . '\\' . ucfirst($api['provider']) . '\\';
135+
$this->setModelToUse($modelClass . 'BasepackagesApiClientServicesApis' . $api['category'] . $api['provider']);
136+
} else {
137+
$modelClass = 'Apps\\' . $api['location'] . '\\Packages\\System\\ApiClientServices\\Apis\\' . $api['category'] . '\\' . $api['provider'] . '\\';
132138

133-
$this->setModelToUse($modelClass . 'Model\\SystemApiApis' . ucfirst($api['category']) . ucfirst($api['provider']));
139+
$this->setModelToUse($modelClass . 'Model\\SystemApiApis' . $api['category'] . $api['provider']);
134140
}
135141

136-
$this->packageName = 'apiApis' . ucfirst($api['category']) . ucfirst($api['provider']);
142+
$this->packageName = 'apiApis' . $api['category'] . $api['provider'];
137143
} else {
138144
$this->setModelToUse($modelToUse = BasepackagesApiClientServices::class);
139145

@@ -368,8 +374,8 @@ public function getApiClass($category, $provider, $basepackages = true)
368374
{
369375
//Class of API defined in the package defined the location of the API and its category and provider
370376
//Example: WhateverLocation\\Apis\\{Category}\\{Provider}\\API_CLASS
371-
$basepackagesApis = $this->modules->packages->getPackagesForCategory('basepackages_apis');
372-
$apis = $this->modules->packages->getPackagesForCategory('apis');
377+
$basepackagesApis = $this->modules->packages->getPackagesForCategory('basepackagesApis');
378+
$apis = $this->modules->packages->getPackagesForCategory('appsApis');
373379

374380
$apis = array_merge($basepackagesApis, $apis);
375381

system/Base/Providers/BasepackagesServiceProvider/Packages/ApiClientServices/Apis.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,32 @@ class Apis extends BasePackage
2727
'verify' => false
2828
];
2929

30-
public function init($apiConfig = null, $api = null, $httpOptions = null)
30+
public function init($apiConfig = null, $apiClientServices = null, $httpOptions = null)
3131
{
3232
if (isset($apiConfig['checkOnly']) && $apiConfig['checkOnly'] === true) {//used for checking via ServicesComponent if the API exists
3333
return $this;
3434
}
3535

36+
$apiConfig['location'] = ucfirst($apiConfig['location']);
3637
$apiConfig['category'] = ucfirst($apiConfig['category']);
3738
$apiConfig['provider'] = ucfirst($apiConfig['provider']);
3839

3940
$this->apiConfig = $apiConfig;
4041

42+
$this->apiClientServices = $apiClientServices;
43+
4144
$this->setConfiguration();
4245

4346
if ($httpOptions) {
4447
$this->httpOptions = array_merge($this->httpOptions, $httpOptions);
4548
}
4649

47-
$this->api = $api;
48-
49-
if ($this->apiConfig['location'] === 'system') {
50+
if ($this->apiConfig['location'] === 'Basepackages') {
5051
$this->serviceClass =
5152
"System\\Base\\Providers\\BasepackagesServiceProvider\\Packages\\ApiClientServices\\Apis\\{$this->apiConfig['category']}\\{$this->apiConfig['provider']}\\Api\\";
52-
} else if ($this->apiConfig['location'] === 'apps') {
53+
} else {
5354
$this->serviceClass =
54-
"Apps\\Dash\\Packages\\System\\ApiClientServices\\Apis\\{$this->apiConfig['category']}\\{$this->apiConfig['provider']}\\Api\\";
55+
"Apps\\{$this->apiConfig['location']}\\Packages\\System\\ApiClientServices\\Apis\\{$this->apiConfig['category']}\\{$this->apiConfig['provider']}\\Api\\";
5556
}
5657

5758
return $this;
@@ -80,15 +81,19 @@ protected function initRemoteWebContent($method, $apiConfig)
8081

8182
protected function setConfiguration()
8283
{
83-
$configurationClass = "System\\Base\\Providers\\BasepackagesServiceProvider\\Packages\\ApiClientServices\\Apis\\Repos\\{$this->apiConfig['provider']}\\Configuration";
84+
if ($this->apiConfig['location'] === 'Basepackages') {
85+
$configurationClass = "System\\Base\\Providers\\BasepackagesServiceProvider\\Packages\\ApiClientServices\\Apis\\{$this->apiConfig['category']}\\{$this->apiConfig['provider']}\\Configuration";
86+
} else {
87+
$configurationClass = "Apps\\{$this->apiConfig['location']}\\Packages\\System\\ApiClientServices\\Apis\\{$this->apiConfig['category']}\\{$this->apiConfig['provider']}\\Configuration";
88+
}
8489

8590
$this->config = new $configurationClass;
8691

8792
$this->config->setHost($this->helper->reduceSlashes($this->apiConfig['api_url']));
8893

8994
if (isset($this->apiConfig['debug']) && $this->apiConfig['debug'] === true) {
9095
$this->config->setDebug(true);
91-
$this->config->setDebugFile(base_path('var/log/api.log'));
96+
$this->config->setDebugFile(base_path("var/log/api_{$this->apiConfig['category']}_{$this->apiConfig['provider']}.log"));
9297
$this->httpOptions['debug'] = true;
9398
}
9499

@@ -156,9 +161,9 @@ public function toArray()
156161
return $responseArr;
157162
}
158163

159-
public function getApi()
164+
public function getApiClientServices()
160165
{
161-
return $this->api;
166+
return $this->apiClientServices;
162167
}
163168

164169
public function getApiConfig()

system/Base/Providers/BasepackagesServiceProvider/Packages/ApiClientServices/Apis/Repos/Gitea/ApisReposGitea.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ class ApisReposGitea extends Repos
88
{
99
public function init($apiConfig = null, $api = null, $httpOptions = null)
1010
{
11+
if (!isset($apiConfig['category'])) {
12+
$apiConfig['category'] = 'Repos';
13+
}
14+
if (!isset($apiConfig['provider'])) {
15+
$apiConfig['provider'] = 'Gitea';
16+
}
17+
1118
parent::init($apiConfig, $api, $httpOptions);
1219

1320
return $this;

system/Base/Providers/BasepackagesServiceProvider/Packages/ApiClientServices/Apis/Repos/Github/ApisReposGithub.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ class ApisReposGithub extends Repos
88
{
99
public function init($apiConfig = null, $api = null, $httpOptions = null)
1010
{
11+
if (!isset($apiConfig['category'])) {
12+
$apiConfig['category'] = 'Repos';
13+
}
14+
if (!isset($apiConfig['provider'])) {
15+
$apiConfig['provider'] = 'Github';
16+
}
17+
1118
parent::init($apiConfig, $api, $httpOptions);
1219

1320
return $this;

system/Base/Providers/BasepackagesServiceProvider/Packages/ApiClientServices/Apis/Repos/Repos.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ class Repos extends Apis
88
{
99
public function init($apiConfig = null, $api = null, $httpOptions = null)
1010
{
11+
if (!isset($apiConfig['category'])) {
12+
$apiConfig['category'] = 'Repos';
13+
}
14+
1115
parent::init($apiConfig, $api, $httpOptions);
1216

1317
return $this;

0 commit comments

Comments
 (0)