ts / reader-excel
Excel plugin for ts/reader, my extensible string and file reading library.
This package has no released version yet, and little information is available.
README
Excel plugin for ts/reader, my extensible string and file reading library.
Installation
Use Composer to install: composer require ts/reader-excel:~2.0
Direct usage of an implementation
If you know exactly what you want to read, feel free to instantiate a reader implementation directly:
use TS\Reader\Implementation\Json; $jsonReader = new Json; // Setting a json string $jsonReader->setString('{ "key": "value" }'); // Setting a json file $jsonReader->setFile(/* path to .json file */); // Reading the data $data = $jsonReader->readAll();
Using the ReaderContainer
Instead of instantiating reader implementations directly you can use the reader container to create the reader for you after a little bit of bootstrapping:
use TS\Reader\ReaderContainer; $container = new ReaderContainer; // Registration $container->registerReader('TS\\Reader\\Implementation\\Json', ['json']); // Register further implementations... // Creation using a json string $reader = $container->createForString('json', '{ "key": "value" }'); // Creation using a json file $reader = $container->createForFile(/* path to .json file */); // Reading the data $data = $reader->readAll();
Using the Symfony EventDispatcher
You can intercept or influence most parts of the reader's lifecycle by utilizing Symfony's EventDispatcher Component.
To utilize the full power of the EventDispatcher, you need to explicitly pass an instance when creating either the ReaderContainer or reader implementation:
use Symfony\Component\EventDispatcher\EventDispatcher; use TS\Reader\Implementation\Json; use TS\Reader\ReaderContainer; // Instantiate or get the EventDispatcher instance from somewhere, like a service/DI container $dispatcher = new EventDispatcher; // Pass it to the reader implementation or container $jsonReader = new Json($dispatcher); $container = new ReaderContainer($dispatcher);
You're now able to listen in to the following events, which are described inside the TS\Reader\ReaderEvents
class:
- INIT: Dispatched right in the reader's constructor.
- READ: Dispatched after reading.
- READ_COMPLETE: Dispatched when everything has been read.
- READ_LINE: Dispatched when a line has been read.