/**
  * @param Block $block
  * @return BlockController
  */
 public function createController(Block $block)
 {
     $componentClass = $block->getComponentClass();
     $configuration = $this->getConfiguration($componentClass);
     $reflection = new \ReflectionClass($configuration->getControllerClass());
     $controller = $reflection->newInstance($block, $configuration);
     $controller->setContainer($this->container);
     return $controller;
 }
Exemple #2
0
 /**
  * Creates new instance based on the discriminator of the base entity.
  *
  * @param Localization $base
  * @return Block
  */
 public static function factory(Localization $base, Block $source = null)
 {
     $block = null;
     switch ($base::DISCRIMINATOR) {
         case self::TEMPLATE_DISCR:
             $block = new TemplateBlock();
             break;
         case self::PAGE_DISCR:
         case self::APPLICATION_DISCR:
             $block = new PageBlock();
             break;
         default:
             throw new \LogicException("Not recognized discriminator value for entity [{$base}].");
     }
     if ($source !== null) {
         $block->setComponentClass($source->getComponentClass());
         $block->setPosition($source->getPosition());
         foreach ($source->getBlockProperties() as $blockProperty) {
             /* @var $blockProperty BlockProperty */
             $newBlockProperty = clone $blockProperty;
             $newBlockProperty->setLocalization($base);
             $newBlockProperty->setBlock($block);
             $block->getBlockProperties()->add($newBlockProperty);
         }
     }
     return $block;
 }