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: 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
 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:     public function getEntity()
 88:     {
 89:         return $this->factory ? $this->factory->getEntity() : NULL;
 90:     }
 91: 
 92: 
 93:     /**
 94:      * @return self
 95:      */
 96:     public function setArguments(array $args = array())
 97:     {
 98:         if (!$this->factory) {
 99:             $this->factory = new Statement($this->class);
100:         }
101:         $this->factory->arguments = $args;
102:         return $this;
103:     }
104: 
105: 
106:     /**
107:      * @param  Statement[]
108:      * @return self
109:      */
110:     public function setSetup(array $setup)
111:     {
112:         foreach ($setup as $v) {
113:             if (!$v instanceof Statement) {
114:                 throw new Nette\InvalidArgumentException('Argument must be Nette\DI\Statement[].');
115:             }
116:         }
117:         $this->setup = $setup;
118:         return $this;
119:     }
120: 
121: 
122:     /**
123:      * @return Statement[]
124:      */
125:     public function getSetup()
126:     {
127:         return $this->setup;
128:     }
129: 
130: 
131:     /**
132:      * @return self
133:      */
134:     public function addSetup($entity, array $args = array())
135:     {
136:         $this->setup[] = $entity instanceof Statement ? $entity : new Statement($entity, $args);
137:         return $this;
138:     }
139: 
140: 
141:     /**
142:      * @return self
143:      */
144:     public function setParameters(array $params)
145:     {
146:         $this->parameters = $params;
147:         return $this;
148:     }
149: 
150: 
151:     /**
152:      * @return array
153:      */
154:     public function getParameters()
155:     {
156:         return $this->parameters;
157:     }
158: 
159: 
160:     /**
161:      * @return self
162:      */
163:     public function setTags(array $tags)
164:     {
165:         $this->tags = $tags;
166:         return $this;
167:     }
168: 
169: 
170:     /**
171:      * @return array
172:      */
173:     public function getTags()
174:     {
175:         return $this->tags;
176:     }
177: 
178: 
179:     /**
180:      * @return self
181:      */
182:     public function addTag($tag, $attr = TRUE)
183:     {
184:         $this->tags[$tag] = $attr;
185:         return $this;
186:     }
187: 
188: 
189:     /**
190:      * @return mixed
191:      */
192:     public function getTag($tag)
193:     {
194:         return isset($this->tags[$tag]) ? $this->tags[$tag] : NULL;
195:     }
196: 
197: 
198:     /**
199:      * @param  bool
200:      * @return self
201:      */
202:     public function setAutowired($state = TRUE)
203:     {
204:         $this->autowired = (bool) $state;
205:         return $this;
206:     }
207: 
208: 
209:     /**
210:      * @return bool
211:      */
212:     public function isAutowired()
213:     {
214:         return $this->autowired;
215:     }
216: 
217: 
218:     /**
219:      * @param  bool
220:      * @return self
221:      */
222:     public function setDynamic($state = TRUE)
223:     {
224:         $this->dynamic = (bool) $state;
225:         return $this;
226:     }
227: 
228: 
229:     /**
230:      * @return bool
231:      */
232:     public function isDynamic()
233:     {
234:         return $this->dynamic;
235:     }
236: 
237: 
238:     /**
239:      * @param  string
240:      * @return self
241:      */
242:     public function setImplement($interface)
243:     {
244:         $this->implement = ltrim($interface, '\\');
245:         return $this;
246:     }
247: 
248: 
249:     /**
250:      * @return string
251:      */
252:     public function getImplement()
253:     {
254:         return $this->implement;
255:     }
256: 
257: 
258:     /**
259:      * @param  string
260:      * @return self
261:      */
262:     public function setImplementType($type)
263:     {
264:         if (!in_array($type, array('get', 'create'), TRUE)) {
265:             throw new Nette\InvalidArgumentException('Argument must be get|create.');
266:         }
267:         $this->implementType = $type;
268:         return $this;
269:     }
270: 
271: 
272:     /**
273:      * @return string
274:      */
275:     public function getImplementType()
276:     {
277:         return $this->implementType;
278:     }
279: 
280: 
281:     /** @deprecated */
282:     public function setShared($on)
283:     {
284:         trigger_error(__METHOD__ . '() is deprecated.', E_USER_DEPRECATED);
285:         $this->autowired = $on ? $this->autowired : FALSE;
286:         return $this;
287:     }
288: 
289: 
290:     /** @deprecated */
291:     public function isShared()
292:     {
293:         trigger_error(__METHOD__ . '() is deprecated.', E_USER_DEPRECATED);
294:     }
295: 
296: 
297:     /** @return self */
298:     public function setInject($state = TRUE)
299:     {
300:         //trigger_error(__METHOD__ . '() is deprecated.', E_USER_DEPRECATED);
301:         return $this->addTag(Extensions\InjectExtension::TAG_INJECT, $state);
302:     }
303: 
304: 
305:     /** @return self */
306:     public function getInject()
307:     {
308:         //trigger_error(__METHOD__ . '() is deprecated.', E_USER_DEPRECATED);
309:         return $this->getTag(Extensions\InjectExtension::TAG_INJECT);
310:     }
311: 
312: }
313: 
Nette 2.3.4 API API documentation generated by ApiGen 2.8.0