Created
January 28, 2012 13:01
-
-
Save COil/1694230 to your computer and use it in GitHub Desktop.
Load fixtures with Symfony2, snippet 01
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace COil\Jobeet2Bundle\DataFixtures\ORM; | |
use Doctrine\Common\DataFixtures\AbstractFixture; | |
use Symfony\Component\DependencyInjection\ContainerAwareInterface; | |
use Symfony\Component\DependencyInjection\ContainerInterface; | |
use Symfony\Component\Yaml\Yaml; | |
abstract class LoadJobeet2Data extends AbstractFixture implements ContainerAwareInterface | |
{ | |
/** | |
* Return the file for the current model. | |
*/ | |
abstract function getModelFile(); | |
/** | |
* @var Symfony\Component\DependencyInjection\ContainerInterface | |
*/ | |
private $container; | |
/** | |
* Make the sc available to our loader. | |
* | |
* @param ContainerInterface $container | |
*/ | |
public function setContainer(ContainerInterface $container = null) | |
{ | |
$this->container = $container; | |
} | |
/** | |
* Return the fixtures for the current model. | |
* | |
* @return Array | |
*/ | |
public function getModelFixtures() | |
{ | |
$fixturesPath = realpath(dirname(__FILE__). '/../fixtures'); | |
$fixtures = Yaml::parse(file_get_contents($fixturesPath. '/'. $this->getModelFile(). '.yml')); | |
return $fixtures; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment