Market.php 959 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace Doctrine\Tests\Models\StockExchange;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. /**
  5. * @Entity
  6. * @Table(name="exchange_markets")
  7. */
  8. class Market
  9. {
  10. /**
  11. * @Id @Column(type="integer") @GeneratedValue
  12. * @var int
  13. */
  14. private $id;
  15. /**
  16. * @Column(type="string")
  17. * @var string
  18. */
  19. private $name;
  20. /**
  21. * @OneToMany(targetEntity="Stock", mappedBy="market", indexBy="symbol")
  22. * @var Stock[]
  23. */
  24. public $stocks;
  25. public function __construct($name)
  26. {
  27. $this->name = $name;
  28. $this->stocks = new ArrayCollection();
  29. }
  30. public function getId()
  31. {
  32. return $this->id;
  33. }
  34. public function getName()
  35. {
  36. return $this->name;
  37. }
  38. public function addStock(Stock $stock)
  39. {
  40. $this->stocks[$stock->getSymbol()] = $stock;
  41. }
  42. public function getStock($symbol)
  43. {
  44. return $this->stocks[$symbol];
  45. }
  46. }