Pre-1.0. Not intended for public use yet. The API is subject to undocumented change, and these pages may already be wrong about it.

Skip to content

Entry API ​

Introduction ​

Storyfeed::compose() builds a feed from entries, and a source's items() returns them. Storyfeed\Sources\Entry is one entry, in three forms: fluent, named arguments, or an array. See Composing Feeds and Feed Sources for setup.

A controller, or wherever the feed is read
php
use Storyfeed\Facades\Storyfeed;

$feed = Storyfeed::compose()
    ->add(fn ($entry) => $entry->by($order->customer)->action('place', $order))
    ->get();

Composed Feeds ​

Storyfeed::compose() returns a Storyfeed\ComposedFeed, a feed builder with these methods of its own:

MethodDoes
add(Closure|Entry $entry)adds one entry; a closure receives a new Entry
addMany(iterable $items, Closure $callback)adds an entry for each item; the callback receives the item, a new Entry and the item's key
inOrder()keeps the entries in the order added; cursors page by position, and nothing groups
source($source)throws a LogicException: a composed feed reads its own entries

The reads are a feed's: get(), cursorPaginate() and simplePaginate(), narrowed by only(), except(), the role filters and limit(). These differ:

CallOn a Composed Feed
read modeLog, whatever grouping.default says
live()groups dated entries that have a verb; throws an InvalidArgumentException when read with inOrder()
ordernewest first, dateless entries last in the order added; with inOrder(), the order added
entries dated in the futureshown
involving(), query(), members()throw FeedMisconfigured. See Source Limitations

Entry Methods ​

MethodSets
verb($verb, $object = null), action($verb, $object = null)the verb, a string or a verb enum, without a dot; and the object, when given
headline(string $headline, array $replace = [])the entry's own headline. See Headline Replacements
actor(), by()the actor
object()the object
target(), and its aliases to(), on(), in(), for(), with(), into()the target
context()the context
origin()the origin
result(), resulting()the result
instrument(), using()the instrument
location(), at()the location
generator()the generator
data(array|Arrayable $data)the entry's data
body($body)the object's body: a string, a body, or a list of bodies
id(string $id)the payload id; without it, one is derived from the entry and stays the same between reads
publishedAt($date)the date; without it, the entry is dateless
startsAt($date), endsAt($date)the time range the entry describes

Each role method takes a role value. An entry has no from() target alias: Entry::from() reads the array form.

Role Values ​

ValueExampleIn the Payload
a Feedable model$projectthe model's entity, from toFeed() and feedMedia() when the feed is read
a party name'Storyfeed'a party entity, type: "storyfeed.entity"
an entity with no model['type' => 'release', 'label' => 'v0.18.0']an entity with that type and label

A model that is not Feedable throws an InvalidArgumentException. An entity array takes these keys; any other throws:

KeyValue
typethe entity's type; required
labelthe entity's label; required
idthe entity's id; defaults to the label
urlthe entity's link
datavalues carried with the entity
bodythe entity's bodies
mediaicon, image and preview, each a URL, a FeedImage or its array form (src, mediaType, width, height, alt); and initials and color for its avatar

An Image or MediaObject body that names a slot the entity's media doesn't declare throws an InvalidArgumentException when the entry is added.

Headline Replacements ​

A replacement whose key names a role sets that role, as its method would: ['actor' => $user] is ->by($user). Any other key is replaced in the text when the entry is added, as :key, :Key or :KEY.

MistakeResult
a model under a key that is not a roleInvalidArgumentException
a headline naming a role the entry leaves empty, outside an optional [ ] segmentInvalidArgumentException

An entry's own headline wins over the feed file's. An entry with a verb and no headline reads the verb's headline from the feed file.

Named Arguments ​

Entry::make() takes the same values as named arguments:

app/Sources/GitHubSource.phpitems()
php
use Storyfeed\Sources\Entry;

yield Entry::make(
    verb: 'ship',
    publishedAt: $release['published_at'],
    actor: 'Storyfeed',
    object: ['type' => 'release', 'label' => $release['tag_name']],
);
ArgumentMatches
verb, publishedAtverb(), publishedAt(); both optional
actor, object, target, context, origin, result, instrument, location, generatorthe role methods
data, body, iddata(), body(), id()
startsAt, endsAtstartsAt(), endsAt()

Entry::make() takes no headline: call headline() on the entry it returns.

Array Form ​

Entry::from($array) reads an entry from an array, as an array source does for each item:

KeyMatches
verb, headline, published_atverb(), headline() with no replacements, publishedAt(); all optional
actor, object, target, context, origin, result, instrument, location, generatorthe role methods
data, body, iddata(), body(), id()
starts_at, ends_atstartsAt(), endsAt()

Any other key throws an InvalidArgumentException.

Released under the MIT License.