Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think what you want to do, is more or less to reverse the keys and values returned from <code>PhpFileAndContent</code>. Said class returns a list of <code>filepath =&gt; source</code>, and you want to first reverse the mapping so it is <code>source =&gt; filepath</code> and then expand <code>source</code> for each class defined in <code>source</code>, so it will be <code>class1 =&gt; filepath, class2 =&gt; filepath</code>.</p> <p>It should be easy as in your <code>getChildren()</code> you can simply access <code>$this-&gt;key()</code> to get the current file path for the source you are running <code>getDefinedClasses()</code> on. You can write <code>getDefinedClasses</code> as <code>getDefinedClasses($path, $source)</code> and instead of returning an indexed array of all the classes, it will return a dictionary where each value from the current indexed array is a key in the dictionary and the value is the filepath where that class was defined.</p> <p>Then it will come out just as you want.</p> <p>The other option is to drop your use of <code>RecursiveArrayIterator</code> and instead write your own iterator that is initialized (in <code>getChildren</code>) as</p> <pre><code>return new FilePathMapperIterator($this-&gt;key,getDefinedClasses($this-&gt;current())); </code></pre> <p>and then <code>FilePathMapperIterator</code> will convert the class array from <code>getDefinedClasses</code> to the <code>class =&gt; filepath</code> mapping I described by simply iterating over the array and returning the current class in <code>key()</code> and always returning the specified filepath in <code>current()</code>.</p> <p>I think the latter is more cool, but definitely more code so its unlikely that I would have gone that way if I can adapt <code>getDefinedClasses()</code> for my needs.</p>
 

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