Permalink
Browse files

[RED] Fixtures: YML file and LoadRivers class

  • Loading branch information...
gajdaw committed Jan 3, 2015
1 parent 7cd25b6 commit cd4178b2ec1e9f1eddb2cb4aa2c0026c4742a495
Showing with 34 additions and 0 deletions.
  1. +3 −0 data/rivers.yml
  2. +31 −0 src/AppBundle/DataFixtures/ORM/LoadRivers.php
View
@@ -0,0 +1,3 @@
- { name: "The Nile", length: 1234 }
- { name: "The Thames", length: 9876 }
- { name: "Mississipi", length: 3434 }
@@ -0,0 +1,31 @@
<?php
namespace AppBundle\DataFixtures\ORM;
use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\Yaml\Yaml;
use AppBundle\Entity\River;
class LoadRivers implements FixtureInterface
{
/**
* {@inheritDoc}
*/
public function load(ObjectManager $manager)
{
$filename = __DIR__ . '/../../../../data/rivers.yml';
$yml = Yaml::parse(file_get_contents($filename));
foreach ($yml as $item) {
$river = new River();
$river->setName($item['name']);
$river->setLength($item['length']);
$manager->persist($river);
}
$manager->flush();
}
}

0 comments on commit cd4178b

Please sign in to comment.