88import java .io .StringWriter ;
99import java .util .HashMap ;
1010import java .util .Map ;
11+ import java .util .Map .Entry ;
1112import php .pkg .twig .TwigExtension ;
13+ import php .runtime .Memory ;
1214import php .runtime .annotation .Reflection .Getter ;
1315import php .runtime .annotation .Reflection .Namespace ;
1416import php .runtime .annotation .Reflection .Signature ;
@@ -44,9 +46,18 @@ public String render(Environment env) throws IOException {
4446 return render (env , new HashMap <>());
4547 }
4648
49+ protected void prepareContext (Environment env , Map <String , Object > contexts ) {
50+ for (Entry <String , Object > entry : contexts .entrySet ()) {
51+ if (entry .getValue () instanceof Memory ) {
52+ contexts .put (entry .getKey (), Memory .unwrap (env , (Memory ) entry .getValue (), true ));
53+ }
54+ }
55+ }
56+
4757 @ Signature
4858 public String render (Environment env , Map <String , Object > contexts ) throws IOException {
4959 StringWriter writer = new StringWriter ();
60+ prepareContext (env , contexts );
5061 getWrappedObject ().evaluate (writer , contexts , WrapLocale .getDefault (env ));
5162 return writer .toString ();
5263 }
@@ -59,6 +70,8 @@ public String renderBlock(Environment env, String block) throws IOException {
5970 @ Signature
6071 public String renderBlock (Environment env , String block , Map <String , Object > contexts ) throws IOException {
6172 StringWriter writer = new StringWriter ();
73+ prepareContext (env , contexts );
74+
6275 getWrappedObject ().evaluateBlock (block , writer , contexts , WrapLocale .getDefault (env ));
6376 return writer .toString ();
6477 }
0 commit comments