
Untitled
By: a guest on
May 8th, 2012 | syntax:
None | size: 0.67 KB | hits: 15 | expires: Never
Strategy pattern in Symfony2
$somePageType = new PageType(...);
$this->get('page.service')->render($somePagetype);
// This is the page.service class
class MyPageService {
public function render(PageTypeInterface $page_type) {
$page_type->setContainer($this->container);
// do stuff
}
}
// This is the type strategy
class MyStrategyType extends ContainerAware implements PageTypeInterface {
// you can access the container after MyPageService has injected it.
}
class MyPageService {
public function render(PageTypeInterface $page_type) {
$page_type->setService($this->container->get('my_service'));
// do stuff
}
}