Doctrine\ODM\CouchDB\Tools\Console\MetadataFilter::filter PHP Method

filter() public static method

Filter Metadatas by one or more filter options.
public static filter ( array $metadatas, array | string $filter ) : array
$metadatas array
$filter array | string
return array
    public static function filter(array $metadatas, $filter)
    {
        $metadatas = new MetadataFilter(new \ArrayIterator($metadatas), $filter);
        return iterator_to_array($metadatas);
    }

Usage Example

 /**
  * @see Console\Command\Command
  */
 protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
 {
     $dm = $this->getHelper('couchdb')->getDocumentManager();
     $metadatas = $dm->getMetadataFactory()->getAllMetadata();
     $metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter'));
     // Process destination directory
     if (($destPath = $input->getArgument('dest-path')) === null) {
         $destPath = $dm->getConfiguration()->getProxyDir();
     }
     if (!is_dir($destPath)) {
         mkdir($destPath, 0777, true);
     }
     $destPath = realpath($destPath);
     if (!file_exists($destPath)) {
         throw new \InvalidArgumentException(sprintf("Proxies destination directory '<info>%s</info>' does not exist.", $destPath));
     } elseif (!is_writable($destPath)) {
         throw new \InvalidArgumentException(sprintf("Proxies destination directory '<info>%s</info>' does not have write permissions.", $destPath));
     }
     if (!count($metadatas)) {
         $output->write('No Metadata Classes to process.' . PHP_EOL);
         return;
     }
     foreach ($metadatas as $metadata) {
         $output->write(sprintf('Processing document "<info>%s</info>"', $metadata->name) . PHP_EOL);
     }
     // Acutally generate the Proxies
     $dm->getProxyFactory()->generateProxyClasses($metadatas, $destPath);
     $output->write(PHP_EOL . sprintf('Proxy classes generated to "<info>%s</INFO>"', $destPath) . PHP_EOL);
 }