diff options
Diffstat (limited to 'vendor/doctrine/collections/docs/en/lazy-collections.rst')
| -rw-r--r-- | vendor/doctrine/collections/docs/en/lazy-collections.rst | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/vendor/doctrine/collections/docs/en/lazy-collections.rst b/vendor/doctrine/collections/docs/en/lazy-collections.rst new file mode 100644 index 0000000..b9cafb6 --- /dev/null +++ b/vendor/doctrine/collections/docs/en/lazy-collections.rst | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | Lazy Collections | ||
| 2 | ================ | ||
| 3 | |||
| 4 | To create a lazy collection you can extend the | ||
| 5 | ``Doctrine\Common\Collections\AbstractLazyCollection`` class | ||
| 6 | and define the ``doInitialize`` method. Here is an example where | ||
| 7 | we lazily query the database for a collection of user records: | ||
| 8 | |||
| 9 | .. code-block:: php | ||
| 10 | use Doctrine\DBAL\Connection; | ||
| 11 | |||
| 12 | class UsersLazyCollection extends AbstractLazyCollection | ||
| 13 | { | ||
| 14 | /** @var Connection */ | ||
| 15 | private $connection; | ||
| 16 | |||
| 17 | public function __construct(Connection $connection) | ||
| 18 | { | ||
| 19 | $this->connection = $connection; | ||
| 20 | } | ||
| 21 | |||
| 22 | protected function doInitialize() : void | ||
| 23 | { | ||
| 24 | $this->collection = $this->connection->fetchAll('SELECT * FROM users'); | ||
| 25 | } | ||
| 26 | } | ||
