for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace ORM\Dbal;
use DateTime;
use DateTimeZone;
trait Escaping
{
/** @var string */
protected $quotingCharacter = '"';
protected $identifierDivider = '.';
protected $booleanTrue = '1';
protected $booleanFalse = '0';
/**
* Extract content from parenthesis in $type
*
* @param string $type
* @return string
*/
protected function extractParenthesis($type)
if (preg_match('/\((.+)\)/', $type, $match)) {
return $match[1];
}
return null;
* Escape a string for query
* @param string $value
protected function escapeString($value)
return $this->entityManager->getConnection()->quote($value);
entityManager
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;
* Escape an integer for query
* @param int $value
protected function escapeInteger($value)
return (string) $value;
* Escape a double for Query
* @param double $value
protected function escapeDouble($value)
* Escape NULL for query
protected function escapeNULL()
return 'NULL';
* Escape a boolean for query
* @param bool $value
protected function escapeBoolean($value)
return ($value) ? $this->booleanTrue : $this->booleanFalse;
* Escape a date time object for query
* @param DateTime $value
* @return mixed
protected function escapeDateTime(DateTime $value)
$value->setTimezone(new DateTimeZone('UTC'));
return $this->escapeString($value->format('Y-m-d\TH:i:s.u\Z'));
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: