title: Filter tables to be mapped by Doctrine from the EntityManager (without command line)
body: <p>I'm developing a funcionality on my application that consists  on mapping and generate entities automatically.</p>
  
  <p>The problem is that the user can calect the tables to map, that is why I must to insert a filter for the name of the tables to be converted. To do this in command line, I just need to insert the parameter --filter:</p>
  
  <pre><code>php doctrine orm:convert-mapping --from-database --force --filter='class_name' xml /path_to_app/entities/metadata
  </code></pre>
  
  <p>However I'm developing the funcionality below in PHP, in order to obtain the return of a possible error. This function maps all the tables on database to XML, and posteriorly creates the entities from the mapping. In the meantime I don't know how to filter the tables by the name through the Doctrine PHP Library, in other words, how to do the parameter --filter='class_name'.</p>
  
  <pre><code>public function mapearTabelasValidar() {
  
          //Inicializa variáveis
          $dirBin = DIR_THIRD_PARTY . 'composer/vendor/bin/';
          $dirEntidades = DIR_MODELS . 'entidades/';
          $dirMetadados = $dirEntidades . 'metadados/';
          $title = 'Modelos gerados com sucesso!';
  
          try {
  
              //Inicializa o Doctrine e a configuração do EntityManager
              $doctrine = new Doctrine();
              $em = $doctrine-&gt;em;
              $em-&gt;getConfiguration()-&gt;setMetadataDriverImpl(
                      new \Doctrine\ORM\Mapping\Driver\DatabaseDriver(
                      $em-&gt;getConnection()-&gt;getSchemaManager()
                      )
              );
  
              //Define os metadados 
              $cmf = new \Doctrine\ORM\Tools\DisconnectedClassMetadataFactory();
              $cmf-&gt;setEntityManager($em);
              $metadata = $cmf;
  
              /**
               * Exporta os metadados das entidades em format xml
               * 
               * Comando similar:
               * php doctrine orm:convert-mapping --from-database --force xml /var/www/fwsibe/sistema/models/entidades/metadados
               */
              //echo "&lt;pre&gt;";
              //print_r($metadata);
              //die();
              $cme = new \Doctrine\ORM\Tools\Export\ClassMetadataExporter();
              $exporter = $cme-&gt;getExporter('xml', $dirMetadados);
              $exporter-&gt;setMetadata($metadata-&gt;getAllMetadata());
              $exporter-&gt;export();
  
              /**
               * Gera as entidades a partir do mapeamento XML gerado anteriormente
               * 
               * Comando similar:
               * php doctrine orm:generate:entities --generate-methods=1 --update-entities=1 /var/www/fwsibe/sistema/models/entidades
               */
              $generator = new \Doctrine\ORM\Tools\EntityGenerator();
              $generator-&gt;setGenerateStubMethods(true);
              $generator-&gt;setRegenerateEntityIfExists(false);
              $generator-&gt;generate($metadata-&gt;getAllMetadata(), $dirEntidades);
  
              //Trata a possível exeção
          } catch (Exception $exc) {
              mensagemExcecao($exc, "Falha ao mapear tabelas!", true);
          }
      }
  </code></pre>
  
  <p>Thanks!</p>