PHP code example of otobank / phpstan-doctrine-criteria
1. Go to this page and download the library: Download otobank/phpstan-doctrine-criteria 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/ */
otobank / phpstan-doctrine-criteria example snippets
namespace App\Criteria;
use App\Entity\Foo;
use Otobank\PHPStan\Doctrine\Criteria;
class FooCriteria extends Criteria
{
public static function getTargetClass() : string
{
return Foo::class;
}
}
namespace App\Entity;
use App\Criteria\FooCriteria;
class Bar
{
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\OneToMany(targetEntity="Foo", mappedBy="bar")
*/
private $foos;
public function getFilteredFoos()
{
$criteria = FooCriteria::create();
$criteria = $criteria
->where($criteria->expr()->eq('fieldX', 1)) // Check if fieldX is defined in Foo class
;
return $this->foos->matching($criteria);
}
}