Skip to content

Commit 543b59d

Browse files
committed
Merge Twig global scope with Laravel Globals
1 parent 0e2693d commit 543b59d

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

src/Bridge.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,28 @@ public function mergeShared(array $context)
117117
return $context;
118118
}
119119

120+
/**
121+
* Merges a context with the defined globals.
122+
*
123+
* @param array $context An array representing the context
124+
*
125+
* @return array The context merged with the globals
126+
*/
127+
public function mergeGlobals(array $context)
128+
{
129+
$context = parent::mergeGlobals($context);
130+
131+
// we don't use array_merge as the context being generally
132+
// bigger than globals, this code is faster.
133+
foreach ($this->app['view']->getShared() as $key => $value) {
134+
if (!array_key_exists($key, $context)) {
135+
$context[$key] = $value;
136+
}
137+
}
138+
139+
return $context;
140+
}
141+
120142
/**
121143
* Normalize a view name.
122144
*

0 commit comments

Comments
 (0)