mirror of
https://codeberg.org/streams/streams.git
synced 2024-09-19 23:35:12 +00:00
Provide flag to throw exception on unhandled element
This commit is contained in:
parent
56c25b1c8d
commit
3f84b217f8
2 changed files with 29 additions and 8 deletions
|
@ -47,15 +47,28 @@ class ASObject
|
|||
public $canSearch;
|
||||
public $commentPolicy;
|
||||
|
||||
public function __construct($array = null)
|
||||
/**
|
||||
* @param $input
|
||||
* @param $strict
|
||||
* @throws UnhandledElementException if $strict
|
||||
*/
|
||||
|
||||
public function __construct($input = null, $strict = false)
|
||||
{
|
||||
if ($array && is_array($array)) {
|
||||
foreach ($array as $key => $value) {
|
||||
if ($key === '@context') {
|
||||
$key = 'ldcontext';
|
||||
}
|
||||
if (property_exists($this,$key)) {
|
||||
$this->{$key} = $value;
|
||||
if ($input) {
|
||||
if (is_array($input)) {
|
||||
foreach ($input as $key => $value) {
|
||||
if ($key === '@context') {
|
||||
$key = 'ldcontext';
|
||||
}
|
||||
if (property_exists($this, $key)) {
|
||||
$this->{$key} = $value;
|
||||
}
|
||||
else {
|
||||
if ($strict) {
|
||||
throw new UnhandledElementException("Unhandled element: $key");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
8
Code/ActivityStreams/UnhandledElementException.php
Normal file
8
Code/ActivityStreams/UnhandledElementException.php
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Code\ActivityStreams;
|
||||
|
||||
class UnhandledElementException extends \Exception
|
||||
{
|
||||
|
||||
}
|
Loading…
Reference in a new issue