1<?php 2 3 4namespace EasySwoole\Spl; 5 6 7class SplDoubleLink 8{ 9 private $next; 10 private $pre; 11 12 function hashNext():bool 13 { 14 return (bool)$this->next; 15 } 16 17 function hashPre():bool 18 { 19 return (bool)$this->pre; 20 } 21 22 function next(...$arg):SplDoubleLink 23 { 24 if(!$this->next){ 25 $this->next = $this->newInstance(...$arg); 26 } 27 return $this->next; 28 } 29 30 function pre(...$arg):SplDoubleLink 31 { 32 if(!$this->pre){ 33 $this->pre = $this->newInstance(...$arg); 34 } 35 return $this->pre; 36 } 37 38 function delPre() 39 { 40 $this->pre = null; 41 return $this; 42 } 43 44 function delNext() 45 { 46 $this->next = null; 47 return $this; 48 } 49 50 private function newInstance(...$arg):SplDoubleLink 51 { 52 $ref = new \ReflectionClass(static::class); 53 return $ref->newInstanceArgs($arg); 54 } 55 56}