Created
February 24, 2012 09:10
-
-
Save bwaidelich/1899672 to your computer and use it in GitHub Desktop.
Fluid Interceptors (Replace Tabs by underscores)
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
<?php | |
abstract class Tx_BlogExample_Controller_AbstractController extends Tx_Extbase_MVC_Controller_ActionController { | |
protected $defaultViewObjectName = 'Tx_BlogExample_View_TemplateView'; | |
// ... | |
} | |
?> |
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
<?php | |
class Tx_BlogExample_View_Interceptor_ReplaceTabs implements Tx_Fluid_Core_Parser_InterceptorInterface { | |
/** | |
* @var boolean | |
*/ | |
protected $interceptorEnabled = TRUE; | |
/** | |
* @var Tx_Extbase_Object_ObjectManagerInterface | |
*/ | |
protected $objectManager; | |
/** | |
* @param Tx_Extbase_Object_ObjectManagerInterface $objectManager | |
* @return void | |
*/ | |
public function injectObjectManager(Tx_Extbase_Object_ObjectManagerInterface $objectManager) { | |
$this->objectManager = $objectManager; | |
} | |
/** | |
* @param Tx_Fluid_Core_Parser_SyntaxTree_NodeInterface $node | |
* @param integer $interceptorPosition One of the INTERCEPT_* constants for the current interception point | |
* @param Tx_Fluid_Core_Parser_ParsingState $parsingState the current parsing state. Not needed in this interceptor. | |
* @return Tx_Fluid_Core_Parser_SyntaxTree_NodeInterface | |
*/ | |
public function process(Tx_Fluid_Core_Parser_SyntaxTree_NodeInterface $node, $interceptorPosition, Tx_Fluid_Core_Parser_ParsingState $parsingState) { | |
$nodeText = $node->getText(); | |
$replacedNode = $this->objectManager->create('Tx_Fluid_Core_Parser_SyntaxTree_TextNode', str_replace(chr(9), '_', $nodeText)); | |
return $replacedNode; | |
} | |
/** | |
* @return array Array of INTERCEPT_* constants | |
*/ | |
public function getInterceptionPoints() { | |
return array( | |
self::INTERCEPT_TEXT | |
); | |
} | |
} | |
?> |
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
<?php | |
class Tx_BlogExample_View_TemplateView extends Tx_Fluid_View_TemplateView { | |
/** | |
* @return Tx_Fluid_Core_Parser_Configuration | |
*/ | |
protected function buildParserConfiguration() { | |
$parserConfiguration = parent::buildParserConfiguration(); | |
$parserConfiguration->addInterceptor($this->objectManager->get('Tx_BlogExample_View_Interceptor_ReplaceTabs')); | |
return $parserConfiguration; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment