Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>We've edited quite a bit here already so I'll just post a new answer, hope that's ok. Will leave my old answer up for the sake of it.</p> <p>Anyway, we're starting off from your latest example (<code>Form extends Tag</code>).</p> <p>Seems like you're trying to mimic some kind of <a href="http://en.wikipedia.org/wiki/Builder_pattern" rel="nofollow noreferrer">Builder pattern</a>, so bear with me and let's go with a short example:</p> <pre><code>class TagBuilder { protected $args; protected $className; protected $classLocation; function __construct() { } public function setClass($file, $class) { /* @todo Use reflection maybe to determine if $class is a Tag subclass */ if (file_exists($file)) { require_once $file; // Or use the autoloader } $this-&gt;classLocation = $file; $this-&gt;className = $class; } /** * @return Tag the built tag (or tag subclass) instance */ public function getTag() { $fullyQualifiedClassName = $this-&gt;getFullyQualifiedClassName(); $newTag = new $fullyQualifiedClassName($this-&gt;args); $newTag-&gt;class_location = $this-&gt;classLocation; return $newTag; } protected function getFullyQualifiedClassName() { return $this-&gt;className; } public function setArgs($args) { $this-&gt;args = $args; } } </code></pre> <p>Additionally, you will have to modify the Form constructor to call it's <code>parent::__construct($args)</code> method in order to pass the <code>$args</code> dependency.</p> <p>And then run it with</p> <pre><code>$builder = new TagBuilder(); $builder-&gt;setClass('/library/form/form.php', 'Form'); $builder-&gt;setArgs(array('wahoo', 'ok')); $form = $builder-&gt;getTag(); </code></pre> <p>This is a bit of a long example and it implies changing some of the OP's API, but if I understood the question correctly, then this is the desired behaviour (or part of it) that the OP wants to mimic in his application.</p> <hr> <p><em>Note:</em> I am aware that this isn't a classical example of the Builder pattern and that the <code>getTag</code> method might seem a bit ambiguous to some purists.</p>
    singulars
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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