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