Skip to content

Commit 082ccfb

Browse files
AReveronskie
authored andcommitted
REF #92 improved Action::getData by passing it a key and get the value
1 parent 3acb008 commit 082ccfb

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/Service/Action/Action.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,22 @@ public function implementedEvents(): array
311311
/**
312312
* Returns action input params
313313
*
314-
* @return array
314+
* @param string|null $name Dot separated name of the value to read. Or null to read all data.
315+
* @param mixed $default The default data.
316+
* @return mixed The value being read.
315317
*/
316-
public function getData(): array
318+
public function getData($name = null, $default = null)
317319
{
318-
return $this->getService()->getParser()->getParams();
320+
$data = $this->getService()->getParser()->getParams();
321+
if ($name === null) {
322+
return $data;
323+
}
324+
if (!is_array($data) && $name) {
325+
return $default;
326+
}
327+
328+
/** @psalm-suppress PossiblyNullArgument */
329+
return Hash::get($data, $name, $default);
319330
}
320331

321332
/**

0 commit comments

Comments
 (0)