Created
December 23, 2010 15:25
-
-
Save avalanche123/753115 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
interface Symfony\Bundle\FrameworkBundle\Request\ParamConverter\ConverterInterface | |
{ | |
function convert($value); | |
function setOption($key, $option); | |
function getOption($key); | |
} |
This file contains hidden or 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
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); | |
} | |
} |
This file contains hidden or 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
get_user: | |
pattern: /users/:id | |
arguments: | |
id: { type: doctrine_mongodb_document, class: Bundle\UserBundle\Document\User } | |
defaults: { _controller: UserBundle:Users:get } |
This file contains hidden or 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
<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> |
This file contains hidden or 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
class Bundle\UserBundle\Controller\UserController extends BaseController | |
{ | |
public function getAction(User $user = null) | |
{ | |
if (null === $user) { | |
throw new NotFoundHttpException(); | |
} | |
// some user processing or rendering... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?