Skip to content

Commit

Permalink
do not pull block from main sm
Browse files Browse the repository at this point in the history
  • Loading branch information
hummer2k committed Oct 18, 2015
1 parent 7d9d0e4 commit ce6d402
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
10 changes: 7 additions & 3 deletions src/ConLayout/Block/Factory/BlockFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use ConLayout\Block\BlockInterface;
use ConLayout\Exception\BadMethodCallException;
use ConLayout\Exception\InvalidBlockException;
use ConLayout\Layout\LayoutInterface;
use ConLayout\NamedParametersTrait;
use Zend\EventManager\EventManagerAwareInterface;
Expand Down Expand Up @@ -87,10 +88,13 @@ public function createBlock($blockId, array $specs)
$class = $this->getOption('class', $specs);
if (null !== $this->blockManager && $this->blockManager->has($class)) {
$block = $this->blockManager->get($class);
} elseif ($this->serviceLocator->has($class)) {
$block = $this->serviceLocator->get($class);
} else {
} elseif (class_exists($class)) {
$block = new $class();
} else {
throw new InvalidBlockException(sprintf(
'Block "%s" could not be instantiated. Class does not exist.',
$class
));
}
$block->setVariable(LayoutInterface::BLOCK_ID_VAR, $blockId);
foreach ($this->getOption('options', $specs) as $name => $option) {
Expand Down
13 changes: 13 additions & 0 deletions src/ConLayout/Exception/InvalidBlockException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace ConLayout\Exception;

use RuntimeException;

/**
* @package ConLayout
* @author Cornelius Adams (conlabz GmbH) <cornelius.adams@conlabz.de>
*/
class InvalidBlockException extends RuntimeException implements ExceptionInterface
{
}
19 changes: 5 additions & 14 deletions tests/ConLayoutTest/Block/Factory/BlockFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,23 +166,14 @@ public function testClass()
);
}

/**
* @expectedException \ConLayout\Exception\InvalidBlockException
*/
public function testBlockFromSm()
{
$serviceManager = new ServiceManager();
$block = new ViewModel();
$serviceManager->setService('Test\Block', $block);

$factory = new BlockFactory();
$factory->setServiceLocator($serviceManager);

$specs = [
'class' => 'Test\Block'
];
$this->assertSame(
$block,
$factory->createBlock('test', $specs)
);

$factory->setServiceLocator(new ServiceManager());
$factory->createBlock('test', ['class' => 'NotExists___']);
}

public function testBlockFromBlockManager()
Expand Down

0 comments on commit ce6d402

Please sign in to comment.