Skip to content

Commit d555c73

Browse files
committed
Add new DTO structure
1 parent 5c2e706 commit d555c73

File tree

5 files changed

+30
-22
lines changed

5 files changed

+30
-22
lines changed

Dom/Document.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public function createPrepend(string $element, ?string $value = null, ?string $b
124124
{
125125
$inst = new Element($element, $value);
126126
if (is_null($this->elements)) {
127-
$this->elements = array();
127+
$this->elements = [];
128128
}
129129
if (!is_null($bind)) {
130130
//$new[$bind] = $inst;
@@ -183,7 +183,7 @@ public function execute(?callable $call = null): string
183183
}
184184
return $this->html;
185185
}
186-
186+
187187
/**
188188
* Build document
189189
* @param array $arr elements

Dom/Element.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
class Element extends Document implements ElementInterface
1717
{
1818
private $elem;
19-
private $attr = array();
19+
private $attr = [];
2020
private $snippet;
2121
private $value;
2222
private $hideEmptyTag = false;

Interfaces/DocumentInterface.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ public function bindTag(string $tag, string $key, bool $prepend = false): Elemen
4040
*/
4141
public function create($element, $value = null, ?string $bind = null): ElementInterface;
4242

43-
/**
44-
* Prepend element first
45-
* @param string $element HTML tag (without brackets)
46-
* @param string $value add value to tag
47-
* @return ElementInterface
48-
*/
43+
/**
44+
* Prepend element first
45+
* @param string $element HTML tag (without brackets)
46+
* @param string $value add value to tag
47+
* @return ElementInterface
48+
*/
4949
public function createPrepend(string $element, ?string $value = null, ?string $bind = null): ElementInterface;
5050

5151
/**

SwiftRender.php

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@ public function setContainer(ContainerInterface $container): void
7777
$this->container = $container;
7878
}
7979

80+
/**
81+
* Set a PSR-6 cache instance for partial views, not required
82+
* @param CacheInterface $cache
83+
* @return void
84+
*/
85+
public function setCache(CacheInterface $cache): void
86+
{
87+
$this->cache = $cache;
88+
}
89+
8090
/**
8191
* Get container instance
8292
* @return ContainerInterface
@@ -202,7 +212,7 @@ public function setBuffer(string $output): self
202212
* @return self
203213
* @throws Exception
204214
*/
205-
public function setView(string|callable $file, array $args = array()): self
215+
public function setView(string|callable $file, array $args = []): self
206216
{
207217
if (is_null($this->file) && is_string($file)) {
208218
$this->setFile($file);
@@ -219,7 +229,7 @@ public function setView(string|callable $file, array $args = array()): self
219229
* @return self
220230
* @throws Exception
221231
*/
222-
public function withView(string $file, array $args = array()): self
232+
public function withView(string $file, array $args = []): self
223233
{
224234
$inst = clone $this;
225235
$inst->setView($file, $args);
@@ -234,9 +244,8 @@ public function withView(string $file, array $args = array()): self
234244
* @return SwiftRender
235245
* @throws Exception
236246
*/
237-
public function setPartial(string $partial, array $args = array(), int|false $cacheTime = false): self
247+
public function setPartial(string $partial, array $args = [], int|false $cacheTime = false): self
238248
{
239-
$this->partialKey = $partial;
240249
$keys = $this->selectPartial($partial, $file);
241250
if (is_null($this->file)) {
242251
$this->setFile($file);
@@ -273,7 +282,7 @@ public function unsetPartial(string $key): void
273282
* @return self
274283
* @throws Exception
275284
*/
276-
public function bindToBody(string $key, array $bindArr, array $args = array()): self
285+
public function bindToBody(string $key, array $bindArr, array $args = []): self
277286
{
278287
$this->setFile($key);
279288
$func = $this->build($this->file, $args);
@@ -413,11 +422,10 @@ private function buildView(): void
413422
*/
414423
private function build(
415424
string|callable $file,
416-
array $args = array(),
425+
array $args = [],
417426
?string $partialKey = null,
418427
int|false $cacheTime = false
419-
): callable
420-
{
428+
): callable {
421429

422430
if(is_null($this->cache) && $cacheTime !== false) {
423431
throw new Exception("Cache is not configured");
@@ -433,7 +441,7 @@ private function build(
433441
} else {
434442

435443
$throwError = true;
436-
$missingFiles = array();
444+
$missingFiles = [];
437445
$files = explode("|", $file);
438446

439447
foreach($files as $file) {
@@ -484,8 +492,7 @@ private function getOutput(
484492
?string $partialKey = null,
485493
array $args = [],
486494
int|false $cacheTime = false
487-
): void
488-
{
495+
): void {
489496
if($this->get == "partial" && !is_null($this->cache) && $cacheTime !== false) {
490497
$partialKey = str_replace(["!", "/"], ["", "_"], $partialKey);
491498
$updateTime = filemtime($filePath);
@@ -552,7 +559,7 @@ private function existAtGet(string $key): bool
552559
*/
553560
private function inclRouterFileData(string $filePath, object $obj, array $args): void
554561
{
555-
$extract = ($obj instanceof Traverse) ? $obj->toArray(function($row) {
562+
$extract = ($obj instanceof Traverse) ? $obj->toArray(function ($row) {
556563
return Traverse::value($row);
557564
}) : $args;
558565
extract($extract);

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "maplephp/swiftrender",
33
"type": "library",
4+
"version": "v1.1.0",
45
"description": "PHP SwiftRender is a pure and highly portable PHP template library.",
56
"keywords": ["output buffer", "template", "engine", "partials", "components", "views"],
67
"homepage": "https://wazabii.se",
@@ -17,7 +18,7 @@
1718
],
1819
"require": {
1920
"php": ">=8.0",
20-
"maplephp/dto": "^1.0",
21+
"maplephp/dto": "^2.0",
2122
"maplephp/container": "^1.0"
2223
},
2324
"autoload": {

0 commit comments

Comments
 (0)