public static function getType($typeName)
{
switch ($typeName) {
case 'integer':
case 'int':
return CompiledExpression::INTEGER;
case 'double':
return CompiledExpression::DOUBLE;
case 'string':
return CompiledExpression::STRING;
case 'resource':
return CompiledExpression::RESOURCE;
case 'callable':
return CompiledExpression::CALLABLE_TYPE;
case 'object':
return CompiledExpression::OBJECT;
case 'array':
return CompiledExpression::ARR;
case 'boolean':
case 'bool':
return CompiledExpression::BOOLEAN;
case 'NULL':
return CompiledExpression::NULL;
}
//@codeCoverageIgnoreStart
throw new RuntimeException("Type '{$typeName}' is not supported");
//@codeCoverageIgnoreEnd
}
/** * Compile function to check it * * @param Context $context * @return bool */ public function compile(Context $context) { if ($this->compiled) { return true; } $context->setFilepath($this->filepath); $this->compiled = true; $context->scopePointer = $this->getPointer(); $context->setScope(null); $context->getEventManager()->fire(Event\StatementBeforeCompile::EVENT_NAME, new Event\StatementBeforeCompile($this->statement, $context)); if (count($this->statement->params) > 0) { /** @var Node\Param $parameter */ foreach ($this->statement->params as $parameter) { $type = CompiledExpression::UNKNOWN; if ($parameter->type) { if (is_string($parameter->type)) { $type = Types::getType($parameter->type); } elseif ($parameter->type instanceof Node\Name) { $type = CompiledExpression::OBJECT; } } $context->addVariable(new Parameter($parameter->name, null, $type, $parameter->byRef)); } } foreach ($this->statement->stmts as $st) { \PHPSA\nodeVisitorFactory($st, $context); } return true; }