1. Go to this page and download the library: Download andrew-gos/class-builder 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/ */
andrew-gos / class-builder example snippets
use AndrewGos\ClassBuilder\ClassBuilder;
class A
{
public function __construct(
private int $a,
) {
}
}
$classBuilder = new ClassBuilder();
$a = $classBuilder->build(A::class, ['a' => 1]);
use AndrewGos\ClassBuilder\Attribute\AvailableInheritors;
#[AvailableInheritors([B::class, C::class])]
interface A {}
class B implements A {}
class C implements A {}
use AndrewGos\ClassBuilder\Attribute\AvailableInheritors;
use AndrewGos\ClassBuilder\Attribute\BuildIf;
use AndrewGos\ClassBuilder\Checker\FieldIsChecker;
#[AvailableInheritors([B::class, C::class])]
interface A {}
#[BuildIf(new FieldIsChecker('type', 'b'))]
class B implements A {}
#[BuildIf(new FieldIsChecker('type', 'a'))]
class C implements A {}
use AndrewGos\ClassBuilder\Attribute\ArrayType;
class A
{
public function __construct(
#[ArrayType('int')] private array $a,
) {
}
}
use AndrewGos\ClassBuilder\Attribute\CanBeBuiltFromScalar;
use AndrewGos\ClassBuilder\ClassBuilder;
#[CanBeBuiltFromScalar]
class A
{
public function __construct(
private int $a,
) {
}
}
$classBuilder = new ClassBuilder();
$a = $classBuilder->build(A::class, 1);
use AndrewGos\ClassBuilder\ClassBuilder;
use AndrewGos\ClassBuilder\Attribute\Field;
class A
{
public function __construct(
#[Field('b')] private int $a,
) {
}
}
$classBuilder = new ClassBuilder();
$a = $classBuilder->build(A::class, ['b' => 1]);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.