base.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. namespace MGModule\DNSManager2\mgLibs\models;
  3. use MGModule\DNSManager2 as main;
  4. /**
  5. * Description of abstractModel
  6. *
  7. * @author Michal Czech <michael@modulesgarden.com>
  8. */
  9. abstract class base {
  10. /**
  11. * Normalized Time Stamp
  12. *
  13. * @author Michal Czech <michael@modulesgarden.com>
  14. * @param string $strTime
  15. * @return string
  16. */
  17. static function timeStamp($strTime = 'now')
  18. {
  19. return date('Y-m-d H:i:s', strtotime($strTime));
  20. }
  21. /**
  22. * Disable Get Function
  23. *
  24. * @author Michal Czech <michael@modulesgarden.com>
  25. * @param string $property
  26. * @throws main\mgLibs\exceptions\system
  27. */
  28. function __get($property) {
  29. throw new main\mgLibs\exceptions\system('Property: '.$property.' does not exits in: '.get_called_class(), main\mgLibs\exceptions\codes::PROPERTY_NOT_EXISTS);
  30. }
  31. /**
  32. * Disable Set Function
  33. *
  34. * @author Michal Czech <michael@modulesgarden.com>
  35. * @param string $property
  36. * @param string $value
  37. * @throws main\mgLibs\exceptions\system
  38. */
  39. function __set($property, $value) {
  40. throw new main\mgLibs\exceptions\system('Property: '.$property.' does not exits in: '.get_called_class(), main\mgLibs\exceptions\codes::PROPERTY_NOT_EXISTS);
  41. }
  42. /**
  43. * Disable Call Function
  44. *
  45. * @author Michal Czech <michael@modulesgarden.com>
  46. * @param string $function
  47. * @param string $params
  48. * @throws main\mgLibs\exceptions\system
  49. */
  50. function __call($function, $params) {
  51. throw new main\mgLibs\exceptions\system('Function: '.$function.' does not exits in: '.get_called_class(), main\mgLibs\exceptions\codes::PROPERTY_NOT_EXISTS);
  52. }
  53. /**
  54. * Cast To array
  55. *
  56. * @param string $container
  57. * @return array
  58. */
  59. function toArray($container = true){
  60. $className = get_called_class();
  61. $fields = get_class_vars($className);
  62. foreach(explode('\\', $className) as $className);
  63. $data = array();
  64. foreach($fields as $name => $defult)
  65. {
  66. if(isset($this->{$name}))
  67. {
  68. $data[$name] = $this->{$name};
  69. }
  70. }
  71. if($container === true)
  72. {
  73. return array(
  74. $className => $data
  75. );
  76. }
  77. elseif($container)
  78. {
  79. return array(
  80. $container => $data
  81. );
  82. }
  83. else
  84. {
  85. return $data;
  86. }
  87. }
  88. /**
  89. * Encrypt String using Hash from configration
  90. *
  91. * @author Michal Czech <michael@modulesgarden.com>
  92. * @param string $input
  93. * @return string
  94. */
  95. function encrypt($input) {
  96. if(empty($input))
  97. {
  98. return false;
  99. }
  100. return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, main\mgLibs\process\mainInstance::I()->getEncryptKey(), $input, MCRYPT_MODE_ECB));
  101. }
  102. /**
  103. * Decrypt String using Hash from configration
  104. *
  105. * @author Michal Czech <michael@modulesgarden.com>
  106. * @param string $input
  107. * @return string
  108. */
  109. function decrypt($input) {
  110. if(empty($input))
  111. {
  112. return false;
  113. }
  114. return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, main\mgLibs\process\mainInstance::I()->getEncryptKey(), base64_decode($input), MCRYPT_MODE_ECB));
  115. }
  116. function serialize($input){
  117. return base64_encode(serialize($input));
  118. }
  119. function unserialize($input){
  120. return unserialize(base64_decode($input));
  121. }
  122. }