-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added #[ArrayType(type)] and changed README
- Loading branch information
1 parent
36a81fa
commit 2b0e878
Showing
8 changed files
with
211 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "interaapps/jsonplus", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"type": "library", | ||
"authors": [ | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace de\interaapps\jsonplus\attributes; | ||
|
||
use Attribute; | ||
|
||
#[Attribute] | ||
class ArrayType { | ||
/** | ||
* @param class-string $value | ||
*/ | ||
public function __construct( | ||
public string $value | ||
){ | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
src/main/de/interaapps/jsonplus/typemapper/ArrayTypeMapper.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
namespace de\interaapps\jsonplus\typemapper; | ||
|
||
|
||
use de\interaapps\jsonplus\JSONPlus; | ||
|
||
class ArrayTypeMapper implements TypeMapper { | ||
public function __construct( | ||
private JSONPlus $jsonPlus | ||
){ | ||
} | ||
|
||
public function map(mixed $o, string $type, $entriesType = null): mixed { | ||
if ($entriesType !== null) { | ||
return $this->jsonPlus->mapTypedArray($o, $entriesType); | ||
} else | ||
return $o; | ||
} | ||
|
||
public function mapToJson(mixed $o, string $type): mixed { | ||
$out = []; | ||
foreach ($o as $i=>$val) { | ||
$out[$i] = $this->jsonPlus->mapToJson($val); | ||
} | ||
return $out; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters