As I stated in the previous segment, it’s possible to build a file loading class that has the ability to look for a targeted file recursively. To create a class with this capability, first I’m going to define its basic structure along with a few setter and getter methods, which will be responsible for setting and getting the file for which to search, and for performing the same tasks with the starting file path. If this brief description sounds a bit confusing to you, the following code sample should help to dissipate your doubts. Take a look at it:
// define a recursive loader class class Loader { private $file = ''; private $path = ''; // constructor (not implemented) public function __construct(){}
// set file to load public function set_file($file) { $this->file = $file; }
// get file to load public function get_file() { return $this->file; }
// set path to load file public function set_path($path) { $this->path = $path; }
// get path to load file public function get_path() { return $this->path; } }
As you can see, the above “Loader()” class has some simple methods, apart from the constructor, for setting and getting the file that needs to be included, and for establishing and retrieving the path from which to start searching the file. These setters and getters are very easy to understand, so I’m not going to spend more time discussing how they work. But wait a minute! Didn’t I say at the beginning of this section that my purpose here was building a file loader class that is capable of including a specified file through a recursive search? Yes, I did. But this functionality needs to be implemented by means of a separate method, which not surprisingly will be called “load().” Therefore, to see how this whole new method will be properly defined, read the next section.
blog comments powered by Disqus |
|
|
|
|
|
|
|