Skip to content

Commit

Permalink
[TASK] Better contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Müller committed Aug 6, 2014
1 parent 30eb53c commit ee2fb96
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ class ContextCollectingRuntime extends \TYPO3\TypoScript\Core\Runtime {
*/
protected $collectionSettings;

/**
* If the current TypoScript path ends like this we won't store the context
*
* @var array
*/
protected $excludedPathEndpoints = array(
'<TYPO3.TypoScript:Matcher>',
'<TYPO3.TypoScript:Matcher>/condition',
'<TYPO3.TypoScript:Tag>'
);

/**
* @param string $nodePath
*/
Expand Down Expand Up @@ -126,15 +137,28 @@ public function getDefaultContextVariables() {
* @param $contextObject
*/
protected function collectContext($typoScriptPath, $contextObject = NULL) {
// exclude a view TypoScript objects for now to reduce hits
foreach ($this->excludedPathEndpoints as $excludedPathEndpoint) {
if (strpos(strrev($typoScriptPath), strrev($excludedPathEndpoint)) === 0) {
return;
}
}

if ($this->nodePath !== NULL && strpos($typoScriptPath, '_meta') === FALSE) {
$currentContext = $this->getCurrentContext();
if (isset($currentContext['node']) && ($currentContext['node'] instanceof NodeInterface) && (count($this->collectedContexts) < $this->collectionSettings['limit'])) {
if (isset($currentContext['node']) && ($currentContext['node'] instanceof NodeInterface)) {
$node = $currentContext['node'];
if ($node->getPath() === $this->nodePath) {
if ($contextObject !== NULL) {
$currentContext['this'] = $contextObject;
$configuration = $this->getConfigurationForPath($typoScriptPath);
if (isset($configuration['__meta']['class'])) {
if ($contextObject !== NULL) {
$currentContext['this'] = $contextObject;
}
if (count($this->collectedContexts) >= $this->collectionSettings['limit']) {
array_shift($this->collectedContexts);
}
$this->collectedContexts[preg_replace('#<[^<>]*>/#', '/', $typoScriptPath)] = $currentContext;
}
$this->collectedContexts[preg_replace('/<[^<>]*>/', '', $typoScriptPath)] = $currentContext;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@
*/
class VariableInfoViewHelper extends \TYPO3\Fluid\Core\ViewHelper\AbstractViewHelper {

/**
* @Flow\Inject
* @var \TYPO3\Flow\Reflection\ReflectionService;
*/
protected $reflectionService;

/**
* @var boolean
*/
Expand All @@ -36,6 +30,8 @@ class VariableInfoViewHelper extends \TYPO3\Fluid\Core\ViewHelper\AbstractViewHe
* @return mixed
*/
public function render($variable, $as = 'variableInformation') {
$reflectionService = $this->objectManager->get('TYPO3\Flow\Reflection\ReflectionService');

$variableInformation = array(
'isScalarValue' => FALSE
);
Expand All @@ -47,7 +43,7 @@ public function render($variable, $as = 'variableInformation') {

if ($variableInformation['baseType'] === 'object') {
$variableInformation['gettableProperties'] = \TYPO3\Flow\Reflection\ObjectAccess::getGettablePropertyNames($variable);
$variableInformation['className'] = $this->reflectionService->getClassNameByObject($variable);
$variableInformation['className'] = $reflectionService->getClassNameByObject($variable);
}

$this->templateVariableContainer->add($as, $variableInformation);
Expand Down
2 changes: 1 addition & 1 deletion Configuration/Settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Flowpack:
Neos:
contextWatcher:
enable: FALSE
limit: 10
limit: 20

TYPO3:
Neos:
Expand Down

0 comments on commit ee2fb96

Please sign in to comment.