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