AbstractResource.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. *
  4. * Cube Framework $Id$ mY0BQHM1+YtXhLfmkODATOjdl7QwzwWlrsk3nz99dpw=
  5. *
  6. * @link http://codecu.be/framework
  7. * @copyright Copyright (c) 2014 CodeCube SRL
  8. * @license http://codecu.be/framework/license Commercial License
  9. *
  10. * @version 1.0
  11. */
  12. /**
  13. * abstract application resources class
  14. */
  15. namespace Cube\Application\Resource;
  16. abstract class AbstractResource implements ResourceInterface
  17. {
  18. /**
  19. *
  20. * array of settings for a certain resource
  21. *
  22. * @var array
  23. */
  24. protected $_options = array();
  25. /**
  26. *
  27. * get options array
  28. *
  29. * @return array
  30. */
  31. public function getOptions()
  32. {
  33. return $this->_options;
  34. }
  35. /**
  36. *
  37. * set options array
  38. *
  39. * @param array $options
  40. *
  41. * @return $this
  42. */
  43. public function setOptions(array $options)
  44. {
  45. if (is_array($this->_options)) {
  46. $this->_options = array_merge($this->_options, $options);
  47. }
  48. else {
  49. $this->_options = $options;
  50. }
  51. return $this;
  52. }
  53. /**
  54. *
  55. * get a key from the options array
  56. *
  57. * @param string $key
  58. *
  59. * @return mixed|null
  60. */
  61. public function getOption($key)
  62. {
  63. if (isset($this->_options[$key])) {
  64. return $this->_options[$key];
  65. }
  66. return null;
  67. }
  68. /**
  69. *
  70. * set or unset a key in the options array
  71. *
  72. * @param string $key
  73. * @param mixed|null $value
  74. *
  75. * @return $this
  76. */
  77. public function setOption($key, $value = null)
  78. {
  79. if ($value === null && isset($this->_options[$key])) {
  80. unset($this->_options[$key]);
  81. }
  82. else {
  83. $this->_options[$key] = $value;
  84. }
  85. return $this;
  86. }
  87. }