3131
3232namespace VuFind \View \Helper \Root ;
3333
34- use Laminas \View \Helper \AbstractHelper ;
3534use Laminas \View \Renderer \RendererInterface ;
35+ use VuFind \ServiceManager \Factory \Autowire ;
3636
3737/**
3838 * Context manager (useful for using render() instead of partial() for better
4545 * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
4646 * @link https://vufind.org/wiki/development Wiki
4747 */
48- class Context extends AbstractHelper
48+ class Context
4949{
50+ /**
51+ * Constructor
52+ *
53+ * @param RendererInterface $view View renderer
54+ */
55+ #[Autowire]
56+ public function __construct (
57+ protected RendererInterface $ view
58+ ) {
59+ }
60+
5061 /**
5162 * Set an array of variables in the view; return the previous values of those
5263 * variables so they can be restored.
@@ -57,12 +68,10 @@ class Context extends AbstractHelper
5768 */
5869 public function apply ($ vars )
5970 {
60- $ view = $ this ->getView ();
61-
6271 $ oldVars = [];
6372 foreach ($ vars as $ k => $ v ) {
64- $ oldVars [$ k ] = $ view ->$ k ?? null ;
65- $ view ->$ k = $ v ;
73+ $ oldVars [$ k ] = $ this -> view ->$ k ?? null ;
74+ $ this -> view ->$ k = $ v ;
6675 }
6776 return $ oldVars ;
6877 }
@@ -76,13 +85,11 @@ public function apply($vars)
7685 */
7786 public function restore ($ vars )
7887 {
79- $ view = $ this ->getView ();
80-
8188 foreach ($ vars as $ k => $ v ) {
8289 if (null === $ v ) {
83- unset($ view ->$ k );
90+ unset($ this -> view ->$ k );
8491 } else {
85- $ view ->$ k = $ v ;
92+ $ this -> view ->$ k = $ v ;
8693 }
8794 }
8895 }
@@ -101,22 +108,22 @@ public function restore($vars)
101108 public function renderInContext ($ template , $ context )
102109 {
103110 $ oldContext = $ this ->apply ($ context );
104- $ html = $ this ->getView () ->render ($ template );
111+ $ html = $ this ->view ->render ($ template );
105112 $ this ->restore ($ oldContext );
106113 return $ html ;
107114 }
108115
109116 /**
110- * Grab the helper object, so we can call methods on it .
117+ * Return this helper instance .
111118 *
112- * @param ? RendererInterface $view View object to modify.
119+ * @param RendererInterface $view View Renderer
113120 *
114121 * @return Context
115122 */
116123 public function __invoke (?RendererInterface $ view = null )
117124 {
118125 if (null !== $ view ) {
119- $ this ->setView ( $ view) ;
126+ $ this ->view = $ view ;
120127 }
121128 return $ this ;
122129 }
0 commit comments