Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I will answer my own question as I found a solution.</p> <p>Ok, clues were fine. The problem was that PHP including a file binds the symbols for later use while parsing the file.</p> <p>So, I needed some kind of instrospection. After reading/googling/searching for all night, finally I've ended up finding <a href="https://github.com/zenovich/runkit" rel="nofollow">Runkit</a>.</p> <p><a href="http://pt2.php.net/manual/en/book.runkit.php" rel="nofollow">Runkit documentation</a> can be found here. I know that is not the best thing you can do with your code design. But for my project needs, the truth is that <a href="http://en.wikipedia.org/wiki/Reflection_%28computer_programming%29" rel="nofollow">Reflection</a> was needed.</p> <p>Here is the modified code using <code>Runkit</code>:</p> <pre><code>protected function execute(InputInterface $input, OutputInterface $output) { // Gets a reference to the console application and removes all commands $pamperoApp = $this-&gt;getApplication(); $pamperoApp-&gt;clearCommands(); // Adds default commands and add this command $pamperoApp-&gt;addCommands($pamperoApp-&gt;getDefaultCommands()); $pamperoApp-&gt;add($this); $namespace = "pampero\\cli\\modules"; foreach(glob(MODULES_DIR . "/*/*Command.php") as $filename) { $className = str_replace(".php", "", $namespace . "\\" . basename(dirname($filename)) . "\\" . basename($filename)); // Do not add this command again. This command shouldn't be modified on-the-fly if (get_class($this) !== $className) { $class = new $className(); // Redefines the class definition runkit_import($filename, RUNKIT_IMPORT_CLASSES | RUNKIT_OVERRIDE_OBJECTS | RUNKIT_IMPORT_OVERRIDE); $pamperoApp-&gt;add($class); } } } </code></pre>
    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.
    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