1
0

defaultvalue.class.php 814 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. namespace Juju\PDO;
  3. class DefaultValue {
  4. private static $defaults = [];
  5. private $name;
  6. private $default;
  7. private function __construct(string $name, string $default){
  8. $this->name = $name;
  9. $this->default = $default;
  10. self::$defaults[$name] = $this;
  11. }
  12. public function __toString(){
  13. return $this->default;
  14. }
  15. public static function named(string $name){
  16. if(!isset(self::$defaults[$name])){
  17. throw new \Exception("DefaultValue {$name} not defined");
  18. }
  19. return self::$defaults[$name];
  20. }
  21. public static function add(string $name, string $default){
  22. if(isset(self::$defaults[$name])){
  23. throw new \Exception("DefaultValue {$name} already defined");
  24. }
  25. return new DefaultValue($name, $default);
  26. }
  27. }
  28. DefaultValue::add('current_timestamp', 'current_timestamp');
  29. ?>