@@ -390,8 +390,8 @@ private function handleModifier(
390390 string $ modifier ,
391391 mixed $ bindValue
392392 ):void {
393- $ modifierChar = $ modifier[ 0 ] ;
394- $ modifierValue = substr ($ modifier, 1 );
393+ $ modifierChar = $ this -> getModifierType ( $ modifier) ;
394+ $ modifierValue = $ this -> getModifierBody ($ modifier );
395395 $ condition = null ;
396396 if (false !== $ spacePos = strpos ($ modifierValue , " " )) {
397397 $ modifierValue = substr ($ modifierValue , $ spacePos + 1 );
@@ -409,6 +409,9 @@ private function handleModifier(
409409 case ": " :
410410 $ tokenList = $ this ->getTokenList ($ element , $ attribute );
411411 $ tokenNames = $ this ->resolveTokenNames ($ modifier , $ bindValue );
412+ if ($ this ->isInverseModifier ($ modifier )) {
413+ $ bindValue = !$ bindValue ;
414+ }
412415 if ($ bindValue ) {
413416 $ tokenList ->add (...$ tokenNames );
414417 }
@@ -418,7 +421,7 @@ private function handleModifier(
418421 break ;
419422
420423 case "? " :
421- if ($ modifierValue [ 0 ] === " ! " ) {
424+ if ($ this -> isInverseModifier ( $ modifier ) ) {
422425 $ bindValue = !$ bindValue ;
423426 }
424427
@@ -463,8 +466,7 @@ private function extractBindKey(string $bindExpression):string {
463466 }
464467
465468 private function extractModifierExpression (string $ modifier ):string {
466- $ modifierValue = substr ($ modifier , 1 );
467- $ modifierValue = ltrim ($ modifierValue , "! " );
469+ $ modifierValue = $ this ->getModifierBody ($ modifier );
468470 return strtok ($ modifierValue , " " ) ?: "" ;
469471 }
470472
@@ -485,8 +487,7 @@ private function resolveTokenNames(string $modifier, mixed $bindValue):array {
485487
486488 /** @return array<int, string> */
487489 private function extractModifierTokens (string $ modifier ):array {
488- $ modifierValue = substr ($ modifier , 1 );
489- $ modifierValue = ltrim ($ modifierValue , "! " );
490+ $ modifierValue = $ this ->getModifierBody ($ modifier );
490491 $ spacePos = strpos ($ modifierValue , " " );
491492 if ($ spacePos === false ) {
492493 return [];
@@ -495,6 +496,30 @@ private function extractModifierTokens(string $modifier):array {
495496 return $ this ->prepareTokenListValues (substr ($ modifierValue , $ spacePos + 1 ));
496497 }
497498
499+ private function getModifierType (string $ modifier ):string {
500+ foreach (str_split ($ modifier ) as $ char ) {
501+ if ($ char === ": " || $ char === "? " ) {
502+ return $ char ;
503+ }
504+ }
505+
506+ return $ modifier [0 ];
507+ }
508+
509+ private function isInverseModifier (string $ modifier ):bool {
510+ return str_contains ($ modifier , "! " );
511+ }
512+
513+ private function getModifierBody (string $ modifier ):string {
514+ $ modifierType = $ this ->getModifierType ($ modifier );
515+ $ modifierValue = ltrim ($ modifier , "! " );
516+ if (str_starts_with ($ modifierValue , $ modifierType )) {
517+ return ltrim (substr ($ modifierValue , 1 ), "! " );
518+ }
519+
520+ return ltrim (substr ($ modifier , 1 ), "! " );
521+ }
522+
498523 private function extractCondition (string $ bindExpression ):?string {
499524 $ parts = explode ("= " , $ bindExpression , 2 );
500525 return $ parts [1 ] ?? null ;
0 commit comments