PHP code example of sevaske / support

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

    

sevaske / support example snippets


use Sevaske\Support\Traits\HasAttributes;

class User {
    use HasAttributes;
}

$user = new User();
$user->fill(['name' => 'John', 'age' => 30]);
$user->age = 31;
$user->age; // 31
$user['age']; // 31
unset($user->name);

$copy = $user->replicate();

class User implements HasReadOnlyAttributesContract {
    use HasAttributes;

    public function getReadOnlyAttributes(): bool|array 
    {
        return ['age'];
    }
}

$user = new User();
$user->fill(['name' => 'John', 'age' => 30]);
$user->name = 'Alice'; // allowed
$user->age = 32; // throws LogicException

use Sevaske\Support\Exceptions\ContextableException;

    $ex = new ContextableException('Error', ['user_id' => 123]);
    $ex->withContext(['ip' => '127.0.0.1']);
    print_r($ex->context());