Adding initial support for services only events
Publish PHP Package / docker (push) Successful in 7s Details

This commit is contained in:
Pavel Shevaev 2025-01-20 20:12:19 +03:00
parent d228b43d1e
commit c330fda0cf
2 changed files with 50 additions and 2 deletions

View File

@ -586,6 +586,7 @@ class mtgMetaService extends mtgMetaUnit implements mtgScope
private $name;
private $parent_scope;
private $rpcs = array();
private $events = array();
private $user_types = array();
function __construct($name, mtgScope $parent_scope, array $tokens = array())
@ -615,7 +616,7 @@ class mtgMetaService extends mtgMetaUnit implements mtgScope
return $this->parent_scope->findSymbol($name);
}
function getRPCs()
function getRPCs() : array
{
return $this->rpcs;
}
@ -646,7 +647,7 @@ class mtgMetaService extends mtgMetaUnit implements mtgScope
return $this->rpcs[$name];
}
function getUserTypes()
function getUserTypes() : array
{
return $this->user_types;
}
@ -671,6 +672,17 @@ class mtgMetaService extends mtgMetaUnit implements mtgScope
return $this->user_types[$name];
}
function addEvent(mtgMetaStruct $evt)
{
$this->events[] = $evt;
$this->addUserStruct($evt);
}
function getEvents() : array
{
return $this->events;
}
function getClassId()
{
if($this->hasToken('class_id'))

View File

@ -31,6 +31,7 @@ class mtgMetaInfoParser2 implements mtgIMetaInfoParser
const T_bool = 1030;
const T_blob = 1031;
const T_Service = 1032;
const T_Event = 1033;
const T_MaxType = 1034; //built-in types end mark
private array $config = array();
@ -95,6 +96,7 @@ class mtgMetaInfoParser2 implements mtgIMetaInfoParser
"extends" => self::T_Extends,
"implements" => self::T_Implements,
"func" => self::T_Func,
"event" => self::T_Event,
];
$this->T2descr = array_flip($this->symbol2T);
@ -113,6 +115,7 @@ class mtgMetaInfoParser2 implements mtgIMetaInfoParser
$this->T2descr[self::T_Extends] = '<extends>';
$this->T2descr[self::T_Implements] = '<implements>';
$this->T2descr[self::T_Func] = '<func>';
$this->T2descr[self::T_Event] = '<Event>';
}
private static function _addDefaultTokens(array &$config)
@ -574,6 +577,37 @@ class mtgMetaInfoParser2 implements mtgIMetaInfoParser
$this->_addUnit(new mtgMetaInfoUnit($this->module, $fn));
}
private function _parseEvent() : mtgMetaStruct
{
$this->_nextT();
$struct_origin = new mtgOrigin($this->file, $this->line);
$name = $this->_parseDotName();
$this->_checkThenNext(ord('{'));
$s = new mtgMetaStruct($name, array(), null, array(), array());
$s->setOrigin($struct_origin);
$tokens = $this->shared_tokens;
if($this->T == self::T_Prop)
$tokens = array_merge($tokens, $this->_parsePropTokens());
$s->setTokens($tokens);
$flds = $this->_parseFields(
function()
{
if($this->_nextIf(ord('}')))
return true;
if($this->_nextIf(self::T_Func))
$this->_error("Events don't support functions");
}
);
foreach($flds as $fld)
$s->addField($fld);
return $s;
}
private function _parseStruct()
{
$this->_nextT();
@ -719,6 +753,8 @@ class mtgMetaInfoParser2 implements mtgIMetaInfoParser
$service->addRPC($this->_parseRPC(false));
else if($this->T == self::T_Enum)
$service->addUserType($this->_parseEnum(false));
else if($this->T == self::T_Event)
$service->addUserType($this->_parseEvent());
else
$this->_error("Unsupported type");
}