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