Stub.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace TYPO3\PharStreamWrapper\Phar;
  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. /**
  13. * @internal Experimental implementation of Phar archive internals
  14. */
  15. class Stub
  16. {
  17. /**
  18. * @param string $content
  19. * @return self
  20. */
  21. public static function fromContent($content)
  22. {
  23. $target = new static();
  24. $target->content = $content;
  25. if (
  26. stripos($content, 'Phar::mapPhar(') !== false
  27. && preg_match('#Phar\:\:mapPhar\(([^)]+)\)#', $content, $matches)
  28. ) {
  29. // remove spaces, single & double quotes
  30. // @todo `'my' . 'alias' . '.phar'` is not evaluated here
  31. $target->mappedAlias = trim($matches[1], ' \'"');
  32. }
  33. return $target;
  34. }
  35. /**
  36. * @var string
  37. */
  38. private $content;
  39. /**
  40. * @var string
  41. */
  42. private $mappedAlias = '';
  43. /**
  44. * @return string
  45. */
  46. public function getContent()
  47. {
  48. return $this->content;
  49. }
  50. /**
  51. * @return string
  52. */
  53. public function getMappedAlias()
  54. {
  55. return $this->mappedAlias;
  56. }
  57. }