Skip to content

Commit

Permalink
Merge pull request #3 from curiosity26/develop
Browse files Browse the repository at this point in the history
Still need to do the cast, but let's not bring in a huge library for it
  • Loading branch information
curiosity26 authored Nov 12, 2018
2 parents 4672a2e + e4d63b2 commit b02fd38
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 3 deletions.
1 change: 0 additions & 1 deletion .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 18 additions & 1 deletion DependencyInjection/Curiosity26AclHelperExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@

namespace Curiosity26\AclHelperBundle\DependencyInjection;

use Curiosity26\AclHelperBundle\Doctrine\DQL\CastAsInt;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;

class Curiosity26AclHelperExtension extends Extension
class Curiosity26AclHelperExtension extends Extension implements PrependExtensionInterface
{
/**
* @param array $configs
Expand All @@ -26,4 +28,19 @@ public function load(array $configs, ContainerBuilder $container)
$loader = new YamlFileLoader($container, new FileLocator([__DIR__.'/../Resources/config/']));
$loader->load('services.yaml');
}

public function prepend(ContainerBuilder $container)
{
$configs = $container->getExtensionConfig('doctrine');

if (!empty($configs) && array_key_exists('orm', $configs[0])) {
$config = $configs[0];
$default = array_key_exists(
'default_entity_manager',
$config['orm']
) ? $config['orm']['default_entity_manager'] : 'default';
$config['orm']['entity_managers'][$default]['dql']['string_functions']['INT'] = CastAsInt::class;
$container->prependExtensionConfig('doctrine', $config);
}
}
}
38 changes: 38 additions & 0 deletions Doctrine/DQL/CastAsInt.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/**
* Created by PhpStorm.
* User: alex.boyce
* Date: 11/12/18
* Time: 3:34 PM
*/

namespace Curiosity26\AclHelperBundle\Doctrine\DQL;

use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\AST\InputParameter;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\SqlWalker;

class CastAsInt extends FunctionNode
{
/**
* @var InputParameter
*/
public $stringPrimary;

public function getSql(SqlWalker $sqlWalker)
{
return 'CAST(' . $this->stringPrimary->dispatch($sqlWalker) . ' AS integer)';
}

public function parse(Parser $parser)
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);

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

$parser->match(Lexer::T_CLOSE_PARENTHESIS);
}
}
2 changes: 1 addition & 1 deletion QueryBuilder/AclHelperQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function buildAclQuery($strategy = PermissionGrantingStrategy::ANY)
}

$q
->select('acl_o.objectIdentifier')
->select('INT(acl_o.objectIdentifier)')
->distinct()
->from(ObjectIdentity::class, 'acl_o')
->innerJoin(AclClass::class, 'acl_c', Join::WITH, 'acl_c.id = acl_o.classId')
Expand Down

0 comments on commit b02fd38

Please sign in to comment.