for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace kujaff\VersionsBundle\Model;
/**
* Helps your using Doctrine
* Just needs a property ContainerInterface $container
*/
trait DoctrineHelper
{
* Execute a DQL query (only for SELECT, UPDATE or DELETE)
*
* @param string $dql
* @param array $parameters
* @return mixed
protected function executeDQL($dql, array $parameters = array())
$em = $this->container->get('doctrine')->getManager();
container
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
class MyClass { } $x = new MyClass(); $x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:
class MyClass { public $foo; } $x = new MyClass(); $x->foo = true;
$query = $em->createQuery($dql);
foreach ($parameters as $name => $value) {
$query->setParameter($name, $value);
}
return $query->getResult();
* Execute raw SQL
* @param string $sql
* @return \Doctrine\DBAL\Statement
protected function executeSQL($sql, array $parameters = array())
$stmt = $em->getConnection()->prepare($sql);
$stmt->bindValue($name, $value);
$stmt->execute();
return $stmt;
* Drop tables if exists
* @param array $tables
protected function dropTables(array $tables)
foreach ($tables as $table) {
$this->executeSQL('DROP TABLE IF EXISTS ' . $table);
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: