<?php

namespace Acme\DemoBundle\Repository;

use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;

use Doctrine\ORM\EntityRepository;

/**
 * FooRepository
 *
 * @author Iain Cuthbertson <iain.cuthbertson@siftware.com>
 */
class FooRepository extends EntityRepository implements ContainerAwareInterface
{
    /**
     * @var ContainerInterface
     */
    private $container;

    public function setContainer(ContainerInterface $container = null)
    {
        $this->container = $container;
    }

    /**
     * Example method that uses a container service
     *
     * @param integer $parentId
     * @return \Acme\DemoBundle\Entity\Foo
     */
    public function getOrCreate($controllerId)
    {
        $foo = new Foo();
        
        $exampleTools = $this->container->get('exampleTools');
        $exampleTools->someMethod($foo);
        
        return $foo;
    }
}