Tharos

Entity generator output

Apr 19th, 2011
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.62 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * Test entity
  5.  *
  6.  */
  7. class Test
  8. {
  9.  
  10.     private $id;
  11.  
  12.     private $string;
  13.  
  14.     private $string2;
  15.  
  16.     private $string3;
  17.  
  18.     private $char;
  19.  
  20.     private $int;
  21.  
  22.     private $int2;
  23.  
  24.     private $int3;
  25.  
  26.     private $int4;
  27.  
  28.     private $date;
  29.  
  30.     private $datetime;
  31.  
  32.     private $text;
  33.  
  34.     public function __construct($params)
  35.     {
  36.         $reflection = new ReflectionClass($this);
  37.         foreach ($params as $key => $value) {
  38.             $setter = 'set' . ucfirst($key);
  39.             if ($reflection->hasMethod($setter)) {
  40.                 $this->$setter($value);
  41.             } else {
  42.                 throw new \Exception("Entity class '" . get_class() . "' doesn't have setter '" . $setter . "'");
  43.             }
  44.         }
  45.     }
  46.  
  47.     public function getId()
  48.     {
  49.         return (int) $this->id;
  50.     }
  51.  
  52.     private function setId($value)
  53.     {
  54.         if ($value === null) {
  55.             throw new \Exception('Field \'id\' cannot be null');
  56.         }
  57.         if (is_int($value) !== true) {
  58.             throw new \Exception('Type mismatch in field \'id\'');
  59.         }
  60.         if ($value < 0 or $value > 4294967295) {
  61.             throw new \OutOfBoundsException('Value of field \'id\' is out of range');
  62.         }
  63.         $this->id = $value;
  64.     }
  65.  
  66.     public function getString()
  67.     {
  68.         return (string) $this->string;
  69.     }
  70.  
  71.     public function setString($value)
  72.     {
  73.         if ($value === null) {
  74.             throw new \Exception('Field \'string\' cannot be null');
  75.         }
  76.         if (is_string($value) !== true) {
  77.             throw new \Exception('Type mismatch in field \'string\'');
  78.         }
  79.         if (mb_strlen($value) > 20) {
  80.             throw new \OutOfBoundsException('Value of field \'string\' is out of range');
  81.         }
  82.         $this->string = $value;
  83.     }
  84.  
  85.     public function getString2()
  86.     {
  87.         return (string) $this->string2;
  88.     }
  89.  
  90.     public function setString2($value)
  91.     {
  92.         if ($value === null) {
  93.             $this->string2 = null;
  94.             return;
  95.         }
  96.         if (is_string($value) !== true) {
  97.             throw new \Exception('Type mismatch in field \'string2\'');
  98.         }
  99.         if (mb_strlen($value) > 255) {
  100.             throw new \OutOfBoundsException('Value of field \'string2\' is out of range');
  101.         }
  102.         $this->string2 = $value;
  103.     }
  104.  
  105.     public function getString3()
  106.     {
  107.         return (string) $this->string3;
  108.     }
  109.  
  110.     public function setString3($value)
  111.     {
  112.         if ($value === null) {
  113.             $this->string3 = "hello";
  114.             return;
  115.         }
  116.         if (is_string($value) !== true) {
  117.             throw new \Exception('Type mismatch in field \'string3\'');
  118.         }
  119.         if (mb_strlen($value) > 50) {
  120.             throw new \OutOfBoundsException('Value of field \'string3\' is out of range');
  121.         }
  122.         $this->string3 = $value;
  123.     }
  124.  
  125.     public function getChar()
  126.     {
  127.         return (string) $this->char;
  128.     }
  129.  
  130.     public function setChar($value)
  131.     {
  132.         if ($value === null) {
  133.             $this->char = null;
  134.             return;
  135.         }
  136.         if (is_string($value) !== true) {
  137.             throw new \Exception('Type mismatch in field \'char\'');
  138.         }
  139.         if (mb_strlen($value) !== 3) {
  140.             throw new \OutOfBoundsException('Value of field \'char\' is out of range');
  141.         }
  142.         $this->char = $value;
  143.     }
  144.  
  145.     public function getInt()
  146.     {
  147.         return (int) $this->int;
  148.     }
  149.  
  150.     public function setInt($value)
  151.     {
  152.         if ($value === null) {
  153.             $this->int = null;
  154.             return;
  155.         }
  156.         if (is_int($value) !== true) {
  157.             throw new \Exception('Type mismatch in field \'int\'');
  158.         }
  159.         if ($value < -32768 or $value > 32767) {
  160.             throw new \OutOfBoundsException('Value of field \'int\' is out of range');
  161.         }
  162.         $this->int = $value;
  163.     }
  164.  
  165.     public function getInt2()
  166.     {
  167.         return (int) $this->int2;
  168.     }
  169.  
  170.     public function setInt2($value)
  171.     {
  172.         if ($value === null) {
  173.             $this->int2 = 5;
  174.             return;
  175.         }
  176.         if (is_int($value) !== true) {
  177.             throw new \Exception('Type mismatch in field \'int2\'');
  178.         }
  179.         if ($value < 0 or $value > 65535) {
  180.             throw new \OutOfBoundsException('Value of field \'int2\' is out of range');
  181.         }
  182.         $this->int2 = $value;
  183.     }
  184.  
  185.     public function getInt3()
  186.     {
  187.         return (int) $this->int3;
  188.     }
  189.  
  190.     public function setInt3($value)
  191.     {
  192.         if ($value === null) {
  193.             $this->int3 = 0;
  194.             return;
  195.         }
  196.         if (is_int($value) !== true) {
  197.             throw new \Exception('Type mismatch in field \'int3\'');
  198.         }
  199.         if ($value < 0 or $value > 255) {
  200.             throw new \OutOfBoundsException('Value of field \'int3\' is out of range');
  201.         }
  202.         $this->int3 = $value;
  203.     }
  204.  
  205.     public function getInt4()
  206.     {
  207.         return (int) $this->int4;
  208.     }
  209.  
  210.     public function setInt4($value)
  211.     {
  212.         if ($value === null) {
  213.             throw new \Exception('Field \'int4\' cannot be null');
  214.         }
  215.         if (is_int($value) !== true) {
  216.             throw new \Exception('Type mismatch in field \'int4\'');
  217.         }
  218.         if ($value < -9223372036854775808 or $value > 9223372036854775807) {
  219.             throw new \OutOfBoundsException('Value of field \'int4\' is out of range');
  220.         }
  221.         $this->int4 = $value;
  222.     }
  223.  
  224.     public function getDate()
  225.     {
  226.         return $this->date;
  227.     }
  228.  
  229.     public function setDate($value)
  230.     {
  231.         if ($value === null) {
  232.             $this->date = "2011-04-18";
  233.             return;
  234.         }
  235.         $value = new \DateTime($value); // throws \Exception on type mismatch
  236.         $value = $value->format('Y-m-d');
  237.         $this->date = $value;
  238.     }
  239.  
  240.     public function getDatetime()
  241.     {
  242.         return $this->datetime;
  243.     }
  244.  
  245.     public function setDatetime($value)
  246.     {
  247.         if ($value === null) {
  248.             $this->datetime = null;
  249.             return;
  250.         }
  251.         $value = new \DateTime($value); // throws \Exception on type mismatch
  252.         $value = $value->format('Y-m-d h:i:s');
  253.         $this->datetime = $value;
  254.     }
  255.  
  256.     public function getText()
  257.     {
  258.         return (string) $this->text;
  259.     }
  260.  
  261.     public function setText($value)
  262.     {
  263.         if ($value === null) {
  264.             throw new \Exception('Field \'text\' cannot be null');
  265.         }
  266.         if (is_string($value) !== true) {
  267.             throw new \Exception('Type mismatch in field \'text\'');
  268.         }
  269.         if (mb_strlen($value) > 65535) {
  270.             throw new \OutOfBoundsException('Value of field \'text\' is out of range');
  271.         }
  272.         $this->text = $value;
  273.     }
  274.  
  275. }
Advertisement
Add Comment
Please, Sign In to add comment