Skip to content

Commit 9e669f8

Browse files
authored
v1.5.0 (#4)
* Added getJsonBody method * Made getJsonBody public * Updated setWebAppData array keys * Updated changelog
1 parent f1fd549 commit 9e669f8

File tree

6 files changed

+59
-16
lines changed

6 files changed

+59
-16
lines changed

CHANGELOG.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
- `Fixed` for any bug fixes.
1414
- `Security` in case of vulnerabilities
1515

16+
## [1.5.0] - 2025.03.07
17+
18+
### Added
19+
20+
- Added `getJsonBody` method to `WebAppController`
21+
22+
### Changed
23+
24+
- Changed array keys of Veil template data in `setWebAppData`
25+
1626
## [1.4.0] - 2025.01.10
1727

1828
### Added
1929

20-
Added public `Translate` class to `WebAppService`
30+
- Added public `Translate` class to `WebAppService`
2131

2232
## [1.3.0] - 2025.01.19
2333

composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"bayfrontmedia/bones": "^5.3",
3131
"bayfrontmedia/php-array-helpers": "^2.0",
3232
"bayfrontmedia/php-cookies": "^2.0",
33+
"bayfrontmedia/php-http-request": "^3.1",
3334
"bayfrontmedia/route-it": "^3.1",
3435
"bayfrontmedia/translation": "^2.0",
3536
"bayfrontmedia/veil": "^2.1"

docs/controllers.md

+15
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,23 @@ The [WebAppService class](webappservice-class.md) is available within the contro
1010

1111
Methods:
1212

13+
- [getJsonBody](#getjsonbody)
1314
- [respond](#respond)
1415

16+
## getJsonBody
17+
18+
**Description:**
19+
20+
Get JSON body from request as array, or return empty array if not existing.
21+
22+
**Parameters:**
23+
24+
- (none)
25+
26+
**Returns:**
27+
28+
- (array)
29+
1530
## respond
1631

1732
**Description:**

docs/filters.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,9 @@ Add support for the `@say:` template tag which returns the translation of a give
6464

6565
Set web app data for use in Veil templates.
6666

67-
- `app.version`: As defined at `app.version` config array, if existing
68-
- `locale.current`
69-
- `locale.valid`
70-
- `webapp`: `webapp.public` config array
67+
- `webapp.locale.current`
68+
- `webapp.locale.valid`
69+
- `webapp.public`: `webapp.public` config array
7170

7271
**Parameters:**
7372

src/Abstracts/WebAppController.php

+19
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Bayfront\BonesService\WebApp\Exceptions\WebAppServiceException;
77
use Bayfront\BonesService\WebApp\Interfaces\WebAppControllerInterface;
88
use Bayfront\BonesService\WebApp\WebAppService;
9+
use Bayfront\HttpRequest\Request;
910
use Bayfront\HttpResponse\InvalidStatusCodeException;
1011
use Bayfront\Veil\FileNotFoundException;
1112

@@ -31,6 +32,24 @@ public function __construct(WebAppService $webAppService)
3132

3233
}
3334

35+
/**
36+
* Get JSON body from request as array, or return empty array if not existing.
37+
*
38+
* @return array
39+
*/
40+
public function getJsonBody(): array
41+
{
42+
43+
$body = json_decode(Request::getBody(), true);
44+
45+
if (!$body || !is_array($body)) {
46+
return [];
47+
}
48+
49+
return $body;
50+
51+
}
52+
3453
/**
3554
* Send web app response.
3655
*

src/Filters/WebAppServiceFilters.php

+10-11
Original file line numberDiff line numberDiff line change
@@ -151,26 +151,25 @@ public function addTagSay(string $body): string
151151
/**
152152
* Set web app data for use in Veil templates.
153153
*
154-
* - app.version (As defined at app.version config array, if existing)
155-
* - locale.current
156-
* - locale.valid
157-
* - webapp (webapp.public config array)
154+
* - webapp.locale.current
155+
* - webapp.locale.valid
156+
* - webapp.public (webapp.public config array)
158157
*
159158
* @param array $data
160159
* @return array
161160
*/
162161
public function setWebAppData(array $data): array
163162
{
164163
$data = array_merge($data, [
165-
'locale' => [
166-
'current' => $this->translate->getLocale(),
167-
'valid' => App::getConfig('webapp.locale.valid', [])
168-
],
169-
'webapp' => App::getConfig('webapp.public', [])
164+
'webapp' => [
165+
'locale' => [
166+
'current' => $this->translate->getLocale(),
167+
'valid' => App::getConfig('webapp.locale.valid', [])
168+
],
169+
'public' => App::getConfig('webapp.public', [])
170+
]
170171
]);
171172

172-
$data['app']['version'] = App::getConfig('app.version');
173-
174173
VeilData::set($data);
175174
return $data;
176175
}

0 commit comments

Comments
 (0)