-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New behavior for Plugs in 2.3: they are rendered in their local context.
Possibility to configure the View for legacy plug behavior.
- Loading branch information
Showing
4 changed files
with
211 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
/** | ||
* @author Gabriel Zerbib <gabriel@figdice.org> | ||
* @copyright 2004-2016, Gabriel Zerbib. | ||
* @version 2.3 | ||
* @package FigDice | ||
*/ | ||
namespace figdice\classes; | ||
|
||
class Plug { | ||
/** | ||
* @var ViewElementTag | ||
*/ | ||
private $tag; | ||
/** | ||
* @var string | ||
*/ | ||
private $renderedString; | ||
/** | ||
* @var bool | ||
*/ | ||
private $append; | ||
|
||
public function __construct(ViewElementTag $plugTag, $renderedString = null, $isAppend = false) { | ||
$this->tag = $plugTag; | ||
$this->renderedString = $renderedString; | ||
$this->append = $isAppend; | ||
} | ||
|
||
/** | ||
* @return ViewElementTag | ||
*/ | ||
public function getTag() | ||
{ | ||
return $this->tag; | ||
} | ||
|
||
/** | ||
* @return null|string | ||
*/ | ||
public function getRenderedString() | ||
{ | ||
return $this->renderedString; | ||
} | ||
|
||
public function isAppend() | ||
{ | ||
return $this->append; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
/** | ||
* @author Gabriel Zerbib <gabriel@figdice.org> | ||
* @copyright 2004-2016, Gabriel Zerbib. | ||
* @version 2.3 | ||
* @package FigDice | ||
*/ | ||
|
||
namespace figdice\test; | ||
|
||
use figdice\View; | ||
use PHPUnit_Framework_TestCase; | ||
|
||
class SlotPlugTest extends PHPUnit_Framework_TestCase | ||
{ | ||
public function testPlugExecutesInLocalContext() | ||
{ | ||
$template = <<<ENDTEMPLATE | ||
<fig:template> | ||
<!-- define a slot --> | ||
<slot fig:slot="myslot">Default Slot Content</slot> | ||
<!-- create some contextual data --> | ||
<fig:mount target="someData" value="1" /> | ||
<!-- execute the plug in the current context --> | ||
<title fig:mute="true" fig:plug="myslot" fig:text="/someData"/> | ||
<!-- modify the data that the plug refers to. | ||
Prior to version 2.3, the plug contents would render using the ending global context, | ||
but since 2.3 the plug is executed in its local context. --> | ||
<fig:mount target="someData" value="2" /> | ||
</fig:template> | ||
ENDTEMPLATE; | ||
|
||
$view = new View([View::GLOBAL_PLUGS]); | ||
$view->loadString(trim($template)); | ||
|
||
$rendered = $view->render(); | ||
$this->assertEquals(2, trim($rendered)); | ||
|
||
$view = new View(); | ||
$view->loadString(trim($template)); | ||
|
||
$rendered = $view->render(); | ||
$this->assertEquals(1, trim($rendered)); | ||
} | ||
} |