I am brushing up on my non-framework Object Oriented PHP and decided to do a test. Unfortunately, while I understand the concept of calling methods from a class, this particular test is slightly more complicated and I don't know what the terminology is for this particular type of situation is.
Test
Create a PHP class that parses (unknown number of) text files in a folder and allows to extract the total value of amount field from the file and get filenames of parsed files.
File Format:
The files are plain text csv files. Let's assume that the files contain a list of payments changed in the last N days. There are 2 different types of line:
- Card payment collected - type = 1, date, order id, amount
- Card payment rejected - type = 2, date, order id, reason, amount
Example file:
1,20090313,542,11.99
1,20090313,543,9.99
2,20090312,500,some reason, 2.99
Usage Example:
The usage could be something like this:
$parser = new Parser(...);
$files = $parser->getFiles();
foreach ($files as $file) {
$filename = $file->getFileName();
$amount_collected = $file->getTotalAmount(...);
$amount_rejected = $file->getTotalAmount(...);
}
My question is:
How can you do $file->method() when the class is called parser? I'm guessing you return an object from the getFiles method in the parser class, but how can you run methods with the returned object?
I attempted to Google this, but as I don't know the terminology for this situation I didn't find anything.
Any help is much appreciated, even if it's just what the terminology for this situation is.