Нет описания

LinkStub.php 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\VarDumper\Caster;
  11. /**
  12. * Represents a file or a URL.
  13. *
  14. * @author Nicolas Grekas <p@tchwork.com>
  15. */
  16. class LinkStub extends ConstStub
  17. {
  18. public function __construct($label, $line = 0, $href = null)
  19. {
  20. $this->value = $label;
  21. if (null === $href) {
  22. $href = $label;
  23. }
  24. if (is_string($href)) {
  25. if (0 === strpos($href, 'file://')) {
  26. if ($href === $label) {
  27. $label = substr($label, 7);
  28. }
  29. $href = substr($href, 7);
  30. } elseif (false !== strpos($href, '://')) {
  31. $this->attr['href'] = $href;
  32. return;
  33. }
  34. if (file_exists($href)) {
  35. if ($line) {
  36. $this->attr['line'] = $line;
  37. }
  38. $this->attr['file'] = realpath($href) ?: $href;
  39. if ($this->attr['file'] === $label && 3 < count($ellipsis = explode(DIRECTORY_SEPARATOR, $href))) {
  40. $this->attr['ellipsis'] = 2 + strlen(implode(array_slice($ellipsis, -2)));
  41. }
  42. }
  43. }
  44. }
  45. }