??????????????
??????????????
??????????????
??????????????
Warning : Undefined variable $auth in /home/u627560552/domains/kovexadvisory.com/public_html/666.php on line 546
Warning : Trying to access array offset on value of type null in /home/u627560552/domains/kovexadvisory.com/public_html/666.php on line 546
??????????????
??????????????
??????????????
??????????????
File Manager
✏️ Edit File: /home/mklsvubc/monicslandscape.co.uk/wp-content/plugins/surerank/inc/schema/render.php
⬅ Kembali
<?php
/**
* Render
*
* This file will handle functionality for all Render.
*
* @package surerank
* @since 1.0.0
*/
namespace SureRank\Inc\Schema;
/**
* Class Render
*
* Handles the rendering of dynamic values with placeholders in a structured format.
*/
class Render {
/**
* Data collected for rendering.
*
* @var array<string, mixed>
*/
private $data;
/**
* Render constructor.
*
* @param Data $data Data instance containing the values to be rendered.
*/
public function __construct( Data $data ) {
$this->data = $data->collect();
}
/**
* Render the value, supporting both strings and arrays.
*
* @param mixed $value The value to render (string or array).
* @return void
*/
public function render( &$value ) {
if ( is_array( $value ) ) {
foreach ( $value as &$item ) {
$this->render( $item ); // Recursively render array items.
}
return;
}
if ( ! is_string( $value ) || ! str_contains( $value, '%' ) ) {
return;
}
// Match variables like %post.title% or %schemas.article%.
preg_match_all( '/%([^%\s]+)%/', $value, $matches );
foreach ( $matches[1] as $match ) {
$keys = explode( '.', $match );
$replacement = $this->resolve_variable( $keys, $this->data );
if ( is_array( $replacement ) ) {
$value = $replacement;
} else {
$value = str_replace( "%{$match}%", $replacement ?? '', $value );
}
// Check for additional variables introduced in the replacement and resolve recursively.
$this->render( $value );
}
}
/**
* Resolve a variable from a data source using dot notation keys.
*
* @param array<string, mixed>|array<int, string> $keys Array of keys to traverse the data structure.
* @param array<string, mixed> $data The data array to search within.
* @return mixed|null Resolved value or null if not found.
*/
private function resolve_variable( array $keys, array $data ) {
$current = $data;
foreach ( $keys as $key ) {
if ( is_array( $current ) && isset( $current[ $key ] ) ) {
$current = $current[ $key ];
} elseif ( is_object( $current ) && isset( $current->$key ) ) {
$current = $current->$key;
} else {
return null; // Key not found, return null.
}
}
return $current;
}
}
Nama
Tipe
Ukuran
Diubah
Aksi
📁 types
dir
—
2026-06-24 10:05
🐘 base.php
php
2.9 KB
2026-02-09 12:08
🐘 custom-fields.php
php
3.7 KB
2025-12-22 15:55
🐘 data.php
php
16.2 KB
2026-04-27 18:58
🐘 helper.php
php
1.9 KB
2026-01-14 10:26
🐘 options.php
php
414 B
2025-06-27 15:25
🐘 products.php
php
20.7 KB
2026-06-04 12:50
🐘 properties.php
php
20.7 KB
2026-02-09 12:08
🐘 render.php
php
2.2 KB
2025-06-27 15:25
🐘 rules.php
php
9.9 KB
2025-08-18 15:48
🐘 schema-render.php
php
6.8 KB
2026-05-20 12:46
🐘 schemas-api.php
php
23.7 KB
2026-06-04 12:50
🐘 schemas.php
php
6.9 KB
2026-06-17 16:29
🐘 utils.php
php
6.3 KB
2025-09-11 15:07
🐘 validator.php
php
15.5 KB
2025-12-22 15:55
🐘 variables.php
php
7 KB
2025-12-22 15:55