Closed deni-zen closed 7 years ago
Complete/consider these first:
The more I think about this the more I think extending SplFileObject the way I am is a bad idea. I think a better way to go would be to rewrite the Writable interface to fit with SplFileObject so that any SplFileObject can be passed to the Reader/Writer as-is. I could maybe write specialized versions of them just for clarity and to restrict access to certain methods or whatever, but you wouldn't have to use my file object(s). So basically I would just change the Readable interface to...
Readable
interface Readable
{
public function fgets() (or getCurrentLine());
public function fread($length);
public function eof();
public function rewind();
}
Writable
interface Writable
{
public function fwrite($string);
}
In fact I could probably still keep my CSVelte\IO\File object for convenience if I want it. But I just need ot adjust the interfaces. Probably want to add this one too:
Seekable
interface Seekable
{
public function fseek($pos);
}
The SplFileObject::setCsvControl() and getCsvControl methods should be incorperated somehow. Like when using IO\File, it should alter these methods to accept and return a Flavor object, and in the reader, if no flavor is set, then it should consult SplFileObject::getCsvControl
I think we can scrap CSVelte\IO\Stream (#97) for now... SplFileObject should work in its place AFAIK
This may be relevant: http://php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen
Also I don't know how, or even if its possible, to get the actual resource object of SplFileObject
Rather than having to go with some nonstandard duck-typing or instanceof solution I have decided (I think) to support (in a way) the reading of SplFileObject by creating an adapter. So you simply do this instead:
$reader = CSVelte::readerFromSplFileObject($splFileObj);
or
$file = CSVelte\IO\File::fromSplFileObject($obj);
Since I won't be able to accept SplFileObject directly, change the Readable, Writable, and Seekable methods back to read()
, write()
, seek()
, etc.
The more I use this thing the more I feel restricted by it. Scrap it. Extend stream instead. It just works better. Provides way more flexibility.
Scrapped and removed.
Rather than just extending Stream, extend SplFileObject for your IO/File object. Here's whatcha need ta do: