Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

Definition.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 14.44 KiB


 001  <?php
 002   
 003  /*
 004   * This file is part of the Symfony package.
 005   *
 006   * (c) Fabien Potencier <fabien@symfony.com>
 007   *
 008   * For the full copyright and license information, please view the LICENSE
 009   * file that was distributed with this source code.
 010   */
 011   
 012  namespace Symfony\Component\DependencyInjection;
 013   
 014  use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
 015  use Symfony\Component\DependencyInjection\Exception\OutOfBoundsException;
 016   
 017  /**
 018   * Definition represents a service definition.
 019   *
 020   * @author Fabien Potencier <fabien@symfony.com>
 021   *
 022   * @api
 023   */
 024  class Definition
 025  {
 026      private $class;
 027      private $file;
 028      private $factoryClass;
 029      private $factoryMethod;
 030      private $factoryService;
 031      private $scope;
 032      private $properties;
 033      private $calls;
 034      private $configurator;
 035      private $tags;
 036      private $public;
 037      private $synthetic;
 038      private $abstract;
 039      private $synchronized;
 040      private $lazy;
 041   
 042      protected $arguments;
 043   
 044      /**
 045       * Constructor.
 046       *
 047       * @param string $class     The service class
 048       * @param array  $arguments An array of arguments to pass to the service constructor
 049       *
 050       * @api
 051       */
 052      public function __construct($class = null, array $arguments = array())
 053      {
 054          $this->class = $class;
 055          $this->arguments = $arguments;
 056          $this->calls = array();
 057          $this->scope = ContainerInterface::SCOPE_CONTAINER;
 058          $this->tags = array();
 059          $this->public = true;
 060          $this->synthetic = false;
 061          $this->synchronized = false;
 062          $this->lazy = false;
 063          $this->abstract = false;
 064          $this->properties = array();
 065      }
 066   
 067      /**
 068       * Sets the name of the class that acts as a factory using the factory method,
 069       * which will be invoked statically.
 070       *
 071       * @param string $factoryClass The factory class name
 072       *
 073       * @return Definition The current instance
 074       *
 075       * @api
 076       */
 077      public function setFactoryClass($factoryClass)
 078      {
 079          $this->factoryClass = $factoryClass;
 080   
 081          return $this;
 082      }
 083   
 084      /**
 085       * Gets the factory class.
 086       *
 087       * @return string The factory class name
 088       *
 089       * @api
 090       */
 091      public function getFactoryClass()
 092      {
 093          return $this->factoryClass;
 094      }
 095   
 096      /**
 097       * Sets the factory method able to create an instance of this class.
 098       *
 099       * @param string $factoryMethod The factory method name
 100       *
 101       * @return Definition The current instance
 102       *
 103       * @api
 104       */
 105      public function setFactoryMethod($factoryMethod)
 106      {
 107          $this->factoryMethod = $factoryMethod;
 108   
 109          return $this;
 110      }
 111   
 112      /**
 113       * Gets the factory method.
 114       *
 115       * @return string The factory method name
 116       *
 117       * @api
 118       */
 119      public function getFactoryMethod()
 120      {
 121          return $this->factoryMethod;
 122      }
 123   
 124      /**
 125       * Sets the name of the service that acts as a factory using the factory method.
 126       *
 127       * @param string $factoryService The factory service id
 128       *
 129       * @return Definition The current instance
 130       *
 131       * @api
 132       */
 133      public function setFactoryService($factoryService)
 134      {
 135          $this->factoryService = $factoryService;
 136   
 137          return $this;
 138      }
 139   
 140      /**
 141       * Gets the factory service id.
 142       *
 143       * @return string The factory service id
 144       *
 145       * @api
 146       */
 147      public function getFactoryService()
 148      {
 149          return $this->factoryService;
 150      }
 151   
 152      /**
 153       * Sets the service class.
 154       *
 155       * @param string $class The service class
 156       *
 157       * @return Definition The current instance
 158       *
 159       * @api
 160       */
 161      public function setClass($class)
 162      {
 163          $this->class = $class;
 164   
 165          return $this;
 166      }
 167   
 168      /**
 169       * Gets the service class.
 170       *
 171       * @return string The service class
 172       *
 173       * @api
 174       */
 175      public function getClass()
 176      {
 177          return $this->class;
 178      }
 179   
 180      /**
 181       * Sets the arguments to pass to the service constructor/factory method.
 182       *
 183       * @param array $arguments An array of arguments
 184       *
 185       * @return Definition The current instance
 186       *
 187       * @api
 188       */
 189      public function setArguments(array $arguments)
 190      {
 191          $this->arguments = $arguments;
 192   
 193          return $this;
 194      }
 195   
 196      /**
 197       * @api
 198       */
 199      public function setProperties(array $properties)
 200      {
 201          $this->properties = $properties;
 202   
 203          return $this;
 204      }
 205   
 206      /**
 207       * @api
 208       */
 209      public function getProperties()
 210      {
 211          return $this->properties;
 212      }
 213   
 214      /**
 215       * @api
 216       */
 217      public function setProperty($name, $value)
 218      {
 219          $this->properties[$name] = $value;
 220   
 221          return $this;
 222      }
 223   
 224      /**
 225       * Adds an argument to pass to the service constructor/factory method.
 226       *
 227       * @param mixed $argument An argument
 228       *
 229       * @return Definition The current instance
 230       *
 231       * @api
 232       */
 233      public function addArgument($argument)
 234      {
 235          $this->arguments[] = $argument;
 236   
 237          return $this;
 238      }
 239   
 240      /**
 241       * Sets a specific argument
 242       *
 243       * @param int     $index
 244       * @param mixed   $argument
 245       *
 246       * @return Definition The current instance
 247       *
 248       * @throws OutOfBoundsException When the replaced argument does not exist
 249       *
 250       * @api
 251       */
 252      public function replaceArgument($index, $argument)
 253      {
 254          if ($index < 0 || $index > count($this->arguments) - 1) {
 255              throw new OutOfBoundsException(sprintf('The index "%d" is not in the range [0, %d].', $index, count($this->arguments) - 1));
 256          }
 257   
 258          $this->arguments[$index] = $argument;
 259   
 260          return $this;
 261      }
 262   
 263      /**
 264       * Gets the arguments to pass to the service constructor/factory method.
 265       *
 266       * @return array The array of arguments
 267       *
 268       * @api
 269       */
 270      public function getArguments()
 271      {
 272          return $this->arguments;
 273      }
 274   
 275      /**
 276       * Gets an argument to pass to the service constructor/factory method.
 277       *
 278       * @param int     $index
 279       *
 280       * @return mixed The argument value
 281       *
 282       * @throws OutOfBoundsException When the argument does not exist
 283       *
 284       * @api
 285       */
 286      public function getArgument($index)
 287      {
 288          if ($index < 0 || $index > count($this->arguments) - 1) {
 289              throw new OutOfBoundsException(sprintf('The index "%d" is not in the range [0, %d].', $index, count($this->arguments) - 1));
 290          }
 291   
 292          return $this->arguments[$index];
 293      }
 294   
 295      /**
 296       * Sets the methods to call after service initialization.
 297       *
 298       * @param array $calls An array of method calls
 299       *
 300       * @return Definition The current instance
 301       *
 302       * @api
 303       */
 304      public function setMethodCalls(array $calls = array())
 305      {
 306          $this->calls = array();
 307          foreach ($calls as $call) {
 308              $this->addMethodCall($call[0], $call[1]);
 309          }
 310   
 311          return $this;
 312      }
 313   
 314      /**
 315       * Adds a method to call after service initialization.
 316       *
 317       * @param string $method    The method name to call
 318       * @param array  $arguments An array of arguments to pass to the method call
 319       *
 320       * @return Definition The current instance
 321       *
 322       * @throws InvalidArgumentException on empty $method param
 323       *
 324       * @api
 325       */
 326      public function addMethodCall($method, array $arguments = array())
 327      {
 328          if (empty($method)) {
 329              throw new InvalidArgumentException(sprintf('Method name cannot be empty.'));
 330          }
 331          $this->calls[] = array($method, $arguments);
 332   
 333          return $this;
 334      }
 335   
 336      /**
 337       * Removes a method to call after service initialization.
 338       *
 339       * @param string $method The method name to remove
 340       *
 341       * @return Definition The current instance
 342       *
 343       * @api
 344       */
 345      public function removeMethodCall($method)
 346      {
 347          foreach ($this->calls as $i => $call) {
 348              if ($call[0] === $method) {
 349                  unset($this->calls[$i]);
 350                  break;
 351              }
 352          }
 353   
 354          return $this;
 355      }
 356   
 357      /**
 358       * Check if the current definition has a given method to call after service initialization.
 359       *
 360       * @param string $method The method name to search for
 361       *
 362       * @return bool
 363       *
 364       * @api
 365       */
 366      public function hasMethodCall($method)
 367      {
 368          foreach ($this->calls as $call) {
 369              if ($call[0] === $method) {
 370                  return true;
 371              }
 372          }
 373   
 374          return false;
 375      }
 376   
 377      /**
 378       * Gets the methods to call after service initialization.
 379       *
 380       * @return array An array of method calls
 381       *
 382       * @api
 383       */
 384      public function getMethodCalls()
 385      {
 386          return $this->calls;
 387      }
 388   
 389      /**
 390       * Sets tags for this definition
 391       *
 392       * @param array $tags
 393       *
 394       * @return Definition the current instance
 395       *
 396       * @api
 397       */
 398      public function setTags(array $tags)
 399      {
 400          $this->tags = $tags;
 401   
 402          return $this;
 403      }
 404   
 405      /**
 406       * Returns all tags.
 407       *
 408       * @return array An array of tags
 409       *
 410       * @api
 411       */
 412      public function getTags()
 413      {
 414          return $this->tags;
 415      }
 416   
 417      /**
 418       * Gets a tag by name.
 419       *
 420       * @param string $name The tag name
 421       *
 422       * @return array An array of attributes
 423       *
 424       * @api
 425       */
 426      public function getTag($name)
 427      {
 428          return isset($this->tags[$name]) ? $this->tags[$name] : array();
 429      }
 430   
 431      /**
 432       * Adds a tag for this definition.
 433       *
 434       * @param string $name       The tag name
 435       * @param array  $attributes An array of attributes
 436       *
 437       * @return Definition The current instance
 438       *
 439       * @api
 440       */
 441      public function addTag($name, array $attributes = array())
 442      {
 443          $this->tags[$name][] = $attributes;
 444   
 445          return $this;
 446      }
 447   
 448      /**
 449       * Whether this definition has a tag with the given name
 450       *
 451       * @param string $name
 452       *
 453       * @return bool
 454       *
 455       * @api
 456       */
 457      public function hasTag($name)
 458      {
 459          return isset($this->tags[$name]);
 460      }
 461   
 462      /**
 463       * Clears all tags for a given name.
 464       *
 465       * @param string $name The tag name
 466       *
 467       * @return Definition
 468       */
 469      public function clearTag($name)
 470      {
 471          if (isset($this->tags[$name])) {
 472              unset($this->tags[$name]);
 473          }
 474   
 475          return $this;
 476      }
 477   
 478      /**
 479       * Clears the tags for this definition.
 480       *
 481       * @return Definition The current instance
 482       *
 483       * @api
 484       */
 485      public function clearTags()
 486      {
 487          $this->tags = array();
 488   
 489          return $this;
 490      }
 491   
 492      /**
 493       * Sets a file to require before creating the service.
 494       *
 495       * @param string $file A full pathname to include
 496       *
 497       * @return Definition The current instance
 498       *
 499       * @api
 500       */
 501      public function setFile($file)
 502      {
 503          $this->file = $file;
 504   
 505          return $this;
 506      }
 507   
 508      /**
 509       * Gets the file to require before creating the service.
 510       *
 511       * @return string The full pathname to include
 512       *
 513       * @api
 514       */
 515      public function getFile()
 516      {
 517          return $this->file;
 518      }
 519   
 520      /**
 521       * Sets the scope of the service
 522       *
 523       * @param string $scope Whether the service must be shared or not
 524       *
 525       * @return Definition The current instance
 526       *
 527       * @api
 528       */
 529      public function setScope($scope)
 530      {
 531          $this->scope = $scope;
 532   
 533          return $this;
 534      }
 535   
 536      /**
 537       * Returns the scope of the service
 538       *
 539       * @return string
 540       *
 541       * @api
 542       */
 543      public function getScope()
 544      {
 545          return $this->scope;
 546      }
 547   
 548      /**
 549       * Sets the visibility of this service.
 550       *
 551       * @param bool    $boolean
 552       *
 553       * @return Definition The current instance
 554       *
 555       * @api
 556       */
 557      public function setPublic($boolean)
 558      {
 559          $this->public = (bool) $boolean;
 560   
 561          return $this;
 562      }
 563   
 564      /**
 565       * Whether this service is public facing
 566       *
 567       * @return bool
 568       *
 569       * @api
 570       */
 571      public function isPublic()
 572      {
 573          return $this->public;
 574      }
 575   
 576      /**
 577       * Sets the synchronized flag of this service.
 578       *
 579       * @param bool    $boolean
 580       *
 581       * @return Definition The current instance
 582       *
 583       * @api
 584       */
 585      public function setSynchronized($boolean)
 586      {
 587          $this->synchronized = (bool) $boolean;
 588   
 589          return $this;
 590      }
 591   
 592      /**
 593       * Whether this service is synchronized.
 594       *
 595       * @return bool
 596       *
 597       * @api
 598       */
 599      public function isSynchronized()
 600      {
 601          return $this->synchronized;
 602      }
 603   
 604      /**
 605       * Sets the lazy flag of this service.
 606       *
 607       * @param bool    $lazy
 608       *
 609       * @return Definition The current instance
 610       */
 611      public function setLazy($lazy)
 612      {
 613          $this->lazy = (bool) $lazy;
 614   
 615          return $this;
 616      }
 617   
 618      /**
 619       * Whether this service is lazy.
 620       *
 621       * @return bool
 622       */
 623      public function isLazy()
 624      {
 625          return $this->lazy;
 626      }
 627   
 628      /**
 629       * Sets whether this definition is synthetic, that is not constructed by the
 630       * container, but dynamically injected.
 631       *
 632       * @param bool    $boolean
 633       *
 634       * @return Definition the current instance
 635       *
 636       * @api
 637       */
 638      public function setSynthetic($boolean)
 639      {
 640          $this->synthetic = (bool) $boolean;
 641   
 642          return $this;
 643      }
 644   
 645      /**
 646       * Whether this definition is synthetic, that is not constructed by the
 647       * container, but dynamically injected.
 648       *
 649       * @return bool
 650       *
 651       * @api
 652       */
 653      public function isSynthetic()
 654      {
 655          return $this->synthetic;
 656      }
 657   
 658      /**
 659       * Whether this definition is abstract, that means it merely serves as a
 660       * template for other definitions.
 661       *
 662       * @param bool    $boolean
 663       *
 664       * @return Definition the current instance
 665       *
 666       * @api
 667       */
 668      public function setAbstract($boolean)
 669      {
 670          $this->abstract = (bool) $boolean;
 671   
 672          return $this;
 673      }
 674   
 675      /**
 676       * Whether this definition is abstract, that means it merely serves as a
 677       * template for other definitions.
 678       *
 679       * @return bool
 680       *
 681       * @api
 682       */
 683      public function isAbstract()
 684      {
 685          return $this->abstract;
 686      }
 687   
 688      /**
 689       * Sets a configurator to call after the service is fully initialized.
 690       *
 691       * @param callable $callable A PHP callable
 692       *
 693       * @return Definition The current instance
 694       *
 695       * @api
 696       */
 697      public function setConfigurator($callable)
 698      {
 699          $this->configurator = $callable;
 700   
 701          return $this;
 702      }
 703   
 704      /**
 705       * Gets the configurator to call after the service is fully initialized.
 706       *
 707       * @return callable The PHP callable to call
 708       *
 709       * @api
 710       */
 711      public function getConfigurator()
 712      {
 713          return $this->configurator;
 714      }
 715  }
 716