Add 100+ automated unit tests from .expect file specifications Add session system test Add rsx:constants:regenerate command test Add rsx:logrotate command test Add rsx:clean command test Add rsx:manifest:stats command test Add model enum system test Add model mass assignment prevention test Add rsx:check command test Add migrate:status command test 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
58 lines
1.2 KiB
PHP
58 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\RSpade\Core\View;
|
|
|
|
/**
|
|
* PageData - Store page-specific data for JavaScript access
|
|
*
|
|
* Allows views to add data to window.rsxapp.page_data via @rsx_page_data directive.
|
|
* Data is accumulated during view rendering and output when bundle is rendered.
|
|
*
|
|
* Usage in Blade views:
|
|
* @rsx_page_data(['user_id' => $user->id])
|
|
* @rsx_page_data(['key' => 'value', 'another' => $data])
|
|
*
|
|
* Access in JavaScript:
|
|
* const user_id = window.rsxapp.page_data.user_id;
|
|
*/
|
|
class PageData
|
|
{
|
|
/**
|
|
* Accumulated page data for current request
|
|
*
|
|
* @var array
|
|
*/
|
|
protected static array $data = [];
|
|
|
|
/**
|
|
* Add data to page_data object
|
|
*
|
|
* @param array $data Associative array of data to add
|
|
* @return void
|
|
*/
|
|
public static function add(array $data): void
|
|
{
|
|
static::$data = array_merge(static::$data, $data);
|
|
}
|
|
|
|
/**
|
|
* Get all accumulated page data
|
|
*
|
|
* @return array
|
|
*/
|
|
public static function get(): array
|
|
{
|
|
return static::$data;
|
|
}
|
|
|
|
/**
|
|
* Check if any page data has been set
|
|
*
|
|
* @return bool
|
|
*/
|
|
public static function has_data(): bool
|
|
{
|
|
return !empty(static::$data);
|
|
}
|
|
}
|