File tree Expand file tree Collapse file tree 3 files changed +88
-1
lines changed
Expand file tree Collapse file tree 3 files changed +88
-1
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Yajra \DataTables \Contracts ;
4+
5+ use Yajra \DataTables \Html \Builder ;
6+
7+ interface DataTableHtmlBuilder
8+ {
9+ /**
10+ * Handle building of dataTables html.
11+ *
12+ * @return \Yajra\DataTables\Html\Builder
13+ * @throws \Exception
14+ */
15+ public function handle ();
16+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Yajra \DataTables \Html ;
4+
5+ use BadMethodCallException ;
6+ use Yajra \DataTables \Contracts \DataTableHtmlBuilder ;
7+
8+ /**
9+ * @mixin Builder
10+ */
11+ abstract class DataTableHtml implements DataTableHtmlBuilder
12+ {
13+ /**
14+ * @var \Yajra\DataTables\Html\Builder
15+ */
16+ protected $ htmlBuilder ;
17+
18+ /**
19+ * @return \Yajra\DataTables\Html\Builder
20+ */
21+ public static function make ()
22+ {
23+ return app (static ::class)->handle ();
24+ }
25+
26+ /**
27+ * @param string $name
28+ * @param mixed $arguments
29+ * @return mixed
30+ * @throws \Exception
31+ */
32+ public function __call ($ name , $ arguments )
33+ {
34+ if (method_exists ($ this ->getHtmlBuilder (), $ name )) {
35+ return $ this ->getHtmlBuilder ()->{$ name }(...$ arguments );
36+ }
37+
38+ throw new BadMethodCallException ("Method {$ name } does not exists " );
39+ }
40+
41+ /**
42+ * @return \Yajra\DataTables\Html\Builder
43+ */
44+ protected function getHtmlBuilder ()
45+ {
46+ if ($ this ->htmlBuilder ) {
47+ return $ this ->htmlBuilder ;
48+ }
49+
50+ return $ this ->htmlBuilder = app (Builder::class);
51+ }
52+
53+ /**
54+ * @param mixed $builder
55+ * @return static
56+ */
57+ public function setHtmlBuilder ($ builder )
58+ {
59+ $ this ->htmlBuilder = $ builder ;
60+
61+ return $ this ;
62+ }
63+ }
Original file line number Diff line number Diff line change @@ -289,7 +289,15 @@ public function html()
289289 */
290290 public function builder ()
291291 {
292- return $ this ->htmlBuilder ?: $ this ->htmlBuilder = app ('datatables.html ' );
292+ if ($ this ->htmlBuilder ) {
293+ return $ this ->htmlBuilder ;
294+ }
295+
296+ if (method_exists ($ this , 'htmlBuilder ' )) {
297+ return $ this ->htmlBuilder = app ()->call ([$ this , 'htmlBuilder ' ]);
298+ }
299+
300+ return $ this ->htmlBuilder = app ('datatables.html ' );
293301 }
294302
295303 /**
You can’t perform that action at this time.
0 commit comments