Advertisement
RalfEggert

ToppingEntity class

Dec 13th, 2012
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.83 KB | None | 0 0
  1. /**
  2.  * namespace definition and usage
  3.  */
  4. namespace Pizza\Entity;
  5.  
  6. use Zend\Stdlib\ArraySerializableInterface;
  7.  
  8. /**
  9.  * Topping entity
  10.  *
  11.  * @package    Pizza
  12.  */
  13. class ToppingEntity implements ArraySerializableInterface
  14. {
  15.     protected $id;
  16.     protected $name;
  17.     protected $costs;
  18.    
  19.     /**
  20.      * Set id
  21.      *
  22.      * @param integer $id
  23.      */
  24.     public function setId($id)
  25.     {
  26.         $this->id = $id;
  27.     }
  28.    
  29.     /**
  30.      * Get id
  31.      *
  32.      * @return integer $id
  33.      */
  34.     public function getId()
  35.     {
  36.         return $this->id;
  37.     }
  38.    
  39.     /**
  40.      * Set name
  41.      *
  42.      * @param string $name
  43.      */
  44.     public function setName($name)
  45.     {
  46.         $this->name = $name;
  47.     }
  48.    
  49.     /**
  50.      * Get name
  51.      *
  52.      * @return string $name
  53.      */
  54.     public function getName()
  55.     {
  56.         return $this->name;
  57.     }
  58.    
  59.     /**
  60.      * Set costs
  61.      *
  62.      * @param float $costs
  63.      */
  64.     public function setCosts($costs)
  65.     {
  66.         $this->costs = $costs;
  67.     }
  68.    
  69.     /**
  70.      * Get costs
  71.      *
  72.      * @return float $costs
  73.      */
  74.     public function getCosts()
  75.     {
  76.         return round($this->costs, 2);
  77.     }
  78.    
  79.     /**
  80.      * Exchange internal values from provided array
  81.      *
  82.      * @param  array $array
  83.      * @return void
  84.      */
  85.     public function exchangeArray(array $array)
  86.     {
  87.         $this->setId($array['id']);
  88.         $this->setName($array['name']);
  89.         $this->setCosts($array['costs']);
  90.     }
  91.    
  92.     /**
  93.      * Return an array representation of the object
  94.      *
  95.      * @return array
  96.      */
  97.     public function getArrayCopy()
  98.     {
  99.         return array(
  100.             'id'    => $this->getId(),
  101.             'name'  => $this->getName(),
  102.             'costs' => $this->getCosts(),
  103.         );
  104.     }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement