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
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Loaders
    • Localization
    • Mail
    • Neon
    • PhpGenerator
    • Reflection
    • Security
    • Utils
  • none
  • Tracy
    • Bridges
      • Nette

Classes

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

Exceptions

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