PHP code example of barechain / general

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

    

barechain / general example snippets




use Barechain\General\Dto;

final class User extends Dto
{
    public function __construct(
        public readonly string $firstName,
        public readonly string $lastName,
        public readonly bool $isEnabled = true
    ) {
    }
}

# Make new dto
$dto = new User(firstName: 'John', lastName: 'Doe', isEnabled: true);
$dto = new User('John', 'Doe');
$dto = new User(...['firstName' => 'John', 'lastName' => 'Doe', 'isEnabled' => false]);
$dto = new User(...['John', 'Doe', false]);

# Get all items in the Dto
$dto->all();

# Convert to array
$dto->toArray();

# Create collection
$dto->collect();

# Make new Dto with named arguments
$newDto = $dto->with(isEnabled: false, lastName: 'Smith');