1+ <?php namespace Quince \Pelastic \Api \Document ;
2+
3+ use Quince \Pelastic \Api \Request ;
4+ use Quince \Pelastic \Contracts \Api \Document \Index \IndexRequestInterface ;
5+ use Quince \Pelastic \Contracts \DocumentInterface ;
6+
7+ class IndexRequest extends Request implements IndexRequestInterface {
8+
9+ /**
10+ * Set document to work on
11+ *
12+ * @param DocumentInterface $document
13+ * @param null $id
14+ * @return $this
15+ */
16+ public function setDocument (DocumentInterface $ document , $ id = null )
17+ {
18+ $ this ->setAttribute ('document ' , $ document );
19+
20+ if (null !== $ id ) {
21+ $ this ->setId ($ id );
22+ }elseif (null !== ($ id = $ document ->getId ())) {
23+ $ this ->setId ($ id );
24+ }
25+
26+ return $ this ;
27+ }
28+
29+ /**
30+ * Set id
31+ *
32+ * @param $id
33+ * @return $this
34+ */
35+ public function setId ($ id )
36+ {
37+ $ this ->setAttribute ('id ' , $ id );
38+
39+ return $ this ;
40+ }
41+
42+ /**
43+ * Index to store document on
44+ *
45+ * @param $index
46+ * @return $this
47+ */
48+ public function setIndex ($ index )
49+ {
50+ $ this ->setAttribute ('index ' , (string ) $ index );
51+ }
52+
53+ /**
54+ * Type to set document on
55+ *
56+ * @param $type
57+ * @return $this
58+ */
59+ public function setType ($ type )
60+ {
61+ $ this ->setAttribute ('type ' , (string ) $ type );
62+ }
63+
64+ /**
65+ * Index with all args
66+ *
67+ * @param DocumentInterface $document
68+ * @param $index
69+ * @param null $type
70+ * @param null $id
71+ * @return mixed
72+ */
73+ public function index (DocumentInterface $ document , $ index , $ type = null , $ id = null )
74+ {
75+ $ this ->setIndex ($ index );
76+
77+ if (null !== $ type ) {
78+ $ this ->setType ($ type );
79+ }
80+
81+ $ this ->setDocument ($ document , $ id );
82+
83+ return $ this ;
84+ }
85+
86+ /**
87+ * Get document of the request
88+ *
89+ * @return DocumentInterface
90+ */
91+ public function getDocument ()
92+ {
93+ return $ this ->getAttribute ('document ' , true );
94+ }
95+
96+ /**
97+ * Get id of the document
98+ *
99+ * @return string|integer
100+ */
101+ public function getDocumentId ()
102+ {
103+ return $ this ->getAttribute ('id ' , false , $ this ->getDocument ()->getId ());
104+ }
105+
106+ /**
107+ * Get index that should be used to store documents on.
108+ *
109+ * @return string
110+ */
111+ public function getIndex ()
112+ {
113+ return $ this ->getAttribute ('id ' , true );
114+ }
115+
116+ /**
117+ * Get type that should be used to store documents on.
118+ *
119+ * @return string
120+ */
121+ public function getType ()
122+ {
123+ return $ this ->getAttribute ('type ' , false , null );
124+ }
125+ }
0 commit comments