1. Go to this page and download the library: Download idei/usim library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
idei / usim example snippets
namespace App\UI\Screens;
use Idei\Usim\UI;
use Idei\Usim\Enums\LayoutType;
use Idei\Usim\Screen;
use Idei\Usim\Components\Container;
class HelloScreen extends Screen
{
protected function buildBaseUI(Container $container, ...$params): void
{
$container
->layout(LayoutType::VERTICAL)
->padding(20);
$container->add(
UI::label('title')
->text('Welcome to the UsersManager')
->style('h1')
);
$container->add(
UI::button('hello_btn')
->label('Hello USIM!')
->primary()
->action('hello_button_clicked')
);
}
public function onHelloButtonClicked(array $params): void
{
$this->toast('Data refreshed!', 'success');
}
}
class MyScreen extends Screen
{
protected string $store_username = ''; // persisted in plain text
protected int $store_page = 1; // persisted in plain text
protected string $store_theme = 'light'; // readable by the client
protected string $store_token_crypt = ''; // persisted encrypted
protected string $tempValue = ''; // NOT persisted
}
->visible(bool $visible)
->width(string $width)
->padding(mixed $padding)
->margin(mixed $margin)
// ... and many more styling options
// app/UI/Screens/Products/List.php
namespace App\UI\Screens\Products;
use Idei\Usim\Screen;
use Idei\Usim\Components\Container;
use Idei\Usim\UI;
class List extends Screen
{
protected function buildBaseUI(Container $container, ...$params): void
{
$container->add(
UI::label('title')->text('Products')->style('h1')
);
// Add your table, filters, etc.
}
}
// Public screen (default)
public static function authorize(): bool
{
return true;
}
// Authenticated users only
public static function authorize(): bool
{
return self:: return self::
public static function getMenuLabel(): string
{
return 'My Screen';
}
public static function getMenuIcon(): ?string
{
return '📊';
}
protected function postLoadUI(): void
{
// Update components with current data after state restoration
$user = Auth::user();
$this->input_name->value($user->name);
$this->input_email->value($user->email);
}
// In buildBaseUI:
$container->add(
UI::button('btn_save')
->label('Save')
->action('save_item') // → calls onSaveItem()
);
// Handler:
public function onSaveItem(array $params): void
{
$name = $params['input_name'] ?? '';
$email = $params['input_email'] ?? '';
// Save to database...
$this->toast('Item saved!', 'success');
}
use Idei\Usim\Events\UsimEvent;
// Emit from anywhere:
event(new UsimEvent('user_logged_in', ['user' => $user]));
// In Menu screen or any other screen:
public function onUserLoggedIn(array $params): void
{
$user = $params['user'];
$this->updateMenuForUser($user);
}
// Show a toast notification
$this->toast('Operation successful', 'success'); // types: success, error, info, warning
// Navigate to another URL
$this->redirect('/products');
$this->redirect(); // reload current screen
// Close the currently open modal
$this->closeModal();
// Update modal fields
$this->updateModal([
'field_name' => ['error' => 'This field is
use Idei\Usim\Modals\ConfirmDialog;
use Idei\Usim\Enums\DialogType;
public function onDeleteItem(array $params): void
{
ConfirmDialog::open(
caller: $this,
type: DialogType::CONFIRM,
title: 'Delete Item',
message: 'Are you sure you want to delete this item?',
confirmAction: 'confirm_delete',
cancelAction: 'cancel_delete',
);
}
public function onConfirmDelete(array $params): void
{
// Perform the delete...
$this->closeModal();
$this->toast('Item deleted', 'success');
}
use App\Models\User;
use App\UI\Screens\Admin\UsersManager;
use Idei\Usim\Contracts\ScreenAuthorizerInterface;
use Mockery;
it('authorizes admin via mock authorizer', function () {
$user = new User(['id' => 1, 'email' => '[email protected]']);
$authorizer = Mockery::mock(ScreenAuthorizerInterface::class);
$authorizer->shouldReceive('can')->with($user, 'users.manage', Mockery::any())->once()->andReturn(true);
app()->instance(ScreenAuthorizerInterface::class, $authorizer);
$screen = new UsersManager();
expect($screen->authorize($user))->toBeTrue();
});