Sources

Introduction

Source adapters helps you query any source of data you might encounter in the wild.

Defining Sources

Specify source information in your stream configuration.

If no source is specified, the below defaults will be assumed.

// streams/{handle}.json
{
    "source": {
        "format": "json",
        "type": "filebase",
        "path": "streams/data/{handle}"
    }
}

Available Sources

The following sources are available with the Streams platform by default.

Self

You can define data within on your stream configuration file.

// streams/contacts.json
{
    "source": {
        "type": "self"
    },
    "data": {
        "john": {
            "name": "John Doe"
        },
        "jane": {
            "name": "Jane Doe"
        }
    }
}

Filebase

The flat file database powered by the fantastic Filebase package is the default source.

// streams/contacts.json
{
    ...
    "source": {
        "format": "json",
        "type": "filebase",
        "path": "streams/data/contacts",
        "prototype": "Streams\\Core\\Entry\\Entry"
    }
}

JSON Format

// streams/data/contacts/ryan.json
{
    "name": "Ryan",
    "email": "[email protected]"
}

YAML Format

// streams/data/contacts/ryan.yaml

---

name: "Ryan"
email: "[email protected]"

---

The body is built in: {{ $entry->name }}

MD Format

// streams/data/contacts/ryan.md

---

name: "Ryan"
email: "[email protected]"

---

The body is built in: {{ $entry->name }}

TPL Format

// streams/data/contacts/ryan.tpl

---

name: "Ryan"
email: "[email protected]"

---

The body is built in: {{ $entry->name }}

Eloquent Model

The eloquent model source uses Laravel models to query and can return stream-enhanced Eloquent models.

// streams/contacts.json
{
    "source": {
        "type": "eloquent",
        "model": "App\\Contact\\ContactModel"
    }
}

Laravel Database

The Laravel database source uses generic Laravel database tables to query and return stream entries.

// streams/contacts.json
{
    "source": {
        "type": "database",
        "table": "contacts",
        "connection": "default",
        "prototype": "Streams\\Core\\Entry\\Entry"
    }
}

Extending

You can create and register a custom source adapter for any source of information you might encounter.

Custom Sources

@todo Talk about developing custom source adapters.