우선 순위를 오름차순으로 변경
This commit is contained in:
@@ -2,12 +2,12 @@
|
|||||||
namespace sammo;
|
namespace sammo;
|
||||||
|
|
||||||
abstract class ObjectTrigger{
|
abstract class ObjectTrigger{
|
||||||
const PRIORITY_MAX = 99999;
|
const PRIORITY_MIN = 0;
|
||||||
const PRIORITY_BEGIN = 50000;
|
const PRIORITY_BEGIN = 10000;
|
||||||
const PRIORITY_PRE = 40000;
|
const PRIORITY_PRE = 20000;
|
||||||
const PRIORITY_BODY = 30000;
|
const PRIORITY_BODY = 30000;
|
||||||
const PRIORITY_POST = 20000;
|
const PRIORITY_POST = 40000;
|
||||||
const PRIORITY_FINAL = 10000;
|
const PRIORITY_FINAL = 50000;
|
||||||
|
|
||||||
static protected $priority;
|
static protected $priority;
|
||||||
protected $object = null;
|
protected $object = null;
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ namespace sammo;
|
|||||||
abstract class TriggerCaller{
|
abstract class TriggerCaller{
|
||||||
|
|
||||||
protected $triggerListByPriority = [];
|
protected $triggerListByPriority = [];
|
||||||
protected $sorted = false;
|
|
||||||
|
|
||||||
abstract function checkValidTrigger(ObjectTrigger $trigger):bool;
|
abstract function checkValidTrigger(ObjectTrigger $trigger):bool;
|
||||||
|
|
||||||
@@ -18,7 +17,7 @@ abstract class TriggerCaller{
|
|||||||
}
|
}
|
||||||
|
|
||||||
$sorted = true;
|
$sorted = true;
|
||||||
$minPriority = ObjectTrigger::PRIORITY_MAX;
|
$maxPriority = ObjectTrigger::PRIORITY_MIN;
|
||||||
|
|
||||||
foreach($triggerList as $trigger){
|
foreach($triggerList as $trigger){
|
||||||
if(!checkValidTrigger($trigger)){
|
if(!checkValidTrigger($trigger)){
|
||||||
@@ -29,10 +28,10 @@ abstract class TriggerCaller{
|
|||||||
$uniqueID = $trigger->getUniqueID();
|
$uniqueID = $trigger->getUniqueID();
|
||||||
|
|
||||||
if($sorted){
|
if($sorted){
|
||||||
if($minPriority > $priority){
|
if($maxPriority < $priority){
|
||||||
$minPriority = $priority;
|
$maxPriority = $priority;
|
||||||
}
|
}
|
||||||
else if($minPriority < $priority){
|
else if($maxPriority > $priority){
|
||||||
$sorted = false;
|
$sorted = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -46,7 +45,7 @@ abstract class TriggerCaller{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!$sorted){
|
if(!$sorted){
|
||||||
krsort($this->triggerListByPriority);
|
ksort($this->triggerListByPriority);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -64,7 +63,7 @@ abstract class TriggerCaller{
|
|||||||
}
|
}
|
||||||
|
|
||||||
$lastKey = Util::array_last_key($this->triggerListByPriority);
|
$lastKey = Util::array_last_key($this->triggerListByPriority);
|
||||||
if($lastKey > $priority){
|
if($lastKey < $priority){
|
||||||
$this->triggerListByPriority[$priority] = [$uniqueID=>$trigger];
|
$this->triggerListByPriority[$priority] = [$uniqueID=>$trigger];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -74,7 +73,7 @@ abstract class TriggerCaller{
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->triggerListByPriority[$priority] = [$uniqueID=>$trigger];
|
$this->triggerListByPriority[$priority] = [$uniqueID=>$trigger];
|
||||||
krsort($this->triggerListByPriority);
|
ksort($this->triggerListByPriority);
|
||||||
}
|
}
|
||||||
|
|
||||||
function merge(?TriggerCaller $other){
|
function merge(?TriggerCaller $other){
|
||||||
@@ -87,7 +86,7 @@ abstract class TriggerCaller{
|
|||||||
$iterRhs = new \ArrayIterator($other->triggerListByPriority);
|
$iterRhs = new \ArrayIterator($other->triggerListByPriority);
|
||||||
|
|
||||||
while($iterLhs->valid() && $iterRhs->valid()){
|
while($iterLhs->valid() && $iterRhs->valid()){
|
||||||
if($iterLhs->key() > $iterRhs->key()){
|
if($iterLhs->key() < $iterRhs->key()){
|
||||||
$newTriggerList[$iterLhs->key()] = $iterLhs->current();
|
$newTriggerList[$iterLhs->key()] = $iterLhs->current();
|
||||||
$iterLhs->next();
|
$iterLhs->next();
|
||||||
continue;
|
continue;
|
||||||
@@ -116,11 +115,6 @@ abstract class TriggerCaller{
|
|||||||
}
|
}
|
||||||
|
|
||||||
function fire(?array $env = null, $arg = null):?array{
|
function fire(?array $env = null, $arg = null):?array{
|
||||||
if(!$this->sorted){
|
|
||||||
krsort($this->triggerListByPriority);
|
|
||||||
$this->sorted = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach($this->triggerListByPriority as $subTriggerList){
|
foreach($this->triggerListByPriority as $subTriggerList){
|
||||||
/** @var ObjectTrigger[] $subTriggerList */
|
/** @var ObjectTrigger[] $subTriggerList */
|
||||||
foreach($subTriggerList as $trigger){
|
foreach($subTriggerList as $trigger){
|
||||||
|
|||||||
Reference in New Issue
Block a user