1. Go to this page and download the library: Download get-stream/stream-doctrine library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
get-stream / stream-doctrine example snippets
$client = new GetStream\Stream\Client($apiKey, $apiSecret);
$manager = new GetStream\Doctrine\FeedManager($client);
$listener = new GetStream\Doctrine\ModelListener($manager);
$entityManager
->getConfiguration()
->getEntityListenerResolver()
->register($listener);
/**
* @ORM\Table(name="pins")
* @ORM\EntityListeners({"\GetStream\Doctrine\ModelListener"})
*/
class Pin implements Activity
{
use ActivityTrait;
}
class Pin implements ActivityInterface
{
use ActivityTrait;
/**
* Each pin is created by someone.
*
* @var User
*
* @ORM\ManyToOne(targetEntity="User", fetch="EXTRA_LAZY")
* @ORM\JoinColumn(name="creator_id", referencedColumnName="id")
*/
private $creator;
/**
* @ORM\Column(type="datetime_immutable", name="created_at")
*/
private $createdAt;
/**
* @return string
*/
public function activityVerb()
{
return 'pin';
}
/**
* @return string
*/
protected function activityId()
{
return $this->id;
}
/**
* @return string
*/
public function activityActorId()
{
return $this->creator->id();
}
/**
* @return string
*/
public function activityActor()
{
return User::class.':'.$this->activityActorId();
}
/**
* @return DateTimeInterface
*/
public function activityTime()
{
return $this->createdAt;
}
class Tweet implements ActivityInterface
{
use ActivityTrait;
public function activityExtraData()
{
return ['is_retweet' => $this->isRetweet()];
}
}
class Tweet implements ActivityInterface
{
use ActivityTrait;
/**
* @return array
*/
public function activityNotify()
{
if ($this->isRetweet()) {
return ['notification:'.$this->parent()->user()->id()];
}
return [];
}
class Follow implements ActivityInterface
{
use ActivityTrait;
/**
* @return array
*/
public function activityNotify()
{
return ['notification:'.$this->target()->id()];
}
}
use GetStream\Doctrine\Enrich;
$feed = $feedManager->getUserFeed($userId);
$activities = $feed->getActivities(0, 25)['results'];
$enricher = new Enrich();
$activities = $enricher->enrichActivities($activities);
class Pin implements ActivityInterface
{
use ActivityTrait;
public function activityExtraData()
{
return ['parent_tweet' => self::class.':'.$this->parent()->id()];
}
}