class-field.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO\Admin\ConfigurationUI
  6. */
  7. /**
  8. * Class WPSEO_Config_Field
  9. */
  10. class WPSEO_Config_Field {
  11. /** @var string Field name */
  12. protected $field;
  13. /** @var string Component to use */
  14. protected $component;
  15. /** @var array Properties of this field */
  16. protected $properties = array();
  17. /** @var array Field requirements */
  18. protected $requires = array();
  19. /** @var array|mixed Value of this field */
  20. protected $data = array();
  21. /**
  22. * WPSEO_Config_Field constructor.
  23. *
  24. * @param string $field The field name.
  25. * @param string $component The component to use.
  26. */
  27. public function __construct( $field, $component ) {
  28. $this->field = $field;
  29. $this->component = $component;
  30. }
  31. /**
  32. * Get the identifier
  33. *
  34. * @return string
  35. */
  36. public function get_identifier() {
  37. return $this->field;
  38. }
  39. /**
  40. * Get the component
  41. *
  42. * @return string
  43. */
  44. public function get_component() {
  45. return $this->component;
  46. }
  47. /**
  48. * Set a property value
  49. *
  50. * @param string $name Property to set.
  51. * @param mixed $value Value to apply.
  52. */
  53. public function set_property( $name, $value ) {
  54. $this->properties[ $name ] = $value;
  55. }
  56. /**
  57. * Get all the properties
  58. *
  59. * @return array
  60. */
  61. public function get_properties() {
  62. return $this->properties;
  63. }
  64. /**
  65. * Get the data
  66. *
  67. * @return mixed
  68. */
  69. public function get_data() {
  70. return $this->data;
  71. }
  72. /**
  73. * Array representation of this object.
  74. *
  75. * @return array
  76. */
  77. public function to_array() {
  78. $output = array(
  79. 'componentName' => $this->get_component(),
  80. );
  81. $properties = $this->get_properties();
  82. if ( $properties ) {
  83. $output['properties'] = $properties;
  84. }
  85. $requires = $this->get_requires();
  86. if ( ! empty( $requires ) ) {
  87. $output['requires'] = $requires;
  88. }
  89. return $output;
  90. }
  91. /**
  92. * Set the adapter to use
  93. *
  94. * @param WPSEO_Configuration_Options_Adapter $adapter Adapter to register lookup on.
  95. */
  96. public function set_adapter( WPSEO_Configuration_Options_Adapter $adapter ) {
  97. }
  98. /**
  99. * Requires another field to have a certain value.
  100. *
  101. * @param string $field Field to check for a certain value.
  102. * @param mixed $value Value of the field.
  103. */
  104. public function set_requires( $field, $value ) {
  105. $this->requires = array(
  106. 'field' => $field,
  107. 'value' => $value,
  108. );
  109. }
  110. /**
  111. * Get the required field settings (if present)
  112. *
  113. * @return array
  114. */
  115. public function get_requires() {
  116. return $this->requires;
  117. }
  118. }