PHP code example of rugolinifr / enhanced-find-by

1. Go to this page and download the library: Download rugolinifr/enhanced-find-by 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/ */

    

rugolinifr / enhanced-find-by example snippets


$finder = (new \Rugolinifr\EnhancedFindBy\Factory\EnhancedFindByFactory())
    ->createEnhancedFindBy($entityManager);

// fetches every `Person` entity
$entities = $finder->findBy(Person::class);

// fetches every newborn `Person` entity using the "greater than" operator
$newborns = $finder->findBy(Person::class, ['birth >' => new \DateTimeImmutable('yesterday')]);

// fetches every newborn girl `Person`
$newborns = $finder->findBy(
    Person::class,
    [
        'birth >' => new \DateTimeImmutable('yesterday'),
        'sex =' => GenderEnum::GIRL,
    ],
);

// fetches every extra-European `Person` entity with implicit joins on two other entities
$extraEuropeans = $finder->findBy(Person::class, ['address.country.continent !=' => 'Europe']);

// fetches every `Person` entity having long black hair from a Doctrine embeddable
$blackHairedPersons = $finder->findBy(
    Person::class,
    [
        'hair->length >' => 20,
        'hair->color =' => 'black',  // Use arrow ("->") notation to filter against a Doctrine embeddable
    ],
);

$finder->findBy(
    Person::class,
    [
        'name like' => 'John%',
        'birth <' => new DateTimeImmutable('2010-01-01'),
        'eyeColor !=' => 'blue',
        'address.country.continent =' => 'Europe',
    ],
);

// fetches every Person having a description starting with "Once upon a time"
$finder->findBy(Person::class, ['description like' => 'Once upon a time%']);

$finder->findBy(
    from: Person::class,
    where: ['height <=' => 200],
    orderBy: [
        'address.country.continent' => 'ASC',
        'name' => 'DESC',
    ],
);

$finder->findBy(
    from: Person::class,
    limit: 30,
    offset: 60,
);

$query->setMaxResults(30)->setFirstResult(60);

$counter = (new \Rugolinifr\EnhancedFindBy\Factory\EnhancedFindByFactory())
    ->createEnhancedCount($entityManager);

$count = $counter->count(
    from: Person::class,
    where: [
        'name like' => 'John%',
        'eyeColor !=' => 'blue',
    ],
);
dql
SELECT e0
FROM Person e0
JOIN e0.address e1
JOIN e1.country e2
WHERE e0.name LIKE 'John%'
AND e0.birth < '2010-01-01'
AND e0.eyeColor != 'blue'
AND e2.continent = 'Europe'
shell
docker compose up -d --build --force-recreate
docker compose exec php vendor/bin/phpunit tests
docker compose exec php php -d memory_limit=-1 /usr/local/bin/phpstan analyze