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