-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSelect2SelectooWithCollectorFactory.php
54 lines (39 loc) · 1.1 KB
/
Select2SelectooWithCollectorFactory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
namespace Dakujem\Selectoo\Examples;
use Dakujem\Selectoo\ScriptEngineInterface,
Dakujem\Selectoo\Select2Engine,
Dakujem\Selectoo\Selectoo;
/**
* Example Selectoo factory - all the scripts generated by engines are collected for later use.
*
*
* @author Andrej Rypák <xrypak@gmail.com> [dakujem](https://github.com/dakujem)
*/
class Dkj_Select2SelectooWithCollectorFactory
{
/**
* @var Dkj_UiScriptManager
*/
private $collector;
public function __construct(Dkj_UiScriptManager $uiScriptManager)
{
$this->collector = $uiScriptManager;
}
public function create($label = null, $items = null, $multiChoice = false, $engine = true)
{
$i = new Selectoo($label, $items, $multiChoice);
if ($engine === true) {
$engine = new Select2Engine();
}
if ($engine instanceof ScriptEngineInterface) {
$i->setEngine($engine);
$i->setScriptManagement(function($script) {
// collect the script
$this->collector->addScript($script);
// return null to indicate the Selectoo instance that it should not manage the script by itself
return null;
});
}
return $i;
}
}