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