Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I worked out the fairly laborious manual way to do this.</p> <p>Like discussed at top the process itself is simple: </p> <ol> <li>get your list of files for each file. Now for each file:</li> <li>create a random namespace id </li> <li>trim file and replace the first start tag</li> <li>add namespace id and start tag to file</li> <li>write to temp file</li> <li>import temp file</li> <li>do any reflection required then cleanup</li> </ol> <p>I've got an example with some zend here.... probably not the most efficient but it works.</p> <pre><code>&lt;?php //first setup zend set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__)."/../zend/library/"); require_once 'Zend/Loader/Autoloader.php'; $loader = Zend_Loader_Autoloader::getInstance(); $loader-&gt;registerNamespace(dirname(__FILE__)."/../zend/library/"); //include my extender class class Zend_Reflection_File_WithNamespace extends Zend_Reflection_File { public function getFunctionsWithNamespace($namespace = '', $reflectionClass = 'Zend_Reflection_Function') { $functions = array(); foreach ($this-&gt;_functions as $function) { $newName = $namespace . "\\" . $function; $instance = new $reflectionClass($newName); if (!$instance instanceof Zend_Reflection_Function) { require_once 'Zend/Reflection/Exception.php'; throw new Zend_Reflection_Exception('Invalid reflection class provided; must extend Zend_Reflection_Function'); } $functions[] = $instance; } return $functions; } } //find file(s) $startDir = 'hello/'; //$tempDir = 'php://temp/resource='; $tempDir = 'temp/'; $fileList = scandir($startDir); function ppPrintR($data) { echo "&lt;pre&gt;"; print_r($data); echo "&lt;/pre&gt;"; } //Now loop through each file, first writing to temp, including and then testing foreach ($fileList as $key =&gt; &amp;$fileItem) { if (is_file($startDir . $fileItem)) { //Take file and convert it $findDir = $startDir . $fileItem; echo $startDir . $fileItem; $inContents = file_get_contents($findDir); $randIden = 'm' . preg_replace('/\.|\s/', '', microtime()); //Replace the &lt;?[php] at the start of the file with &lt;? namespace xyz; $inContents = trim($inContents); $addString = 'namespace ' . $randIden . '; '; $longTagPos = strpos($inContents,'&lt;?php'); $shortTagPos = strpos($inContents,'&lt;?'); if ($longTagPos !== false &amp;&amp; $longTagPos &lt; 10) { $inContents = str_replace('&lt;?php', '', $inContents); $addString = '&lt;?php ' . $addString; } else if ($shortTagPage !== false &amp;&amp; $longTagPos &lt; 10) { $inContents = str_replace('&lt;?', '', $inContents); $addString = '&lt;? ' . $addString; } $outContents = $addString . $inContents; //Now write and require new temp file $tempItem = $tempDir . $fileItem; file_put_contents($tempItem, $outContents); require($tempItem); //Now do normal things $reflectedFile = new Zend_Reflection_File_WithNamespace($tempItem); echo 'Before&lt;br/&gt;'; $functions = $reflectedFile-&gt;getFunctionsWithNamespace($randIden); echo 'After&lt;br/&gt;'; //Now foreach function, read params and consider execution foreach($functions as &amp;$functionItem) { echo $functionItem-&gt;name . "&lt;br/&gt;"; $functionParams = $functionItem-&gt;getParameters(); ppPrintR($functionParams); } //FIXME should clean here } } ?&gt; </code></pre>
 

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