PHP code example of memran / marwa-support

1. Go to this page and download the library: Download memran/marwa-support 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/ */

    

memran / marwa-support example snippets

bash
use Marwa\Support\Arr;

$array = ['user' => ['name' => 'John', 'age' => 30]];

// Get value using dot notation
$name = Arr::get($array, 'user.name'); // "John"

// Check if key exists
$exists = Arr::has($array, 'user.email'); // false

// Get only specified keys
$filtered = Arr::only($array, ['user.name']); // ['user' => ['name' => 'John']]
bash
// Generate a link
echo Html::link('https://example.com', 'Visit Example');

// Generate a form
echo Html::form('/submit', 'POST', [
    'class' => 'my-form'
]);

// Parse HTML
$results = Html::extract($html, 'div.user > span.name');

// Generate complete document
echo Html::document('My Page', '<h1>Hello World</h1>', [
    'description' => 'A test page'
]);

bash
// Finder with collection methods
$files = Finder::in('/app')
    ->name('.*\.php$')
    ->files()
    ->map(fn($file) => $file->getPathname())
    ->sortBy(fn($path) => $path)
    ->values();
bash
// Basic validation
$data = [
    'name' => 'John Doe',
    'email' => '[email protected]',
    'password' => 'secret',
    'password_confirmation' => 'secret',
    'age' => 25
];

$rules = [
    'name' => ') {
    $errors = $validator->errors();
    // Handle errors
} else {
    // Validation passed
}

// Custom error messages
$messages = [
    'email.
bash
// Password handling
$hash = Security::passwordHash('secret123');
$isValid = Security::passwordVerify('secret123', $hash);

// Encryption
$encrypted = Security::encrypt('sensitive data', 'your-secret-key');
$decrypted = Security::decrypt($encrypted, 'your-secret-key');

// CSRF protection
$token = Security::csrfToken();
// In form: <input type="hidden" name="csrf_token" value="<?= $token