Fix vars exception, change cachedoc usage,

This commit is contained in:
Bradley Schofield
2022-08-13 20:18:48 +01:00
parent cb87c248d5
commit 237f5264d9
4 changed files with 6 additions and 44 deletions
+1 -22
View File
@@ -65,7 +65,7 @@ class Func extends Model
'type' => Response::MODEL_VARIABLE,
'description' => 'Function environment variables.',
'default' => [],
'example' => new \stdClass(),
'example' => [],
'array' => true
])
->addRule('events', [
@@ -121,25 +121,4 @@ class Func extends Model
{
return Response::MODEL_FUNCTION;
}
/**
* Filter Function
*
* Automatically converts a [] default to a stdClass, this is called while grabbing the document.
*
* @param Document $document
* @return Document
*/
public function filter(Document $document): Document
{
$vars = $document->getAttribute('vars');
if ($vars instanceof Document) {
$vars = $vars->getArrayCopy();
}
if (is_array($vars) && empty($vars)) {
$document->setAttribute('vars', new stdClass());
}
return $document;
}
}