My problem is precisely described in the strategy template article in the Doctrine documentation :
- An object
- A page can have several blocks
- A block can be text, image, form, calendar, ... (strategy)
- The page knows about the blocks it contains, but does not know about their behavior.
- Block Inheritance Impossible
The described solution (strategy template) is similar to what I need (read the article for more information):
Page:
<?php
namespace Page\Entity;
class Page
{
protected $id;
protected $title;
protected $body;
protected $blocks;
}
Block:
<?php
namespace Page\Entity;
class Block
{
protected $id;
protected $page;
protected $strategyClass;
protected $strategyInstance;
}
Strategic Interface:
<?php
namespace Page\BlockStrategy;
interface BlockStrategyInterface
{
public function setView($view);
public function getView();
public function setBlock(Block $block);
public function getBlock();
public function renderFrontend();
public function renderBackend();
}
I can easily imagine what would be my strategy if I displayed a form or calendar; but what if my strategy is to display the contents of another object?
/id , .
entityClass entityId , , postLoad BlockListener.
, ? postLoad.
, , , Block .
, , .
, ... , - ?