I wish i knew how to search for this question / phrase it more appropriately. This hampered my search for prior questions; bear with me if this is a duplicate.
See the update / edits at the bottom of this post
Background / what i'm trying to do:
I have a URL that looks a lot like this:
http://myapp.com/calculate/$fileID/$calculateID
$fileID and $calculateID are keys that I use to keep track of a data set and something I call a 'calculation'. Essentially, that URL says perform $calculateID on the data in $fileID.
I go to my database (mongo) and ask for a php class name or sring or file path or what have you that matches $calculateID. For example's sake let's say the table looks like this:
+-----+-------------------+
| _id | phpFile |
+-----+-------------------+
| 1 | basicCalcs.php |
| 2 | advancedCalcs.php |
| 3 | summaryCalcs.php |
+-----+-------------------+
Note: is is safe to assume that each file in the phpFile column has a common interface / set of public methods.
Example:
http://myapp.com/calculate/23/2
would go to the database, get the data from set 23 and then load up the functions in advancedCalcs.php. Once advancedCalcs.php has been loaded, a function within will receive the data. From there, a set of calculations and transformations are performed on the data.
My question
My question is what is a 'laravel 4 friendly' way to dynamically load up advancedCalcs.php and feed the data into a set of methods? Is there a way to lazy load this type of thing. Currently, i am only aware of the very unsophisticated require_once() method. I would really like to avoid this as i am convinced that laravel 4 has functionality to dynamically load an underlying class and hook it up to a common interface.
EDIT 1
Thanks to Antonio Carlos Ribeiro, i was able to make some progress.
After running dump-autoload command, my vendor/composer/autoload_classmap.php file has a few new entries that look like this:
'AnalyzeController' => $baseDir . '/app/controllers/AnalyzeController.php',
'AppName\\Calc\\CalcInterface' => $baseDir . '/app/calculators/CalcInterface.php',
'AppName\\Calc\\basicCalcs' => $baseDir . '/app/calculators/basicCalcs.php',
With code like the sample below, i can create an instance of the basicCalcs class:
$className = "AppName\\Calc\\basicCalcs";
$instance = new $className;
var_dump($instance);
Where the basicCalcs.php file looks like this:
//PATH: /app/calculators/basicCalcs.php
<?php namespace Reporter\Calc;
class basicCalcs {
public function sayHi(){
echo("hello world! i am basicCalcs");
}
};
?>
Updated question:
How can i create an alias similar to the AnalyzeController entry in autoload_classmap.php rather than having to refer to basicCalcs.php with a full namespace?