4 * This file is part of the Prophecy.
5 * (c) Konstantin Kudryashov <ever.zet@gmail.com>
6 * Marcello Duarte <marcello.duarte@gmail.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Prophecy\Doubler\Generator;
14 use Prophecy\Exception\Doubler\ClassCreatorException;
18 * Creates specific class in current environment.
20 * @author Konstantin Kudryashov <ever.zet@gmail.com>
27 * Initializes creator.
29 * @param ClassCodeGenerator $generator
31 public function __construct(ClassCodeGenerator $generator = null)
33 $this->generator = $generator ?: new ClassCodeGenerator;
39 * @param string $classname
40 * @param Node\ClassNode $class
44 * @throws \Prophecy\Exception\Doubler\ClassCreatorException
46 public function create($classname, Node\ClassNode $class)
48 $code = $this->generator->generate($classname, $class);
49 $return = eval($code);
51 if (!class_exists($classname, false)) {
52 if (count($class->getInterfaces())) {
53 throw new ClassCreatorException(sprintf(
54 'Could not double `%s` and implement interfaces: [%s].',
55 $class->getParentClass(), implode(', ', $class->getInterfaces())
59 throw new ClassCreatorException(
60 sprintf('Could not double `%s`.', $class->getParentClass()),