Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

77 Zeilen
2.0KB

  1. <?php
  2. /**
  3. * @link http://www.yiiframework.com/
  4. * @copyright Copyright (c) 2008 Yii Software LLC
  5. * @license http://www.yiiframework.com/license/
  6. */
  7. namespace yii\web;
  8. use yii\base\Object;
  9. /**
  10. * Link represents a link object as defined in [JSON Hypermedia API Language](https://tools.ietf.org/html/draft-kelly-json-hal-03).
  11. *
  12. * @author Qiang Xue <qiang.xue@gmail.com>
  13. * @since 2.0
  14. */
  15. class Link extends Object
  16. {
  17. /**
  18. * The self link.
  19. */
  20. const REL_SELF = 'self';
  21. /**
  22. * @var string a URI [RFC3986](https://tools.ietf.org/html/rfc3986) or
  23. * URI template [RFC6570](https://tools.ietf.org/html/rfc6570). This property is required.
  24. */
  25. public $href;
  26. /**
  27. * @var string a secondary key for selecting Link Objects which share the same relation type
  28. */
  29. public $name;
  30. /**
  31. * @var string a hint to indicate the media type expected when dereferencing the target resource
  32. */
  33. public $type;
  34. /**
  35. * @var boolean a value indicating whether [[href]] refers to a URI or URI template.
  36. */
  37. public $templated = false;
  38. /**
  39. * @var string a URI that hints about the profile of the target resource.
  40. */
  41. public $profile;
  42. /**
  43. * @var string a label describing the link
  44. */
  45. public $title;
  46. /**
  47. * @var string the language of the target resource
  48. */
  49. public $hreflang;
  50. /**
  51. * Serializes a list of links into proper array format.
  52. * @param array $links the links to be serialized
  53. * @return array the proper array representation of the links.
  54. */
  55. public static function serialize(array $links)
  56. {
  57. foreach ($links as $rel => $link) {
  58. if (is_array($link)) {
  59. foreach ($link as $i => $l) {
  60. $link[$i] = $l instanceof self ? array_filter((array) $l) : ['href' => $l];
  61. }
  62. $links[$rel] = $link;
  63. } elseif (!$link instanceof self) {
  64. $links[$rel] = ['href' => $link];
  65. }
  66. }
  67. return $links;
  68. }
  69. }