PHP code example of itsimiro / mi-structure

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

    

itsimiro / mi-structure example snippets


class MyStructure extends \Structure\Structure
{
    public int $userId = 1;
}

$userId = (new MyStructure())->userId;

// $userId = 1;


class MyStructure extends \Structure\Structure
{
    #[MapFrom(name: 'user_id')]
    public int $userId;
}

$userData = [
    'user_id' => 10
];

$structure = (new MyStructure($data));

$userId = $structure->userId;
// $userId = 10;

$userId = $structure->getUserId();
// $userId = 10;

class MyStructure extends \Structure\Structure
{
    #[VariableRules(length: 5, equals: 'Iron Man')]
    public string $name = 'Miro';
}

$userId = (new MyStructure())->name;
// There will be an exception "StructureValidateException"