本文整理汇总了PHP中Signal::detectAction方法的典型用法代码示例。如果您正苦于以下问题:PHP Signal::detectAction方法的具体用法?PHP Signal::detectAction怎么用?PHP Signal::detectAction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Signal
的用法示例。
在下文中一共展示了Signal::detectAction方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fromJson
/**
* Create a signal collection from JSON string.
*
* @param string $json
* @return GraphCommons\Graph\SignalCollection
* @throws GraphCommons\Util\JsonException, \InvalidArgumentException
*/
public static final function fromJson(string $json) : SignalCollection
{
$json = new Json($json);
if ($json->hasError()) {
$jsonError = $json->getError();
throw new JsonException(sprintf('JSON error: code(%d) message(%s)', $jsonError['code'], $jsonError['message']), $jsonError['code']);
}
$data = $json->decode(true);
if (!isset($data['signals'])) {
throw new \InvalidArgumentException("'signals' field is required!");
}
$array = array();
foreach ($data['signals'] as $i => $signal) {
if (!isset($signal['action'])) {
throw new \InvalidArgumentException("Signal 'action' and 'parameters' fields are required!");
}
$array[$i]['action'] = Signal::detectAction(Util::arrayPick($signal, 'action'));
foreach ($signal as $key => $value) {
$array[$i]['parameters'][$key] = $value;
}
}
return self::fromArray($array);
}
示例2: fillGraph
/**
* Fill a lib's graph object.
*
* @param GraphCommons\Graph\Graph $graph
* @param array|object $g
* @return GraphCommons\Graph\Graph
*/
private final function fillGraph(Graph $graph, $g) : Graph
{
// force input being an object
$g = Util::toObject($g);
if (isset($g->id)) {
$graph->setId($g->id)->setName($g->name)->setDescription($g->description)->setSubtitle($g->subtitle)->setStatus($g->status)->setCreatedAt($g->created_at);
// add signals if exists
if (isset($g->signals)) {
$array = [];
foreach ($g->signals as $i => $signal) {
$action = $signal->action;
unset($signal->action);
$array[$i]['action'] = Signal::detectAction($action);
$array[$i]['parameters'] = Util::toArray($signal);
}
$graph->setSignals(SignalCollection::fromArray($array));
}
}
return $graph;
}