Skip to content

Instantly share code, notes, and snippets.

<?php
....
public function prePersist(LifecycleEventArgs $args)
{
$entity = $args->getEntity();
if (method_exists($entity, 'setCreatedBy') {
$user = $this->container->get('security.context')->getToken()->getUser();
$entity->setCreatedBy($user);
}
@Ziumin
Ziumin / IlikeWalker.php
Created August 14, 2012 08:37
[Postgres] Replace LIKE with IIKE (output walker)
<?php
namespace XXX\SearchBundle\Doctrine;
use Doctrine\ORM\Query\SqlWalker;
/**
* Replace LIKE with ILIKE
* Usage: $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'XXX\SearchBundle\Doctrine\IlikeWalker');
*
* @author Ziumin
@Ziumin
Ziumin / MockingDialogTest.php
Created July 26, 2012 09:22
[Symfony2] Mocking user input when testing commands
<?php
namespace XXX\ToolkitBundle\Tests\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use XXX\ToolkitBundle\Command\CommonGenerateCommand;