Fire event
public fire ( string $eventName, array | |
||
$eventName | string | Event to fire. You can also use wildcards to fire multiple events at once, ex: 'event.*' |
$data | array | |
Array or Event object |
$resultType | null | If specified, the event results will be filtered using given class/interface name |
$limit | null | integer | Number of results to return |
return | array | Array of results from EventListeners |
/** * @param Node\Scalar $scalar * @return CompiledExpression */ public function compile(Node\Scalar $scalar) { try { $this->eventManager->fire(Event\ScalarBeforeCompile::EVENT_NAME, new Event\ScalarBeforeCompile($scalar, $this->context)); return $this->factory($scalar); } catch (\Exception $e) { $this->context->debug('ScalarCompiler is not implemented for ' . get_class($scalar)); } }
/** * @param object|string $expr * @throws InvalidArgumentException when $expr is not string/object/null * @throws RuntimeException when compiler class does not return a CompiledExpression * @return CompiledExpression */ public function compile($expr) { if (is_string($expr)) { return new CompiledExpression(CompiledExpression::STRING, $expr); } if (is_null($expr)) { return new CompiledExpression(CompiledExpression::NULL); } if (!is_object($expr)) { throw new InvalidArgumentException('$expr must be string/object/null'); } if ($expr instanceof Node\Scalar) { $scalar = new \PHPSA\Compiler\Scalar($this->context, $this->eventManager); return $scalar->compile($expr); } $this->eventManager->fire(ExpressionBeforeCompile::EVENT_NAME, new ExpressionBeforeCompile($expr, $this->context)); $className = get_class($expr); switch ($className) { case Node\Arg::class: /** * @todo Better compile */ return $this->compile($expr->value); /** * Names */ /** * Names */ case Node\Name::class: return $this->getNodeName($expr); case Node\Name\FullyQualified::class: return $this->getFullyQualifiedNodeName($expr); } $expressionCompiler = $this->factory($expr); if (!$expressionCompiler) { $this->context->debug("Expression compiler is not implemented for {$className}"); return new CompiledExpression(CompiledExpression::UNIMPLEMENTED); } $result = $expressionCompiler->pass($expr, $this->context); if (!$result instanceof CompiledExpression) { throw new RuntimeException('Please return CompiledExpression from ' . get_class($expressionCompiler)); } return $result; }