Note that there are some explanatory texts on larger screens.

plurals
  1. POMaking a Proxy Class
    primarykey
    data
    text
    <p>I'm trying to do a Proxy class that allow me to set custom values to different sfForm's. I have to do it this way because php dosn't have multiple inheritance (all sfForm extends some Base* made by doctrine) and I'm always copy-pasting the same code to sfForm configure() method.</p> <p>Up to now I made the class but couldn't make it work. I know i have to pass the object by reference but i'm stuck!</p> <p>Here is what I made</p> <pre><code>class FormProxy { private $_form; private $_formatter; public function __construct(sfForm &amp;$form, $params = array()) { $this-&gt;_form = $form; if(count($params)&gt;0) $this-&gt;set ($params); } public function set($array = array()){ if (count($array) == 0){ return; } if(isset ($array['formatter'])){ $this-&gt;setFormatter($array['formatter']); } if(isset ($array['CSRFProtection'])){ $this-&gt;disableCSRFProtection(); } return $this; } public function setForm(sfForm &amp;$form){ $this-&gt;_form = $form; return $this; } public function &amp; getForm(){ $this-&gt;init(); return $this-&gt;_form; } public function getFormatter(){ return $this-&gt;_formatter; } public function setFormatter($formatter = null){ $this-&gt;_formatter = $formatter; return $this; } private function init(){ if($this-&gt;_formatter != null){ $decorator = new sfWidgetFormSchemaFormatterLocal($form-&gt;getWidgetSchema(), $form-&gt;getValidatorSchema()); $form-&gt;getWidgetSchema()-&gt;addFormFormatter($this-&gt;_formatter, $decorator); $form-&gt;getWidgetSchema()-&gt;setFormFormatterName($this-&gt;_formatter); } } public function disableCSRFProtection(){ $this-&gt;_form-&gt;disableCSRFProtection(); } } </code></pre> <p>I know the proxy class could be static, but for now it's the same.</p> <p>Edit:</p> <p>My problem is that when I do</p> <pre><code> $proxy = new FormProxy(new ClientForm(), array( 'formatter' =&gt; 'custom', 'CSRFProtection' =&gt; false, )); $form = $proxy-&gt;getForm(); </code></pre> <p>the changes made into the FormProxy doesn't seem applied outside (in the $form variable). I think this is because I'm not handling very good the reference of the $form, but tried in different ways with negative outcomes . </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload