[ Index ]

PHP Cross Reference of phpBB-3.1.12-deutsch

title

Body

[close]

/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/ -> Definition.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of the Symfony package.
   5   *
   6   * (c) Fabien Potencier <fabien@symfony.com>
   7   *
   8   * For the full copyright and license information, please view the LICENSE
   9   * file that was distributed with this source code.
  10   */
  11  
  12  namespace Symfony\Component\DependencyInjection;
  13  
  14  use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
  15  use Symfony\Component\DependencyInjection\Exception\OutOfBoundsException;
  16  
  17  /**
  18   * Definition represents a service definition.
  19   *
  20   * @author Fabien Potencier <fabien@symfony.com>
  21   */
  22  class Definition
  23  {
  24      private $class;
  25      private $file;
  26      private $factoryClass;
  27      private $factoryMethod;
  28      private $factoryService;
  29      private $scope;
  30      private $properties;
  31      private $calls;
  32      private $configurator;
  33      private $tags;
  34      private $public;
  35      private $synthetic;
  36      private $abstract;
  37      private $synchronized;
  38      private $lazy;
  39  
  40      protected $arguments;
  41  
  42      /**
  43       * @param string $class     The service class
  44       * @param array  $arguments An array of arguments to pass to the service constructor
  45       */
  46      public function __construct($class = null, array $arguments = array())
  47      {
  48          $this->class = $class;
  49          $this->arguments = $arguments;
  50          $this->calls = array();
  51          $this->scope = ContainerInterface::SCOPE_CONTAINER;
  52          $this->tags = array();
  53          $this->public = true;
  54          $this->synthetic = false;
  55          $this->synchronized = false;
  56          $this->lazy = false;
  57          $this->abstract = false;
  58          $this->properties = array();
  59      }
  60  
  61      /**
  62       * Sets the name of the class that acts as a factory using the factory method,
  63       * which will be invoked statically.
  64       *
  65       * @param string $factoryClass The factory class name
  66       *
  67       * @return Definition The current instance
  68       */
  69      public function setFactoryClass($factoryClass)
  70      {
  71          $this->factoryClass = $factoryClass;
  72  
  73          return $this;
  74      }
  75  
  76      /**
  77       * Gets the factory class.
  78       *
  79       * @return string The factory class name
  80       */
  81      public function getFactoryClass()
  82      {
  83          return $this->factoryClass;
  84      }
  85  
  86      /**
  87       * Sets the factory method able to create an instance of this class.
  88       *
  89       * @param string $factoryMethod The factory method name
  90       *
  91       * @return Definition The current instance
  92       */
  93      public function setFactoryMethod($factoryMethod)
  94      {
  95          $this->factoryMethod = $factoryMethod;
  96  
  97          return $this;
  98      }
  99  
 100      /**
 101       * Gets the factory method.
 102       *
 103       * @return string The factory method name
 104       */
 105      public function getFactoryMethod()
 106      {
 107          return $this->factoryMethod;
 108      }
 109  
 110      /**
 111       * Sets the name of the service that acts as a factory using the factory method.
 112       *
 113       * @param string $factoryService The factory service id
 114       *
 115       * @return Definition The current instance
 116       */
 117      public function setFactoryService($factoryService)
 118      {
 119          $this->factoryService = $factoryService;
 120  
 121          return $this;
 122      }
 123  
 124      /**
 125       * Gets the factory service id.
 126       *
 127       * @return string The factory service id
 128       */
 129      public function getFactoryService()
 130      {
 131          return $this->factoryService;
 132      }
 133  
 134      /**
 135       * Sets the service class.
 136       *
 137       * @param string $class The service class
 138       *
 139       * @return Definition The current instance
 140       */
 141      public function setClass($class)
 142      {
 143          $this->class = $class;
 144  
 145          return $this;
 146      }
 147  
 148      /**
 149       * Gets the service class.
 150       *
 151       * @return string The service class
 152       */
 153      public function getClass()
 154      {
 155          return $this->class;
 156      }
 157  
 158      /**
 159       * Sets the arguments to pass to the service constructor/factory method.
 160       *
 161       * @param array $arguments An array of arguments
 162       *
 163       * @return Definition The current instance
 164       */
 165      public function setArguments(array $arguments)
 166      {
 167          $this->arguments = $arguments;
 168  
 169          return $this;
 170      }
 171  
 172      public function setProperties(array $properties)
 173      {
 174          $this->properties = $properties;
 175  
 176          return $this;
 177      }
 178  
 179      public function getProperties()
 180      {
 181          return $this->properties;
 182      }
 183  
 184      public function setProperty($name, $value)
 185      {
 186          $this->properties[$name] = $value;
 187  
 188          return $this;
 189      }
 190  
 191      /**
 192       * Adds an argument to pass to the service constructor/factory method.
 193       *
 194       * @param mixed $argument An argument
 195       *
 196       * @return Definition The current instance
 197       */
 198      public function addArgument($argument)
 199      {
 200          $this->arguments[] = $argument;
 201  
 202          return $this;
 203      }
 204  
 205      /**
 206       * Sets a specific argument.
 207       *
 208       * @param int   $index
 209       * @param mixed $argument
 210       *
 211       * @return Definition The current instance
 212       *
 213       * @throws OutOfBoundsException When the replaced argument does not exist
 214       */
 215      public function replaceArgument($index, $argument)
 216      {
 217          if ($index < 0 || $index > count($this->arguments) - 1) {
 218              throw new OutOfBoundsException(sprintf('The index "%d" is not in the range [0, %d].', $index, count($this->arguments) - 1));
 219          }
 220  
 221          $this->arguments[$index] = $argument;
 222  
 223          return $this;
 224      }
 225  
 226      /**
 227       * Gets the arguments to pass to the service constructor/factory method.
 228       *
 229       * @return array The array of arguments
 230       */
 231      public function getArguments()
 232      {
 233          return $this->arguments;
 234      }
 235  
 236      /**
 237       * Gets an argument to pass to the service constructor/factory method.
 238       *
 239       * @param int $index
 240       *
 241       * @return mixed The argument value
 242       *
 243       * @throws OutOfBoundsException When the argument does not exist
 244       */
 245      public function getArgument($index)
 246      {
 247          if ($index < 0 || $index > count($this->arguments) - 1) {
 248              throw new OutOfBoundsException(sprintf('The index "%d" is not in the range [0, %d].', $index, count($this->arguments) - 1));
 249          }
 250  
 251          return $this->arguments[$index];
 252      }
 253  
 254      /**
 255       * Sets the methods to call after service initialization.
 256       *
 257       * @param array $calls An array of method calls
 258       *
 259       * @return Definition The current instance
 260       */
 261      public function setMethodCalls(array $calls = array())
 262      {
 263          $this->calls = array();
 264          foreach ($calls as $call) {
 265              $this->addMethodCall($call[0], $call[1]);
 266          }
 267  
 268          return $this;
 269      }
 270  
 271      /**
 272       * Adds a method to call after service initialization.
 273       *
 274       * @param string $method    The method name to call
 275       * @param array  $arguments An array of arguments to pass to the method call
 276       *
 277       * @return Definition The current instance
 278       *
 279       * @throws InvalidArgumentException on empty $method param
 280       */
 281      public function addMethodCall($method, array $arguments = array())
 282      {
 283          if (empty($method)) {
 284              throw new InvalidArgumentException(sprintf('Method name cannot be empty.'));
 285          }
 286          $this->calls[] = array($method, $arguments);
 287  
 288          return $this;
 289      }
 290  
 291      /**
 292       * Removes a method to call after service initialization.
 293       *
 294       * @param string $method The method name to remove
 295       *
 296       * @return Definition The current instance
 297       */
 298      public function removeMethodCall($method)
 299      {
 300          foreach ($this->calls as $i => $call) {
 301              if ($call[0] === $method) {
 302                  unset($this->calls[$i]);
 303                  break;
 304              }
 305          }
 306  
 307          return $this;
 308      }
 309  
 310      /**
 311       * Check if the current definition has a given method to call after service initialization.
 312       *
 313       * @param string $method The method name to search for
 314       *
 315       * @return bool
 316       */
 317      public function hasMethodCall($method)
 318      {
 319          foreach ($this->calls as $call) {
 320              if ($call[0] === $method) {
 321                  return true;
 322              }
 323          }
 324  
 325          return false;
 326      }
 327  
 328      /**
 329       * Gets the methods to call after service initialization.
 330       *
 331       * @return array An array of method calls
 332       */
 333      public function getMethodCalls()
 334      {
 335          return $this->calls;
 336      }
 337  
 338      /**
 339       * Sets tags for this definition.
 340       *
 341       * @param array $tags
 342       *
 343       * @return Definition the current instance
 344       */
 345      public function setTags(array $tags)
 346      {
 347          $this->tags = $tags;
 348  
 349          return $this;
 350      }
 351  
 352      /**
 353       * Returns all tags.
 354       *
 355       * @return array An array of tags
 356       */
 357      public function getTags()
 358      {
 359          return $this->tags;
 360      }
 361  
 362      /**
 363       * Gets a tag by name.
 364       *
 365       * @param string $name The tag name
 366       *
 367       * @return array An array of attributes
 368       */
 369      public function getTag($name)
 370      {
 371          return isset($this->tags[$name]) ? $this->tags[$name] : array();
 372      }
 373  
 374      /**
 375       * Adds a tag for this definition.
 376       *
 377       * @param string $name       The tag name
 378       * @param array  $attributes An array of attributes
 379       *
 380       * @return Definition The current instance
 381       */
 382      public function addTag($name, array $attributes = array())
 383      {
 384          $this->tags[$name][] = $attributes;
 385  
 386          return $this;
 387      }
 388  
 389      /**
 390       * Whether this definition has a tag with the given name.
 391       *
 392       * @param string $name
 393       *
 394       * @return bool
 395       */
 396      public function hasTag($name)
 397      {
 398          return isset($this->tags[$name]);
 399      }
 400  
 401      /**
 402       * Clears all tags for a given name.
 403       *
 404       * @param string $name The tag name
 405       *
 406       * @return Definition
 407       */
 408      public function clearTag($name)
 409      {
 410          unset($this->tags[$name]);
 411  
 412          return $this;
 413      }
 414  
 415      /**
 416       * Clears the tags for this definition.
 417       *
 418       * @return Definition The current instance
 419       */
 420      public function clearTags()
 421      {
 422          $this->tags = array();
 423  
 424          return $this;
 425      }
 426  
 427      /**
 428       * Sets a file to require before creating the service.
 429       *
 430       * @param string $file A full pathname to include
 431       *
 432       * @return Definition The current instance
 433       */
 434      public function setFile($file)
 435      {
 436          $this->file = $file;
 437  
 438          return $this;
 439      }
 440  
 441      /**
 442       * Gets the file to require before creating the service.
 443       *
 444       * @return string The full pathname to include
 445       */
 446      public function getFile()
 447      {
 448          return $this->file;
 449      }
 450  
 451      /**
 452       * Sets the scope of the service.
 453       *
 454       * @param string $scope Whether the service must be shared or not
 455       *
 456       * @return Definition The current instance
 457       */
 458      public function setScope($scope)
 459      {
 460          $this->scope = $scope;
 461  
 462          return $this;
 463      }
 464  
 465      /**
 466       * Returns the scope of the service.
 467       *
 468       * @return string
 469       */
 470      public function getScope()
 471      {
 472          return $this->scope;
 473      }
 474  
 475      /**
 476       * Sets the visibility of this service.
 477       *
 478       * @param bool $boolean
 479       *
 480       * @return Definition The current instance
 481       */
 482      public function setPublic($boolean)
 483      {
 484          $this->public = (bool) $boolean;
 485  
 486          return $this;
 487      }
 488  
 489      /**
 490       * Whether this service is public facing.
 491       *
 492       * @return bool
 493       */
 494      public function isPublic()
 495      {
 496          return $this->public;
 497      }
 498  
 499      /**
 500       * Sets the synchronized flag of this service.
 501       *
 502       * @param bool $boolean
 503       *
 504       * @return Definition The current instance
 505       */
 506      public function setSynchronized($boolean)
 507      {
 508          $this->synchronized = (bool) $boolean;
 509  
 510          return $this;
 511      }
 512  
 513      /**
 514       * Whether this service is synchronized.
 515       *
 516       * @return bool
 517       */
 518      public function isSynchronized()
 519      {
 520          return $this->synchronized;
 521      }
 522  
 523      /**
 524       * Sets the lazy flag of this service.
 525       *
 526       * @param bool $lazy
 527       *
 528       * @return Definition The current instance
 529       */
 530      public function setLazy($lazy)
 531      {
 532          $this->lazy = (bool) $lazy;
 533  
 534          return $this;
 535      }
 536  
 537      /**
 538       * Whether this service is lazy.
 539       *
 540       * @return bool
 541       */
 542      public function isLazy()
 543      {
 544          return $this->lazy;
 545      }
 546  
 547      /**
 548       * Sets whether this definition is synthetic, that is not constructed by the
 549       * container, but dynamically injected.
 550       *
 551       * @param bool $boolean
 552       *
 553       * @return Definition the current instance
 554       */
 555      public function setSynthetic($boolean)
 556      {
 557          $this->synthetic = (bool) $boolean;
 558  
 559          return $this;
 560      }
 561  
 562      /**
 563       * Whether this definition is synthetic, that is not constructed by the
 564       * container, but dynamically injected.
 565       *
 566       * @return bool
 567       */
 568      public function isSynthetic()
 569      {
 570          return $this->synthetic;
 571      }
 572  
 573      /**
 574       * Whether this definition is abstract, that means it merely serves as a
 575       * template for other definitions.
 576       *
 577       * @param bool $boolean
 578       *
 579       * @return Definition the current instance
 580       */
 581      public function setAbstract($boolean)
 582      {
 583          $this->abstract = (bool) $boolean;
 584  
 585          return $this;
 586      }
 587  
 588      /**
 589       * Whether this definition is abstract, that means it merely serves as a
 590       * template for other definitions.
 591       *
 592       * @return bool
 593       */
 594      public function isAbstract()
 595      {
 596          return $this->abstract;
 597      }
 598  
 599      /**
 600       * Sets a configurator to call after the service is fully initialized.
 601       *
 602       * @param callable $callable A PHP callable
 603       *
 604       * @return Definition The current instance
 605       */
 606      public function setConfigurator($callable)
 607      {
 608          $this->configurator = $callable;
 609  
 610          return $this;
 611      }
 612  
 613      /**
 614       * Gets the configurator to call after the service is fully initialized.
 615       *
 616       * @return callable The PHP callable to call
 617       */
 618      public function getConfigurator()
 619      {
 620          return $this->configurator;
 621      }
 622  }


Generated: Thu Jan 11 00:25:41 2018 Cross-referenced by PHPXref 0.7.1