1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Canvas\Api\Controllers; |
6
|
|
|
|
7
|
|
|
use Baka\Http\Api\BaseController as BakaBaseController; |
8
|
|
|
use Canvas\Models\Apps; |
9
|
|
|
use Canvas\Dto\AppsSettings; |
10
|
|
|
use Phalcon\Http\Response; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class LanguagesController. |
14
|
|
|
* |
15
|
|
|
* @package Canvas\Api\Controllers |
16
|
|
|
* |
17
|
|
|
*/ |
18
|
|
|
class AppsSettingsController extends BakaBaseController |
19
|
|
|
{ |
20
|
|
|
/* |
21
|
|
|
* fields we accept to create |
22
|
|
|
* |
23
|
|
|
* @var array |
24
|
|
|
*/ |
25
|
|
|
protected $createFields = []; |
26
|
|
|
|
27
|
|
|
/* |
28
|
|
|
* fields we accept to create |
29
|
|
|
* |
30
|
|
|
* @var array |
31
|
|
|
*/ |
32
|
|
|
protected $updateFields = []; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* set objects. |
36
|
|
|
* |
37
|
|
|
* @return void |
38
|
|
|
*/ |
39
|
|
|
public function onConstruct() |
40
|
|
|
{ |
41
|
|
|
$this->model = new Apps(); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Format output. |
46
|
|
|
* |
47
|
|
|
* @param [type] $results |
48
|
|
|
* @return void |
49
|
|
|
*/ |
50
|
|
|
protected function processOutput($results) |
51
|
|
|
{ |
52
|
|
|
//DTOAppsSettings |
53
|
|
|
$this->dtoConfig->registerMapping(Apps::class, AppsSettings::class) |
54
|
|
|
->forMember('settings', function (Apps $app) { |
55
|
|
|
$settings = []; |
56
|
|
|
foreach ($app->settingsApp->toArray() as $setting) { |
57
|
|
|
$settings[$setting['name']] = $setting['value']; |
58
|
|
|
} |
59
|
|
|
return $settings; |
60
|
|
|
}); |
61
|
|
|
|
62
|
|
|
return is_iterable($results) ? |
63
|
|
|
$this->mapper->mapMultiple(iterator_to_array($results), AppsSettings::class) |
64
|
|
|
: $this->mapper->map($results, AppsSettings::class); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* get item. |
69
|
|
|
* |
70
|
|
|
* @param mixed $id |
71
|
|
|
* |
72
|
|
|
* @method GET |
73
|
|
|
* @url /v1/data/{id} |
74
|
|
|
* |
75
|
|
|
* @return \Phalcon\Http\Response |
76
|
|
|
*/ |
77
|
|
|
public function getByKey($key = null): Response |
78
|
|
|
{ |
79
|
|
|
//find the info |
80
|
|
|
$record = $this->model->findFirst([ |
81
|
|
|
'key = ?0 AND is_deleted = 0', |
82
|
|
|
'bind' => [$key], |
83
|
|
|
]); |
84
|
|
|
|
85
|
|
|
return $this->response($this->processOutput($record)); |
|
|
|
|
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.