Skip to content

Instantly share code, notes, and snippets.

@imiroslavov
Last active October 10, 2019 07:38
Show Gist options
  • Save imiroslavov/ce554ae19308a3c7aa03aa5eecb698f6 to your computer and use it in GitHub Desktop.
Save imiroslavov/ce554ae19308a3c7aa03aa5eecb698f6 to your computer and use it in GitHub Desktop.
Repository generator
<?php
namespace App\Repository;
use App\Entity\_Test_;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Symfony\Bridge\Doctrine\RegistryInterface;
/**
* Class _Test_Repository
*
* @method _Test_|null find($id, $lockMode = null, $lockVersion = null)
* @method _Test_|null findOneBy(array $criteria, array $orderBy = null)
* @method _Test_[] findAll()
* @method _Test_[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class _Test_Repository extends ServiceEntityRepository
{
/**
* _Test_Repository constructor.
*
* @param RegistryInterface $registry
*/
public function __construct(RegistryInterface $registry)
{
parent::__construct($registry, _Test_::class);
}
}
<?php
$files = scandir(__DIR__.'/Entity');
$template = file_get_contents(__DIR__.'/_Test_Repository.php');
foreach ($files as $file) {
if (!strpos($file, '.php')) {
continue;
}
$class = strstr($file, '.php', true);
$file =__DIR__.'/Repository/'.$class.'Repository.php';
file_put_contents($file, str_replace('_Test_', $class, $template));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment