Lifestream is a stream unifier for PHP. Thanks to this lib, you could easily fetch last datas / status from different services:
Lifestream can also filter some status:
And Lifestream can format each status with formatters:
Add package to your composer.json
:
composer require lyrixx/lifestream:~1.1
Lifestream library is ship with a factory to start very quickly:
<?php
$service = 'twitter';
$username = 'lyrixx';
$stream = Lyrixx\Lifestream\LifestreamFactory::createNewInstance()
->createLifestream($service, array($username))
->addFilter(new Lyrixx\Lifestream\Filter\TwitterMention())
->addFormatter(new Lyrixx\Lifestream\Formatter\Link())
->boot()
->getStream()
;
foreach ($stream as $status) {
echo $status.'<br />';
}
For an extensive demo, look at demo/index.php file.
There are 3 different actors:
A Service (ServiceInterface
): This one will fetch data from a web server and
extract datas
A Lifestream (Lifestream
): This one will use a service to retrieve data and then it will
create a collection of status
A Status (StatusInterface
): This is one item among others. It could be a
tweet, ...
After this bootstrap, you can add FormatterInterface
to format all status and
/ or add FilterInterface
to filter un-wanted status.
So, from scratch:
$service = new Lyrixx\Lifestream\Service\Twitter('lyrixx');
$lifestream = Lyrixx\Lifestream\Lifestream($service);
$lifestream->addFilter(new Lyrixx\Lifestream\Filter\TwitterMention());
$lifestream->addFilter(new Lyrixx\Lifestream\Filter\TwitterRetweet());
$lifestream->addFormatter(new Lyrixx\Lifestream\Formatter\Link());
$lifestream->boot();
$stream = $lifestream->getStream();
foreach ($stream as $status) {
echo $status.'<br />';
}
If you want to fetch and then merge few services, you can use the
Aggregate
service. It will automatically sort all status by date.
Note: This Aggregate service will download all source in parallel for extra speed!
$service1 = new Lyrixx\Lifestream\Service\Twitter('lyrixx');
$service2 = new Lyrixx\Lifestream\Service\TwitterSearch('#symfony2');
$service = new Lyrixx\Lifestream\Service\Aggregate(array($service1, $service2));
// ...