Skip to content

Instantly share code, notes, and snippets.

@avalanche123
Created December 23, 2010 15:25
Show Gist options
  • Save avalanche123/753115 to your computer and use it in GitHub Desktop.
Save avalanche123/753115 to your computer and use it in GitHub Desktop.
interface Symfony\Bundle\FrameworkBundle\Request\ParamConverter\ConverterInterface
{
function convert($value);
function setOption($key, $option);
function getOption($key);
}
class Symfony\Bundle\DoctrineMongoDBBundle\Converter\DocumentConverter implements Symfony\Bundle\FrameworkBundle\Request\ParamConverter\ConverterInterface
{
private $dm;
private $options;
public function __construct(Doctrine\ODM\MongoDB\DocumentManager $dm)
{
$this->dm = $dm;
$this->options = array();
}
function setOption($key, $option)
{
$this->options[$key] = $option;
}
public function convert($value)
{
return $this->dm->getRepository($this->options['class'])->find($value);
}
}
get_user:
pattern: /users/:id
arguments:
id: { type: doctrine_mongodb_document, class: Bundle\UserBundle\Document\User }
defaults: { _controller: UserBundle:Users:get }
<service id="doctrine.odm.mongodb.parameter_converter.document" class="Symfony\Bundle\DoctrineMongoDBBundle\Converter\DocumentConverter">
<tag name="request.parameter_converter" type="doctrine_mongodb_document" />
<argument type="service" id="doctrine.mongodb.odm.document_manager" />
</service>
class Bundle\UserBundle\Controller\UserController extends BaseController
{
public function getAction(User $user = null)
{
if (null === $user) {
throw new NotFoundHttpException();
}
// some user processing or rendering...
}
}
@henrikbjorn
Copy link

I think all this can be solved if we add options to a single route that we merge into the request defaults in a _route_options key. That we can take and call setOptions on a converter?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment