PHP code example of php-architecture-kit / technical

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

    

php-architecture-kit / technical example snippets


use PhpArchitecture\Technical\Assert;
use PhpArchitecture\Technical\ArrayTransformation;

// Assert all items are instances of a given class
Assert::eachInstanceOf($items, SomeClass::class);

// Assert all items are strings
Assert::eachString($tags);

// Index an array by a derived key
$indexed = ArrayTransformation::indexBy($items, fn($item) => $item->getId());

use PhpArchitecture\Technical\Assert;
use RuntimeException;

Assert::eachInstanceOf($commands, Command::class, RuntimeException::class);
Assert::eachString($names, \DomainException::class, displayLimit: 3);

use PhpArchitecture\Technical\ArrayTransformation;

$users = [new User('alice'), new User('bob')];
$byName = ArrayTransformation::indexBy($users, fn(User $u) => $u->getName());
// ['alice' => User, 'bob' => User]
bash
composer