Changeset 58825
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/interactivity-api/class-wp-interactivity-api.php
r58729 r58825 495 495 * @since 6.6.0 The function now adds a warning when the namespace is null, falsy, or the directive value is empty. 496 496 * @since 6.6.0 Removed `default_namespace` and `context` arguments. 497 * @since 6.6.0 Add support for derived state. 497 498 * 498 499 * @param string|true $directive_value The directive attribute value string or `true` when it's a boolean attribute. … … 531 532 return null; 532 533 } 533 } 534 535 if ( $current instanceof Closure ) {536 /*537 * This state getter's namespace is added to the stack so that538 * `state()` or `get_config()` read that namespace when called539 * without specifying one.540 */541 array_push( $this->namespace_stack, $ns );542 try {543 $current = $current();544 } catch ( Throwable $e ) {545 _doing_it_wrong(546 __METHOD__,547 sprintf(548 /* translators: 1: Path pointing to an Interactivity API state property, 2: Namespace for an Interactivity API store. */549 __( 'Uncaught error executing a derived state callback with path "%1$s" and namespace "%2$s".' ),550 $path,551 $ns552 ),553 '6.6.0'554 );555 return null;556 } finally {557 // Remove the property's namespace from the stack.558 array_pop( $this->namespace_stack );534 535 if ( $current instanceof Closure ) { 536 /* 537 * This state getter's namespace is added to the stack so that 538 * `state()` or `get_config()` read that namespace when called 539 * without specifying one. 540 */ 541 array_push( $this->namespace_stack, $ns ); 542 try { 543 $current = $current(); 544 } catch ( Throwable $e ) { 545 _doing_it_wrong( 546 __METHOD__, 547 sprintf( 548 /* translators: 1: Path pointing to an Interactivity API state property, 2: Namespace for an Interactivity API store. */ 549 __( 'Uncaught error executing a derived state callback with path "%1$s" and namespace "%2$s".' ), 550 $path, 551 $ns 552 ), 553 '6.6.0' 554 ); 555 return null; 556 } finally { 557 // Remove the property's namespace from the stack. 558 array_pop( $this->namespace_stack ); 559 } 559 560 } 560 561 } -
trunk/tests/phpunit/tests/interactivity-api/wpInteractivityAPI.php
r58729 r58825 1298 1298 } 1299 1299 1300 1301 1300 /** 1302 1301 * Tests the `evaluate` method for derived state functions that throw. … … 1321 1320 $result = $this->evaluate( 'state.derivedThatThrows' ); 1322 1321 $this->assertNull( $result ); 1322 } 1323 1324 /** 1325 * Tests the `evaluate` method for derived state intermediate values. 1326 * 1327 * @ticket 61741 1328 * 1329 * @covers ::evaluate 1330 */ 1331 public function test_evaluate_derived_state_intermediate() { 1332 $this->interactivity->state( 1333 'myPlugin', 1334 array( 1335 'derivedState' => function () { 1336 return array( 'property' => 'value' ); 1337 }, 1338 ) 1339 ); 1340 $this->set_internal_context_stack(); 1341 $this->set_internal_namespace_stack( 'myPlugin' ); 1342 1343 $result = $this->evaluate( 'state.derivedState.property' ); 1344 $this->assertSame( 'value', $result ); 1323 1345 } 1324 1346
Note: See TracChangeset
for help on using the changeset viewer.