title: Get User inside a SQLFilter in Symfony 3
body: <p>I’m starting with Symfony and I want to make a multi tenant application.</p>
  
  <p>I want to automatically filter in my SQL queries the content according to the company of belonging of the connected user, every time a table has a link with my company table.</p>
  
  <p>I found the way to create filters but I can not find a way to retrieve in this filter the information about the company of the connected user.</p>
  
  <p>I use FOSuser I override it with my own User class.</p>
  
  <p>my config.yml</p>
  
  <pre><code>#app\config\config.yml
  
      doctrine:
          dbal:
             ...
          orm:
              auto_generate_proxy_classes: '%kernel.debug%'
              naming_strategy: doctrine.orm.naming_strategy.underscore
              auto_mapping: true
              filters:
                  company:
                      class: 'Acme\CompanyBundle\Repository\Filters\CompanyFilter'
                      enabled: true
  </code></pre>
  
  <p>my Filter</p>
  
  <pre><code>&lt;?php
  #src\Acme\CompanyBundle\Repository\Filters\CompanyFilter.php
  
  namespace Acme\CompanyBundle\Repository\Filters;
  
  use Doctrine\ORM\Mapping\ClassMetaData;
  use Doctrine\ORM\Query\Filter\SQLFilter;
  use Acme\UserBundle\Entity\UserEntity;
  use Acme\CompanyBundle\Entity\CompanyEntity;
  
  class CompanyFilter extends SQLFilter
  {
      public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias)
      {
          if ($targetEntity-&gt;hasAssociation("company")) {
  
              // here how to get the connected user ???
  
              $company = $user-&gt;getCompany();
              $idCompany = $company-&gt;getId();
              return $targetTableAlias . ".company_id = '".$idCompany."'";
  
  
          }
          return "";
      }
  }
  </code></pre>
  
  <p>in advance thank you for your help</p>