| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Modules\AtomicWidgets\Elements\Base; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; // Exit if accessed directly. |
| 7 |
} |
| 8 |
|
| 9 |
class Render_Context { |
| 10 |
private static $context_stack = []; |
| 11 |
|
| 12 |
public static function push( string $key, array $context ): void { |
| 13 |
if ( ! self::get( $key ) ) { |
| 14 |
self::$context_stack[ $key ] = []; |
| 15 |
} |
| 16 |
|
| 17 |
self::$context_stack[ $key ][] = $context; |
| 18 |
} |
| 19 |
|
| 20 |
public static function pop( string $key ): void { |
| 21 |
if ( isset( self::$context_stack[ $key ] ) && ! empty( self::$context_stack[ $key ] ) ) { |
| 22 |
array_pop( self::$context_stack[ $key ] ); |
| 23 |
} |
| 24 |
} |
| 25 |
|
| 26 |
public static function get( string $key ): array { |
| 27 |
if ( ! isset( self::$context_stack[ $key ] ) || empty( self::$context_stack[ $key ] ) ) { |
| 28 |
return []; |
| 29 |
} |
| 30 |
|
| 31 |
$last_key = array_key_last( self::$context_stack[ $key ] ); |
| 32 |
return self::$context_stack[ $key ][ $last_key ]; |
| 33 |
} |
| 34 |
|
| 35 |
public static function clear(): void { |
| 36 |
self::$context_stack = []; |
| 37 |
} |
| 38 |
} |
| 39 |
|