本文整理匯總了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;
}