|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace eXpansion\Bundle\Acme\Plugins\Gui; |
|
4
|
|
|
|
|
5
|
|
|
use eXpansion\Framework\Core\Model\Gui\ManialinkInterface; |
|
6
|
|
|
use eXpansion\Framework\Core\Model\Gui\Widget; |
|
7
|
|
|
use eXpansion\Framework\Core\Model\Gui\Window; |
|
8
|
|
|
use eXpansion\Framework\Core\Plugins\Gui\WindowFactory as BaseWindowFactory; |
|
9
|
|
|
use eXpansion\Framework\Gui\Components\uiAnimation; |
|
10
|
|
|
use eXpansion\Framework\Gui\Components\uiButton; |
|
11
|
|
|
use eXpansion\Framework\Gui\Components\uiCheckbox; |
|
12
|
|
|
use eXpansion\Framework\Gui\Components\uiDropdown; |
|
13
|
|
|
use eXpansion\Framework\Gui\Components\uiInput; |
|
14
|
|
|
use eXpansion\Framework\Gui\Components\uiLabel; |
|
15
|
|
|
use eXpansion\Framework\Gui\Components\uiTextbox; |
|
16
|
|
|
use eXpansion\Framework\Gui\Components\uiTooltip; |
|
17
|
|
|
use eXpansion\Framework\Gui\Layouts\layoutLine; |
|
18
|
|
|
use eXpansion\Framework\Gui\Layouts\layoutRow; |
|
19
|
|
|
use eXpansion\Framework\Gui\Layouts\layoutScrollable; |
|
20
|
|
|
use FML\Controls\Label; |
|
21
|
|
|
use FML\Controls\Quad; |
|
22
|
|
|
use FML\Script\ScriptLabel; |
|
23
|
|
|
|
|
24
|
|
|
class WindowFactory extends BaseWindowFactory |
|
25
|
|
|
{ |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @param ManialinkInterface|Widget $manialink |
|
29
|
|
|
*/ |
|
30
|
|
|
protected function createContent(ManialinkInterface $manialink) |
|
31
|
|
|
{ |
|
32
|
|
|
parent::createContent($manialink); |
|
33
|
|
|
|
|
34
|
|
|
$lbl = $this->uiFactory->createLabel("update me", uiLabel::TYPE_HEADER, "exp2_text"); |
|
35
|
|
|
$manialink->addChild($lbl); |
|
36
|
|
|
|
|
37
|
|
|
$hash = MemoryWidgetFactory::$exp_hash; |
|
38
|
|
|
// next 2 methods would be generated by script manager |
|
39
|
|
|
$manialink->getFmlManialink()->getScript()->addCustomScriptLabel(ScriptLabel::OnInit, |
|
|
|
|
|
|
40
|
|
|
'declare Text '.$hash.' for LocalUser = ""; |
|
41
|
|
|
declare Text '.$hash.'_check for LocalUser = ""; |
|
42
|
|
|
declare Text '.$hash.'_oldCheck = ""; |
|
43
|
|
|
' |
|
44
|
|
|
); |
|
45
|
|
|
$manialink->getFmlManialink()->getScript()->addCustomScriptLabel(ScriptLabel::Loop, |
|
|
|
|
|
|
46
|
|
|
' |
|
47
|
|
|
if ('.$hash.'_check != '.$hash.'_oldCheck) { |
|
48
|
|
|
---'.$hash.'--- |
|
49
|
|
|
}' |
|
50
|
|
|
); |
|
51
|
|
|
|
|
52
|
|
|
// this is what user needs to do for php part... |
|
53
|
|
|
$manialink->getFmlManialink()->getScript()->addCustomScriptLabel( |
|
|
|
|
|
|
54
|
|
|
$hash, |
|
55
|
|
|
'(Page.GetFirstChild("exp2_text") as CMlLabel).Value ='.$hash.';' |
|
56
|
|
|
); |
|
57
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
} |
|
62
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: