PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/src/PhpWord/Element/Link.php

https://github.com/cyrillkalita/PHPWord
PHP | 139 lines | 44 code | 15 blank | 80 comment | 0 complexity | edd0e4ed19d02bc62886f50e17f25530 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-3.0
  1. <?php
  2. /**
  3. * This file is part of PHPWord - A pure PHP library for reading and writing
  4. * word processing documents.
  5. *
  6. * PHPWord is free software distributed under the terms of the GNU Lesser
  7. * General Public License version 3 as published by the Free Software Foundation.
  8. *
  9. * For the full copyright and license information, please read the LICENSE
  10. * file that was distributed with this source code. For the full list of
  11. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
  12. *
  13. * @link https://github.com/PHPOffice/PHPWord
  14. * @copyright 2010-2014 PHPWord contributors
  15. * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
  16. */
  17. namespace PhpOffice\PhpWord\Element;
  18. use PhpOffice\PhpWord\Shared\String;
  19. use PhpOffice\PhpWord\Style\Font;
  20. use PhpOffice\PhpWord\Style\Paragraph;
  21. /**
  22. * Link element
  23. */
  24. class Link extends AbstractElement
  25. {
  26. /**
  27. * Link target
  28. *
  29. * @var string
  30. */
  31. private $target;
  32. /**
  33. * Link text
  34. *
  35. * @var string
  36. */
  37. private $text;
  38. /**
  39. * Font style
  40. *
  41. * @var string|\PhpOffice\PhpWord\Style\Font
  42. */
  43. private $fontStyle;
  44. /**
  45. * Paragraph style
  46. *
  47. * @var string|\PhpOffice\PhpWord\Style\Paragraph
  48. */
  49. private $paragraphStyle;
  50. /**
  51. * Create a new Link Element
  52. *
  53. * @param string $target
  54. * @param string $text
  55. * @param mixed $fontStyle
  56. * @param mixed $paragraphStyle
  57. */
  58. public function __construct($target, $text = null, $fontStyle = null, $paragraphStyle = null)
  59. {
  60. $this->target = String::toUTF8($target);
  61. $this->text = is_null($text) ? $this->target : String::toUTF8($text);
  62. $this->fontStyle = $this->setStyle(new Font('text'), $fontStyle);
  63. $this->paragraphStyle = $this->setStyle(new Paragraph(), $paragraphStyle);
  64. return $this;
  65. }
  66. /**
  67. * Get link target
  68. *
  69. * @return string
  70. */
  71. public function getTarget()
  72. {
  73. return $this->target;
  74. }
  75. /**
  76. * Get link text
  77. *
  78. * @return string
  79. */
  80. public function getText()
  81. {
  82. return $this->text;
  83. }
  84. /**
  85. * Get Text style
  86. *
  87. * @return string|\PhpOffice\PhpWord\Style\Font
  88. */
  89. public function getFontStyle()
  90. {
  91. return $this->fontStyle;
  92. }
  93. /**
  94. * Get Paragraph style
  95. *
  96. * @return string|\PhpOffice\PhpWord\Style\Paragraph
  97. */
  98. public function getParagraphStyle()
  99. {
  100. return $this->paragraphStyle;
  101. }
  102. /**
  103. * Get Link source
  104. *
  105. * @return string
  106. * @deprecated 0.10.0
  107. * @codeCoverageIgnore
  108. */
  109. public function getLinkSrc()
  110. {
  111. return $this->getTarget();
  112. }
  113. /**
  114. * Get Link name
  115. *
  116. * @return string
  117. * @deprecated 0.10.0
  118. * @codeCoverageIgnore
  119. */
  120. public function getLinkName()
  121. {
  122. return $this->getText();
  123. }
  124. }