How can I parse a Symfony parameter into the fixtures.yml file of Alice

430 views Asked by At

I'm stuck with the package nelmio/alice (Expressive fixtures generator). I don't know how to parse a parameter from the general config/parameters.yml (in my case 'photoupload_directory') file into the fixtures.yml.

Now I have something hard coded like this:

photo: <Image('/Users/vivi/projects.2016/cvsymfony.local/storage/uploads/photos',1080,800,false,false)>...

I tried already:

photo: <Image(getParameter('photoupload_directory'),1080,800,false,false)>

but this is not working either. I also tried

$this->getParameter and $this->getContainer()->getParameter or the %photoupload_directory% notation).

Already searched the internet but so far nothing found.

1

There are 1 answers

0
Vincent On

Yes finally one solution, probably there are more (for parsing the parameters to this class), so if you know let me know. Below worked for me..

First add the name space ContainerAwareInterface :

use Symfony\Component\DependencyInjection\ContainerAwareInterface;

Add the Trait (in the class):

use \Symfony\Component\DependencyInjection\ContainerAwareTrait;

Create the function:

public function getPhotoUploadDir()
{
    return $this->container->getParameter('photoupload_directory');
}

In the fixtures.yml

photo: <Image($this->fake('getPhotoUploadDir'),1080,800,false,false)>