1: <?php
2:
3: /**
4: * This file is part of the Nette Framework (http://nette.org)
5: *
6: * Copyright (c) 2004 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: * Definition used by ContainerBuilder.
19: *
20: * @author David Grudl
21: */
22: class ServiceDefinition extends Nette\Object
23: {
24: /** @var string class or interface name */
25: public $class;
26:
27: /** @var Statement */
28: public $factory;
29:
30: /** @var Statement[] */
31: public $setup = array();
32:
33: /** @var array */
34: public $parameters = array();
35:
36: /** @var array */
37: public $tags = array();
38:
39: /** @var mixed */
40: public $autowired = TRUE;
41:
42: /** @var bool */
43: public $shared = TRUE;
44:
45: /** @var bool */
46: public $internal = FALSE;
47:
48:
49: public function setClass($class, array $args = array())
50: {
51: $this->class = $class;
52: if ($args) {
53: $this->setFactory($class, $args);
54: }
55: return $this;
56: }
57:
58:
59: public function setFactory($factory, array $args = array())
60: {
61: $this->factory = new Statement($factory, $args);
62: return $this;
63: }
64:
65:
66: public function setArguments(array $args = array())
67: {
68: if ($this->factory) {
69: $this->factory->arguments = $args;
70: } else {
71: $this->setClass($this->class, $args);
72: }
73: return $this;
74: }
75:
76:
77: public function addSetup($target, $args = NULL)
78: {
79: $this->setup[] = new Statement($target, is_array($args) ? $args : array_slice(func_get_args(), 1));
80: return $this;
81: }
82:
83:
84: public function setParameters(array $params)
85: {
86: $this->shared = $this->autowired = FALSE;
87: $this->parameters = $params;
88: return $this;
89: }
90:
91:
92: public function addTag($tag, $attrs = TRUE)
93: {
94: $this->tags[$tag] = $attrs;
95: return $this;
96: }
97:
98:
99: public function setAutowired($on)
100: {
101: $this->autowired = $on;
102: return $this;
103: }
104:
105:
106: public function setShared($on)
107: {
108: $this->shared = (bool) $on;
109: $this->autowired = $this->shared ? $this->autowired : FALSE;
110: return $this;
111: }
112:
113:
114: public function setInternal($on)
115: {
116: $this->internal = (bool) $on;
117: return $this;
118: }
119:
120: }
121: