1+ <?php
2+
3+ namespace Xaav \QueueBundle \Entity ;
4+
5+ use Doctrine \ORM \EntityManager ;
6+ use Xaav \QueueBundle \Queue \Job \JobInterface ;
7+ use Xaav \QueueBundle \Queue \QueueInterface ;
8+ use Doctrine \ORM \Mapping as ORM ;
9+
10+ /**
11+ * @ORM\Entity()
12+ */
13+ class Queue implements QueueInterface
14+ {
15+ /**
16+ * @ORM\Id
17+ * @ORM\Column(type="integer")
18+ * @ORM\GeneratedValue(strategy="AUTO")
19+ */
20+ protected $ id ;
21+
22+ /**
23+ * @ORM\Column(type="string", unique=true)
24+ */
25+ protected $ name ;
26+
27+ /**
28+ * @ORM\OneToMany(targetEntity="SerializedJob", mappedBy="queue",cascade={"persist", "all"})
29+ */
30+ protected $ serializedJobs ;
31+
32+ /**
33+ * @var EntityManager
34+ */
35+ protected $ entityManager ;
36+
37+ /**
38+ * Constructor
39+ */
40+ public function __construct ()
41+ {
42+ $ this ->serializedJobs = new \Doctrine \Common \Collections \ArrayCollection ();
43+ }
44+
45+ /**
46+ * Get the name of the Queue
47+ */
48+ public function getName ()
49+ {
50+ return $ this ->name ;
51+ }
52+
53+ /**
54+ * Set the name of the Queue
55+ */
56+ public function setName ($ name )
57+ {
58+ $ this ->name = $ name ;
59+ }
60+
61+ /**
62+ * Get id
63+ *
64+ * @return integer $id
65+ */
66+ public function getId ()
67+ {
68+ return $ this ->id ;
69+ }
70+
71+ /**
72+ * Set Entity Manager
73+ */
74+ public function setEntityManager (EntityManager $ entityManager )
75+ {
76+ $ this ->entityManager = $ entityManager ;
77+ }
78+
79+ /**
80+ * {@InheritDoc}
81+ */
82+ public function get ()
83+ {
84+ $ serializedJob = $ this ->serializedJobs ->last ();
85+ if ($ serializedJob ) {
86+ $ this ->entityManager ->remove ($ serializedJob );
87+
88+ return unserialize ($ serializedJob ->getData ());
89+ }
90+ }
91+
92+ /**
93+ * {@InheritDoc}
94+ */
95+ public function add (JobInterface $ job )
96+ {
97+ $ serializedJob = new SerializedJob ();
98+ $ serializedJob ->setData (serialize ($ job ));
99+ $ serializedJob ->setJobQueue ($ this );
100+
101+ $ this ->serializedJobs ->add ($ serializedJob );
102+ }
103+ }
0 commit comments