SalvageableService.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace Wikimedia\Services;
  3. /**
  4. * Interface for salvageable services.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. * http://www.gnu.org/copyleft/gpl.html
  20. *
  21. * @file
  22. *
  23. * @since 1.28
  24. */
  25. /**
  26. * SalvageableService defines an interface for services that are able to salvage state from a
  27. * previous instance of the same class. The intent is to allow new service instances to re-use
  28. * resources that would be expensive to re-create, such as cached data or network connections.
  29. *
  30. * @note There is no expectation that services will be destroyed when the process (or web request)
  31. * terminates.
  32. */
  33. interface SalvageableService {
  34. /**
  35. * Re-uses state from $other. $other must not be used after being passed to salvage(),
  36. * and should be considered to be destroyed.
  37. *
  38. * @note Implementations are responsible for determining what parts of $other can be re-used
  39. * safely. In particular, implementations should check that the relevant configuration of
  40. * $other is the same as in $this before re-using resources from $other.
  41. *
  42. * @note Implementations must take care to detach any re-used resources from the original
  43. * service instance. If $other is destroyed later, resources that are now used by the
  44. * new service instance must not be affected.
  45. *
  46. * @note If $other is a DestructibleService, implementations should make sure that $other
  47. * is in destroyed state after salvage finished. This may be done by calling $other->destroy()
  48. * after carefully detaching all relevant resources.
  49. *
  50. * @param SalvageableService $other The object to salvage state from. $other must have the
  51. * exact same type as $this.
  52. */
  53. public function salvage( SalvageableService $other );
  54. }
  55. /**
  56. * Retain the old class name for backwards compatibility.
  57. * @deprecated since 1.33
  58. */
  59. class_alias( SalvageableService::class, 'MediaWiki\Services\SalvageableService' );