<?php



namespace ACSEO\FastShowGeneratorBundle\Generator;

use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
use Sensio\Bundle\GeneratorBundle\Generator\Generator;


class FastShowYamlGenerator extends Generator
{
    private $filesystem;

    /**
     * Constructor.
     *
     * @param Filesystem $filesystem A Filesystem instance
     */
    public function __construct(Filesystem $filesystem)
    {
        $this->filesystem = $filesystem;
    }

    public function generate(BundleInterface $bundle, $entityClass, $entity, $group, $extension)
    {
        $this->setSkeletonDirs(__DIR__.'/../Resources/skeleton');
        $dir = sprintf("%s/Resources/config/fastshow",$bundle->getPath());
        if (!file_exists($dir)) {
            $this->filesystem->mkdir($dir, 0777);
        }

        $gridFile = sprintf("%s/%s.%s%s", $dir, $entity, $group, $extension);

        $instance = new \ReflectionClass($entityClass);

        $parameters = array(
            'columns'  => $instance->getProperties(),
            'entityClass' => $entityClass
        );

        $this->renderFile('fastshow/fastshow.yml.twig', $gridFile, $parameters);
    }

}
