PHP code example of php-etl / metadata

1. Go to this page and download the library: Download php-etl/metadata 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-etl / metadata example snippets




use Kiboko\Component\Metadata\TypeGuesser;
use Phpactor\Docblock\DocblockFactory;
use PhpParser\ParserFactory;

$typeGuesser = new TypeGuesser\CompositeTypeGuesser(
    new TypeGuesser\Native\NativeTypeGuesser(),
    new TypeGuesser\Docblock\DocblockTypeGuesser(
        (new ParserFactory())->create(ParserFactory::ONLY_PHP7),
        new DocblockFactory()
    )
);



use Kiboko\Component\Metadata;
use Kiboko\Component\Metadata\TypeGuesser\TypeGuesserInterface;

/** @var TypeGuesserInterface $guesser */

class Person
{
    public string $firstName;
    public string $lastName;
    public ?string $job;
}

$classOrObject = new \ReflectionClass(\Person::class);

/** @var Metadata\ClassTypeMetadata $metadata */
$metadata = (new Metadata\ClassTypeMetadata($classOrObject->getShortName(), $classOrObject->getNamespaceName()))
    ->addProperties(...array_map(
            function(\ReflectionProperty $property) use($classOrObject, $guesser) {
                return new Metadata\PropertyMetadata(
                    $property->getName(),
                    ...$guesser($classOrObject, $property)
                );
            },
            $classOrObject->getProperties(\ReflectionProperty::IS_PUBLIC)
        )
    );


use Kiboko\Component\Metadata;

/** @var Metadata\ClassMetadataBuilder $metadataBuilder */
$metadataBuilder = new Metadata\ClassMetadataBuilder(
    new Metadata\PropertyGuesser\ReflectionPropertyGuesser($typeGuesser),
    new Metadata\MethodGuesser\ReflectionMethodGuesser($typeGuesser),
    new Metadata\FieldGuesser\FieldGuesserChain(
        new Metadata\FieldGuesser\PublicPropertyFieldGuesser(),
        new Metadata\FieldGuesser\VirtualFieldGuesser()
    ),
    new Metadata\RelationGuesser\RelationGuesserChain(
        new Metadata\RelationGuesser\PublicPropertyUnaryRelationGuesser(),
        new Metadata\RelationGuesser\PublicPropertyMultipleRelationGuesser(),
        new Metadata\RelationGuesser\VirtualRelationGuesser()
    )
);

$metadata = $metadataBuilder->buildFromFQCN('FooBarBundle\\Entity\\Foo');
bash
composer