Created
April 7, 2021 02:13
-
-
Save franzose/1d5e02b681a28234a57a01e5f5a8e847 to your computer and use it in GitHub Desktop.
Query objects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class SomeEntityRepository extends EntityRepository | |
{ | |
public function findThis() | |
{ | |
// method body | |
} | |
public function findThat() | |
{ | |
// method body | |
} | |
public function findThese() | |
{ | |
// method body | |
} | |
public function findThose() | |
{ | |
// method body | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class FindThisQuery | |
{ | |
private $em; | |
private $repository; | |
public function __construct(EntityManagerInterface $em) | |
{ | |
$this->em = $em; | |
$this->repository = $em->getRepository(Entity::class); | |
} | |
public function __invoke() | |
{ | |
// query logic | |
} | |
} | |
class FindThatQuery | |
{ | |
private $em; | |
private $repository; | |
public function __construct(EntityManagerInterface $em) | |
{ | |
$this->em = $em; | |
$this->repository = $em->getRepository(Entity::class); | |
} | |
public function __invoke() | |
{ | |
// query logic | |
} | |
} | |
class FindTheseQuery | |
{ | |
private $em; | |
private $repository; | |
public function __construct(EntityManagerInterface $em) | |
{ | |
$this->em = $em; | |
$this->repository = $em->getRepository(Entity::class); | |
} | |
public function __invoke() | |
{ | |
// query logic | |
} | |
} | |
class FindThoseQuery | |
{ | |
private $em; | |
private $repository; | |
public function __construct(EntityManagerInterface $em) | |
{ | |
$this->em = $em; | |
$this->repository = $em->getRepository(Entity::class); | |
} | |
public function __invoke() | |
{ | |
// query logic | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Foo | |
{ | |
private $findThisQuery; | |
private $findThatQuery; | |
public function __construct(FindThisQuery $findThisQuery, FindThatQuery $findThatQuery) | |
{ | |
$this->findThisQuery = $findThisQuery; | |
$this->findThatQuery = $findThatQuery; | |
} | |
pubic function doStuff() | |
{ | |
$resultForThis = ($this->findThisQuery)(); | |
$resultForThat = ($this->findThatQuery)(); | |
// do something... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment