1: <?php
2:
3: /**
4: * This file is part of the Nette Framework (http://nette.org)
5: *
6: * Copyright (c) 2004, 2011 David Grudl (http://davidgrudl.com)
7: *
8: * For the full copyright and license information, please view
9: * the file license.txt that was distributed with this source code.
10: */
11:
12: namespace Nette\DI;
13:
14: use Nette;
15:
16:
17:
18: /**
19: * Basic service builder.
20: *
21: * @author David Grudl
22: */
23: class ServiceBuilder extends Nette\Object implements IServiceBuilder
24: {
25: /** @var string */
26: private $class;
27:
28:
29:
30: public function __construct($class)
31: {
32: $this->class = $class;
33: }
34:
35:
36:
37: public function getClass()
38: {
39: return $this->class;
40: }
41:
42:
43:
44: public function createService(Nette\DI\IContainer $container)
45: {
46: if (!class_exists($this->class)) {
47: throw new Nette\InvalidStateException("Cannot instantiate service, class '$this->class' not found.");
48: }
49: return new $this->class;
50: }
51:
52: }
53: