Download the PHP package get-stream/stream-doctrine without Composer
On this page you can find all versions of the php package get-stream/stream-doctrine. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download get-stream/stream-doctrine
More information about get-stream/stream-doctrine
Files in get-stream/stream-doctrine
Package stream-doctrine
Short Description Build newsfeeds and activity feeds with Doctrine using getstream.io
License BSD-3-Clause
Homepage https://getstream.io/
Informations about the package stream-doctrine
Stream Doctrine
stream-doctrine is a package that integrates you Doctrine entities with Stream.
You can sign up for a Stream account at https://getstream.io/get_started.
Note there is also a lower level PHP - Stream integration library which is suitable for all PHP applications.
💡 This library is built for the Feeds product. The Chat product can be found here.
Build Activity Streams, News Feeds, and More
You can build:
- Activity Streams - like the one seen on GitHub
- A Twitter-like feed
- Instagram / Pinterest Photo Feeds
- Facebook-style newsfeeds
- A Notification System
- Lots more...
Installation
Composer
Composer will install our latest version automatically.
PHP compatibility
Current releases require PHP 8.0
or higher, and depend on doctrine/orm
version 2.14
or higher.
See the GitHub build configuration for details of how it is built and tested against different PHP versions.
GetStream.io Dashboard
Now, login to GetStream.io and create an application in the dashboard.
Retrieve the API key, API secret, and API app id, which are shown in your dashboard.
Stream-Doctrine setup
Setup
To register this plugin into Doctrine ORM, you need to register a ModelListener
on the EntityManager like this:
Features of Stream-Doctrine
Entity integration
Stream-Doctrine provides instant integration with Doctrine entities - implementing the interface and adding an EntityListener will give you automatic tracking of your models to user feeds.
For example:
Every time a Pin is created it will be stored in the feed of the user that created it, and when a Pin instance is deleted then it will get removed as well.
Automatically!
Activity Fields
Models are stored in feeds as activities. An activity is composed of at least the following data fields: actor, verb, object, time. You can also add more custom data if needed.
object is a reference to the entity instance itself
actor is a reference to the user attribute of the instance
verb is a string representation of the class name
time is a DateTimeInterface object of when the activity happened. Mostly this will be the created_at
or similar attribute of the entity.
A few assumptions are made on the entity class in order to be able to implement the ActivityInterface:
- the Entity has an identifier (which goes for every entity).
- the Entity has a *-to-one relationship to some user or "actor".
- the Entity has a timestamp column (
created_at
for example).
You can change how a entity instance is stored as activity by implementing specific methods as explained later.
An example of a complete Activity typed entity is shown below:
You can change every activity*
method according to your needs or entity implementation.
Activity Extra Data
Often, you'll want to store more data than just the basic fields, for use with custom ranking or aggregation, for example. You achieve this by implementing the method in the entity.
NOTE: The data will be serialized using the json_encode function, so it needs to be valid input for that.
Feed Manager
stream-doctrine
comes with a FeedManager class (implementing FeedManagerInterface) that helps with all common feed operations.
The FeedManager needs a configured GetStream\Stream\Client
object when instantiating it.
Pre-Bundled Feeds
To get you started the manager has feeds pre configured. You can add more feeds if your application needs it. The three feeds are divided in three categories.
User Feed:
The user feed stores all activities for a user. Think of it as your personal Facebook page. You can easily get this feed from the manager.
News Feed:
The news feeds store the activities from the people you follow. You can setup the names of the newsfeeds using:
Then you can access those feeds in an ArrayAccess kind of way:
Both user feed and news feeds are shorthand methods for:
Notification Feed:
The notification feed can be used to build notification functionality.
Below we show an example of how you can read the notification feed.
By default the notification feed will be empty. You can specify which users to notify when your model gets created. In the case of a retweet you probably want to notify the user of the parent tweet.
Another example would be following a user. You would commonly want to notify the user which is being followed.
Follow Feed
To create the news feeds you need to notify the system about follow relationships. The manager comes with methods to let a user's news feeds follow another user's feed. This code lets the current user's news feeds follow the target_user's personal feed.
Displaying the Newsfeed
Activity Enrichment
When you read data from feeds with activities created by stream-doctrine
, an activity will look like this:
This is far from ready for usage in your template. We call the process of loading references from the database: enrichment. An example is shown below.
Customizing Enrichment
Sometimes you'll want to customize how enrichment works.
If you store references to model instances as custom fields (using the activityExtraData()
method)
you can use the Enrich
class to take care of it for you:
Tell the enricher to enrich the parent_tweet
field into a full entity object:
Full documentation and Low level APIs access
When needed you can also use the low level PHP API directly. Documentation is available at the Stream website.
Copyright and License Information
Copyright (c) 2014-2022 Stream.io Inc, and individual contributors. All rights reserved.
See the file "LICENSE" for information on the history of this software, terms & conditions for usage, and a DISCLAIMER OF ALL WARRANTIES.