AbstractPostSerializable.php 560 B

12345678910111213141516
  1. <?php
  2. namespace DNB;
  3. abstract class AbstractPostSerializable implements PostSerializableInterface {
  4. public static function fromPostParams(array $post): PostSerializableInterface {
  5. $vars = [];
  6. foreach (static::getClassVars() as $key)
  7. $vars[$key] = isset($post[$key]) && ((bool)$post[$key]) && strtolower((string)$post[$key]) != "off" ? htmlspecialchars($post[$key], ENT_QUOTES | ENT_SUBSTITUTE) : null;
  8. return new static(...array_values($vars));
  9. }
  10. abstract protected static function getClassVars(): array;
  11. }