~ubuntu-branches/debian/experimental/php-nette/experimental

« back to all changes in this revision

Viewing changes to Nette-2.1.0RC/Nette/DI/ServiceDefinition.php

  • Committer: Package Import Robot
  • Author(s): David Prévot
  • Date: 2013-11-30 08:47:54 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20131130084754-4udf1xsu9085tnfc
Tags: 2.1.0~rc-1
* New upstream branch
* Update copyright

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 $inject = FALSE;
 
47
 
 
48
        /** @var string  interface name */
 
49
        public $implement;
 
50
 
 
51
 
 
52
        public function setClass($class, array $args = array())
 
53
        {
 
54
                $this->class = $class;
 
55
                if ($args) {
 
56
                        $this->setFactory($class, $args);
 
57
                }
 
58
                return $this;
 
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
        public function setArguments(array $args = array())
 
70
        {
 
71
                if ($this->factory) {
 
72
                        $this->factory->arguments = $args;
 
73
                } else {
 
74
                        $this->setClass($this->class, $args);
 
75
                }
 
76
                return $this;
 
77
        }
 
78
 
 
79
 
 
80
        public function addSetup($target, array $args = array())
 
81
        {
 
82
                $this->setup[] = new Statement($target, $args);
 
83
                return $this;
 
84
        }
 
85
 
 
86
 
 
87
        public function setParameters(array $params)
 
88
        {
 
89
                $this->shared = $this->autowired = FALSE;
 
90
                $this->parameters = $params;
 
91
                return $this;
 
92
        }
 
93
 
 
94
 
 
95
        public function addTag($tag, $attrs = TRUE)
 
96
        {
 
97
                $this->tags[$tag] = $attrs;
 
98
                return $this;
 
99
        }
 
100
 
 
101
 
 
102
        public function setAutowired($on)
 
103
        {
 
104
                $this->autowired = $on;
 
105
                return $this;
 
106
        }
 
107
 
 
108
 
 
109
        public function setShared($on)
 
110
        {
 
111
                $this->shared = (bool) $on;
 
112
                $this->autowired = $this->shared ? $this->autowired : FALSE;
 
113
                return $this;
 
114
        }
 
115
 
 
116
 
 
117
        public function setInject($on)
 
118
        {
 
119
                $this->inject = (bool) $on;
 
120
                return $this;
 
121
        }
 
122
 
 
123
 
 
124
        public function setImplement($implement)
 
125
        {
 
126
                $this->implement = $implement;
 
127
                $this->shared = TRUE;
 
128
                return $this;
 
129
        }
 
130
 
 
131
}