PHP code example of steevanb / doctrine-read-only-hydrator
1. Go to this page and download the library: Download steevanb/doctrine-read-only-hydrator 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/ */
steevanb / doctrine-read-only-hydrator example snippets
# Foo\Repository\BarRepository
use steevanb\DoctrineReadOnlyHydrator\Hydrator\ReadOnlyHydrator;
class BarRepository
{
public function getReadOnlyUser($id)
{
return $this
->createQueryBuilder('user')
->select('user', 'PARTIAL comments.{id, comment}')
->join('user.comments', 'comments')
->where('user.id = :id')
->setParameter('id', $id)
->getQuery()
->getResult(ReadOnlyHydrator::HYDRATOR_NAME);
}
}
# app/AppKernel.php
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = [
new steevanb\DoctrineReadOnlyHydrator\Bridge\ReadOnlyHydratorBundle\ReadOnlyHydratorBundle()
];
}
}
use steevanb\DoctrineReadOnlyHydrator\Hydrator\SimpleObjectHydrator;
use steevanb\DoctrineReadOnlyHydrator\Hydrator\ReadOnlyHydrator;
$configuration->addCustomHydrationMode(SimpleObjectHydrator::HYDRATOR_NAME, SimpleObjectHydrator::class);
$configuration->addCustomHydrationMode(ReadOnlyHydrator::HYDRATOR_NAME, ReadOnlyHydrator::class);