Development

#2685: PartialHelper.diff.txt

You must first sign up to be able to contribute.

Ticket #2685: PartialHelper.diff.txt

File PartialHelper.diff.txt, 3.1 kB (added by noel, 9 months ago)
Line 
1 Index: lib/helper/PartialHelper.php
2 ===================================================================
3 --- lib/helper/PartialHelper.php    (revision 8279)
4 +++ lib/helper/PartialHelper.php    (working copy)
5 @@ -20,7 +20,7 @@
6  /**
7   * Evaluates and echoes a component slot.
8   * The component name is deduced from the definition of the view.yml
9 - * For a variable to be accessible to the component and its partial,
10 + * For a variable to be accessible to the component and its partial,
11   * it has to be passed in the second argument.
12   *
13   * <b>Example:</b>
14 @@ -76,7 +76,7 @@
15  
16  /**
17   * Evaluates and echoes a component.
18 - * For a variable to be accessible to the component and its partial,
19 + * For a variable to be accessible to the component and its partial,
20   * it has to be passed in the third argument.
21   *
22   * <b>Example:</b>
23 @@ -126,6 +126,11 @@
24      }
25    }
26  
27 +  $response = $context->getResponse();
28 +
29 +  $css = $response->getStylesheets();
30 +  $js  = $response->getJavascripts();
31 +
32    $controller = $context->getController();
33  
34    if (!$controller->componentExists($moduleName, $componentName))
35 @@ -198,7 +203,10 @@
36  
37      if ($cacheManager)
38      {
39 -      $retval = _set_cache($cacheManager, $uri, $retval);
40 +      $importedJs = array_diff_key($response->getJavascripts(), $js);
41 +      $importedCss = array_diff_key($response->getStylesheets(), $css);
42 +
43 +      $retval = _set_cache($cacheManager, $uri, $retval, $importedJs, $importedCss);
44      }
45  
46      return $retval;
47 @@ -269,13 +277,23 @@
48      }
49    }
50  
51 +  $response = $context->getResponse();
52 +
53 +  $css = $response->getStylesheets();
54 +  $js  = $response->getJavascripts();
55 +
56    $view = new sfPartialView();
57    $view->initialize($context, $moduleName, $actionName, '');
58    $retval = $view->render($vars);
59  
60 +
61 +
62    if ($cacheManager)
63    {
64 -    $retval = _set_cache($cacheManager, $uri, $retval);
65 +    $importedJs = array_diff_key($response->getJavascripts(), $js);
66 +    $importedCss = array_diff_key($response->getStylesheets(), $css);
67 +
68 +    $retval = _set_cache($cacheManager, $uri, $retval, $importedJs, $importedCss);
69    }
70  
71    return $retval;
72 @@ -283,19 +301,39 @@
73  
74  function _get_cache($cacheManager, $uri)
75  {
76 -  $retval = $cacheManager->get($uri);
77 +  $datas = @unserialize($cacheManager->get($uri));
78 +  $retval = null;
79 +  if (is_array($datas))
80 +  {
81 +    $response = sfContext::getInstance()->getResponse();
82  
83 +    foreach ($datas['js'] as $js => $options)
84 +    {
85 +      $response->addJavascript($js, '');
86 +    }
87 +
88 +    foreach ($datas['css'] as $css => $options)
89 +    {
90 +      $response->addStylesheet($css, '', $options);
91 +    }
92 +
93 +    $retval = $datas['data'];
94 +  }
95 +
96    if (sfConfig::get('sf_web_debug'))
97    {
98      $retval = sfWebDebug::getInstance()->decorateContentWithDebug($uri, $retval, false);
99    }
100  
101 +
102 +
103    return $retval;
104  }
105  
106 -function _set_cache($cacheManager, $uri, $retval)
107 +function _set_cache($cacheManager, $uri, $retval, $js = array(), $css = array())
108  {
109 -  $saved = $cacheManager->set($retval, $uri);
110 +  $data = array('data' => $retval, 'css' => $css, 'js' => $js);
111 +  $saved = $cacheManager->set(serialize($data), $uri);
112  
113    if ($saved && sfConfig::get('sf_web_debug'))
114    {