Skip to content

Commit

Permalink
Merge pull request beberlei#37 from gallien/master
Browse files Browse the repository at this point in the history
Add MySQL encryption functions MD5, SHA1 and SHA2.
  • Loading branch information
beberlei committed Jun 18, 2011
2 parents 0ccb57a + ef9a467 commit 39e1e24
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 0 deletions.
56 changes: 56 additions & 0 deletions lib/DoctrineExtensions/Query/Mysql/Md5.php
@@ -0,0 +1,56 @@
<?php

/*
* DoctrineExtensions Mysql Function Pack
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to kontakt@beberlei.de so I can send you a copy immediately.
*/

namespace DoctrineExtensions\Query\Mysql;

use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\AST\Functions\FunctionNode;

/**
* "MD5" "(" StringPrimary ")"
*
* @category DoctrineExtensions
* @package DoctrineExtensions\Query\Mysql
* @author Andreas Gallien <gallien@seleos.de>
* @license New BSD License
*/
class Md5 extends FunctionNode
{
public $stringPrimary;

/**
* @override
*/
public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
{
return $sqlWalker->getConnection()->getDatabasePlatform()->getMd5Expression(
$sqlWalker->walkStringPrimary($this->stringPrimary)
);
}

/**
* @override
*/
public function parse(\Doctrine\ORM\Query\Parser $parser)
{
$lexer = $parser->getLexer();

$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);

$this->stringPrimary = $parser->StringPrimary();

$parser->match(Lexer::T_CLOSE_PARENTHESIS);
}
}
56 changes: 56 additions & 0 deletions lib/DoctrineExtensions/Query/Mysql/Sha1.php
@@ -0,0 +1,56 @@
<?php

/*
* DoctrineExtensions Mysql Function Pack
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to kontakt@beberlei.de so I can send you a copy immediately.
*/

namespace DoctrineExtensions\Query\Mysql;

use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\AST\Functions\FunctionNode;

/**
* "SHA1" "(" StringPrimary ")"
*
* @category DoctrineExtensions
* @package DoctrineExtensions\Query\Mysql
* @author Andreas Gallien <gallien@seleos.de>
* @license New BSD License
*/
class Sha1 extends FunctionNode
{
public $stringPrimary;

/**
* @override
*/
public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
{
return 'SHA1(' .
$sqlWalker->walkStringPrimary($this->stringPrimary) .
')';
}

/**
* @override
*/
public function parse(\Doctrine\ORM\Query\Parser $parser)
{
$lexer = $parser->getLexer();

$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);

$this->stringPrimary = $parser->StringPrimary();

$parser->match(Lexer::T_CLOSE_PARENTHESIS);
}
}
62 changes: 62 additions & 0 deletions lib/DoctrineExtensions/Query/Mysql/Sha2.php
@@ -0,0 +1,62 @@
<?php

/*
* DoctrineExtensions Mysql Function Pack
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to kontakt@beberlei.de so I can send you a copy immediately.
*/

namespace DoctrineExtensions\Query\Mysql;

use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\AST\Functions\FunctionNode;

/**
* "SHA2" "(" StringPrimary "," SimpleArithmeticExpression ")"
*
* @category DoctrineExtensions
* @package DoctrineExtensions\Query\Mysql
* @author Andreas Gallien <gallien@seleos.de>
* @license New BSD License
*/
class Sha2 extends FunctionNode
{
public $stringPrimary;

public $simpleArithmeticExpression;

/**
* @override
*/
public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
{
return 'SHA2(' .
$sqlWalker->walkStringPrimary($this->stringPrimary) .
',' .
$sqlWalker->walkSimpleArithmeticExpression($this->simpleArithmeticExpression) .
')';
}

/**
* @override
*/
public function parse(\Doctrine\ORM\Query\Parser $parser)
{
$lexer = $parser->getLexer();

$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);

$this->stringPrimary = $parser->StringPrimary();
$parser->match(Lexer::T_COMMA);
$this->simpleArithmeticExpression = $parser->SimpleArithmeticExpression();

$parser->match(Lexer::T_CLOSE_PARENTHESIS);
}
}

0 comments on commit 39e1e24

Please sign in to comment.