Manager.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace TYPO3\PharStreamWrapper;
  3. /*
  4. * This file is part of the TYPO3 project.
  5. *
  6. * It is free software; you can redistribute it and/or modify it under the terms
  7. * of the MIT License (MIT). For the full copyright and license information,
  8. * please read the LICENSE file that was distributed with this source code.
  9. *
  10. * The TYPO3 project - inspiring people to share!
  11. */
  12. class Manager implements Assertable
  13. {
  14. /**
  15. * @var self
  16. */
  17. private static $instance;
  18. /**
  19. * @var Behavior
  20. */
  21. private $behavior;
  22. /**
  23. * @param Behavior $behaviour
  24. * @return self
  25. */
  26. public static function initialize(Behavior $behaviour)
  27. {
  28. if (self::$instance === null) {
  29. self::$instance = new self($behaviour);
  30. return self::$instance;
  31. }
  32. throw new \LogicException(
  33. 'Manager can only be initialized once',
  34. 1535189871
  35. );
  36. }
  37. /**
  38. * @return self
  39. */
  40. public static function instance()
  41. {
  42. if (self::$instance !== null) {
  43. return self::$instance;
  44. }
  45. throw new \LogicException(
  46. 'Manager needs to be initialized first',
  47. 1535189872
  48. );
  49. }
  50. /**
  51. * @return bool
  52. */
  53. public static function destroy()
  54. {
  55. if (self::$instance === null) {
  56. return false;
  57. }
  58. self::$instance = null;
  59. return true;
  60. }
  61. /**
  62. * @param Behavior $behaviour
  63. */
  64. private function __construct(Behavior $behaviour)
  65. {
  66. $this->behavior = $behaviour;
  67. }
  68. /**
  69. * @param string $path
  70. * @param string $command
  71. * @return bool
  72. */
  73. public function assert($path, $command)
  74. {
  75. return $this->behavior->assert($path, $command);
  76. }
  77. }