Namespaces

  • Latte
    • Loaders
    • Macros
    • Runtime
  • Nette
    • Application
      • Responses
      • Routers
      • UI
    • Bridges
      • ApplicationDI
      • ApplicationLatte
      • ApplicationTracy
      • CacheDI
      • CacheLatte
      • DatabaseDI
      • DatabaseTracy
      • DITracy
      • FormsDI
      • FormsLatte
      • Framework
      • HttpDI
      • HttpTracy
      • MailDI
      • ReflectionDI
      • SecurityDI
      • SecurityTracy
    • Caching
      • Storages
    • ComponentModel
    • Database
      • Conventions
      • Drivers
      • Reflection
      • Table
    • DI
      • Config
        • Adapters
      • Extensions
    • Diagnostics
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Latte
    • Loaders
    • Localization
    • Mail
    • Neon
    • PhpGenerator
    • Reflection
    • Security
    • Templating
    • Utils
  • NetteModule
  • none
  • Tracy
    • Bridges
      • Nette

Classes

  • Compiler
  • CompilerExtension
  • Container
  • ContainerBuilder
  • ContainerFactory
  • ContainerLoader
  • ServiceDefinition
  • Statement

Exceptions

  • MissingServiceException
  • ServiceCreationException
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  1: <?php
  2: 
  3: /**
  4:  * This file is part of the Nette Framework (http://nette.org)
  5:  * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
  6:  */
  7: 
  8: namespace Nette\DI;
  9: 
 10: use Nette;
 11: 
 12: 
 13: /**
 14:  * Definition used by ContainerBuilder.
 15:  *
 16:  * @author     David Grudl
 17:  */
 18: class ServiceDefinition extends Nette\Object
 19: {
 20:     /** @var string|NULL  class or interface name */
 21:     private $class;
 22: 
 23:     /** @var Statement|NULL */
 24:     private $factory;
 25: 
 26:     /** @var Statement[] */
 27:     private $setup = array();
 28: 
 29:     /** @var array */
 30:     public $parameters = array();
 31: 
 32:     /** @var array */
 33:     private $tags = array();
 34: 
 35:     /** @var bool */
 36:     private $autowired = TRUE;
 37: 
 38:     /** @var bool */
 39:     private $dynamic = FALSE;
 40: 
 41:     /** @var string|NULL  interface name */
 42:     private $implement;
 43: 
 44:     /** @var string|NULL  create | get */
 45:     private $implementType;
 46: 
 47: 
 48:     /**
 49:      * @return self
 50:      */
 51:     public function setClass($class, array $args = array())
 52:     {
 53:         $this->class = ltrim($class, '\\');
 54:         if ($args) {
 55:             $this->setFactory($class, $args);
 56:         }
 57:         return $this;
 58:     }
 59: 
 60: 
 61:     /**
 62:      * @return string
 63:      */
 64:     public function getClass()
 65:     {
 66:         return $this->class;
 67:     }
 68: 
 69: 
 70:     /**
 71:      * @return self
 72:      */
 73:     public function setFactory($factory, array $args = array())
 74:     {
 75:         $this->factory = $factory instanceof Statement ? $factory : new Statement($factory, $args);
 76:         return $this;
 77:     }
 78: 
 79: 
 80:     /**
 81:      * @return Statement|NULL
 82:      */
 83:     public function getFactory()
 84:     {
 85:         return $this->factory;
 86:     }
 87: 
 88: 
 89:     public function getEntity()
 90:     {
 91:         return $this->factory ? $this->factory->getEntity() : NULL;
 92:     }
 93: 
 94: 
 95:     /**
 96:      * @return self
 97:      */
 98:     public function setArguments(array $args = array())
 99:     {
100:         if (!$this->factory) {
101:             $this->factory = new Statement($this->class);
102:         }
103:         $this->factory->arguments = $args;
104:         return $this;
105:     }
106: 
107: 
108:     /**
109:      * @param  Statement[]
110:      * @return self
111:      */
112:     public function setSetup(array $setup)
113:     {
114:         foreach ($setup as $v) {
115:             if (!$v instanceof Statement) {
116:                 throw new Nette\InvalidArgumentException('Argument must be Nette\DI\Statement[].');
117:             }
118:         }
119:         $this->setup = $setup;
120:         return $this;
121:     }
122: 
123: 
124:     /**
125:      * @return Statement[]
126:      */
127:     public function getSetup()
128:     {
129:         return $this->setup;
130:     }
131: 
132: 
133:     /**
134:      * @return self
135:      */
136:     public function addSetup($entity, array $args = array())
137:     {
138:         $this->setup[] = $entity instanceof Statement ? $entity : new Statement($entity, $args);
139:         return $this;
140:     }
141: 
142: 
143:     /**
144:      * @return self
145:      */
146:     public function setParameters(array $params)
147:     {
148:         $this->parameters = $params;
149:         return $this;
150:     }
151: 
152: 
153:     /**
154:      * @return array
155:      */
156:     public function getParameters()
157:     {
158:         return $this->parameters;
159:     }
160: 
161: 
162:     /**
163:      * @return self
164:      */
165:     public function setTags(array $tags)
166:     {
167:         $this->tags = $tags;
168:         return $this;
169:     }
170: 
171: 
172:     /**
173:      * @return array
174:      */
175:     public function getTags()
176:     {
177:         return $this->tags;
178:     }
179: 
180: 
181:     /**
182:      * @return self
183:      */
184:     public function addTag($tag, $attr = TRUE)
185:     {
186:         $this->tags[$tag] = $attr;
187:         return $this;
188:     }
189: 
190: 
191:     /**
192:      * @return mixed
193:      */
194:     public function getTag($tag)
195:     {
196:         return isset($this->tags[$tag]) ? $this->tags[$tag] : NULL;
197:     }
198: 
199: 
200:     /**
201:      * @param  bool
202:      * @return self
203:      */
204:     public function setAutowired($state = TRUE)
205:     {
206:         $this->autowired = (bool) $state;
207:         return $this;
208:     }
209: 
210: 
211:     /**
212:      * @return bool
213:      */
214:     public function isAutowired()
215:     {
216:         return $this->autowired;
217:     }
218: 
219: 
220:     /**
221:      * @param  bool
222:      * @return self
223:      */
224:     public function setDynamic($state = TRUE)
225:     {
226:         $this->dynamic = (bool) $state;
227:         return $this;
228:     }
229: 
230: 
231:     /**
232:      * @return bool
233:      */
234:     public function isDynamic()
235:     {
236:         return $this->dynamic;
237:     }
238: 
239: 
240:     /**
241:      * @param  string
242:      * @return self
243:      */
244:     public function setImplement($interface)
245:     {
246:         $this->implement = ltrim($interface, '\\');
247:         return $this;
248:     }
249: 
250: 
251:     /**
252:      * @return string
253:      */
254:     public function getImplement()
255:     {
256:         return $this->implement;
257:     }
258: 
259: 
260:     /**
261:      * @param  string
262:      * @return self
263:      */
264:     public function setImplementType($type)
265:     {
266:         if (!in_array($type, array('get', 'create'), TRUE)) {
267:             throw new Nette\InvalidArgumentException('Argument must be get|create.');
268:         }
269:         $this->implementType = $type;
270:         return $this;
271:     }
272: 
273: 
274:     /**
275:      * @return string
276:      */
277:     public function getImplementType()
278:     {
279:         return $this->implementType;
280:     }
281: 
282: 
283:     /** @deprecated */
284:     public function setShared($on)
285:     {
286:         trigger_error(__METHOD__ . '() is deprecated.', E_USER_DEPRECATED);
287:         $this->autowired = $on ? $this->autowired : FALSE;
288:         return $this;
289:     }
290: 
291: 
292:     /** @deprecated */
293:     public function isShared()
294:     {
295:         trigger_error(__METHOD__ . '() is deprecated.', E_USER_DEPRECATED);
296:     }
297: 
298: 
299:     /** @return self */
300:     public function setInject($state = TRUE)
301:     {
302:         //trigger_error(__METHOD__ . '() is deprecated.', E_USER_DEPRECATED);
303:         return $this->addTag(Extensions\InjectExtension::TAG_INJECT, $state);
304:     }
305: 
306: 
307:     /** @return self */
308:     public function getInject()
309:     {
310:         //trigger_error(__METHOD__ . '() is deprecated.', E_USER_DEPRECATED);
311:         return $this->getTag(Extensions\InjectExtension::TAG_INJECT);
312:     }
313: 
314: }
315: 
Nette 2.3.1 API API documentation generated by ApiGen 2.8.0