Skip to main content

Overview

Namespace: FQL\Stream Stream\Provider opens a data file or an in-memory string and returns a stream object. Each stream implements Interface\Stream and exposes a query() method that returns a Query ready to run against that stream. You rarely need to call stream classes directly — Query\Provider::fromFile() wraps Stream\Provider automatically. Use Stream\Provider directly when you need to configure the stream (e.g. set a custom CSV delimiter) before building a query.

Stream\Provider static methods

fromFile()

Open a file and return the matching stream object. The format is detected from the file extension unless $format is provided.
public static function fromFile(string $path, ?Enum\Format $format = null): Interface\Stream
path
string
required
Absolute or relative path to the data file.
format
FQL\Enum\Format | null
Override the auto-detected format.
returns
FQL\Interface\Stream
A concrete stream instance (e.g. Json, Csv, Xml).
Throws: FileNotFoundException, InvalidFormatException
use FQL\Stream\Provider;
use FQL\Enum\Format;

$stream = Provider::fromFile('data/products.json');
$query  = $stream->query();

// Force a format
$stream = Provider::fromFile('data/export', Format::CSV);

fromString()

Create a stream from an in-memory string. Supported formats: JSON, YAML, NEON.
public static function fromString(string $data, Enum\Format $format): Interface\Stream
data
string
required
The raw string content to parse.
format
FQL\Enum\Format
required
The format of the string content. Must be Format::JSON, Format::YAML, or Format::NEON.
returns
FQL\Interface\Stream
A stream wrapping the parsed string.
Throws: InvalidFormatException for unsupported formats (e.g. XML, CSV).
use FQL\Stream\Provider;
use FQL\Enum\Format;

$json = '{"users": [{"id": 1, "name": "Alice"}]}';

$results = Provider::fromString($json, Format::JSON)
    ->query()
    ->from('users')
    ->execute();

Stream classes

Each stream class can also be instantiated directly via its static open() method. After obtaining a stream instance, call ->query() to get a Query.

Xml

Class: FQL\Stream\Xml
Formats: .xml
public static function open(string $path): Interface\Stream
use FQL\Stream\Xml;

$query = Xml::open('catalog.xml')
    ->query()
    ->from('catalog.book');
For XML files with non-UTF-8 encoding, call ->setInputEncoding('windows-1250') on the stream before calling ->query().

Json

Class: FQL\Stream\Json
Formats: .json (full in-memory parse)
public static function open(string $path): Interface\Stream
Loads the entire JSON file into memory. Use JsonStream for large files.
use FQL\Stream\Json;

$query = Json::open('users.json')
    ->query()
    ->from('data.users');

JsonStream

Class: FQL\Stream\JsonStream
Formats: .json (streaming, lazy)
public static function open(string $path): Interface\Stream
Streams large JSON files row-by-row without loading the entire file into memory.
use FQL\Stream\JsonStream;

$query = JsonStream::open('large-catalog.json')->query();

NDJson

Class: FQL\Stream\NDJson
Formats: .ndjson (Newline Delimited JSON)
public static function open(string $path): Interface\Stream
Each line in the file must be a valid JSON object.
use FQL\Stream\NDJson;

$query = NDJson::open('events.ndjson')->query();

Csv

Class: FQL\Stream\Csv
Formats: .csv, .tsv
public static function open(string $path): Interface\Stream
path
string
required
Path to the CSV file.
Default delimiter is ,. To use a custom delimiter, call openWithDelimiter() directly, or use fromFileQuery() with query parameters.
use FQL\Stream\Csv;

// Default comma delimiter
$query = Csv::open('orders.csv')->query();

// Custom delimiter
$query = Csv::openWithDelimiter('orders.tsv', "\t")->query();
// Via FileQuery string with custom delimiter
use FQL\Query\Provider;

$query = Provider::fromFileQuery('csv(orders.csv, ";").*');

Yaml

Class: FQL\Stream\Yaml
Formats: .yaml, .yml
public static function open(string $path): Interface\Stream
use FQL\Stream\Yaml;

$query = Yaml::open('config.yaml')->query()->from('services');

Neon

Class: FQL\Stream\Neon
Formats: .neon
public static function open(string $path): Interface\Stream
NEON is the configuration format used by the Nette framework.
use FQL\Stream\Neon;

$query = Neon::open('config.neon')->query();

Xls

Class: FQL\Stream\Xls
Formats: .xls, .xlsx
public static function open(string $path): Interface\Stream
use FQL\Stream\Xls;

$query = Xls::open('report.xlsx')->query()->from('Sheet1');

Ods

Class: FQL\Stream\Ods
Formats: .ods
public static function open(string $path): Interface\Stream
use FQL\Stream\Ods;

$query = Ods::open('spreadsheet.ods')->query();

Dir

Class: FQL\Stream\Dir
Formats: dir
public static function open(string $path): Interface\Stream
Treats a directory as a data source. Each file in the directory becomes a row.
use FQL\Stream\Dir;

$query = Dir::open('/var/log/')->query();

query() method

All stream classes inherit query() from AbstractStream.
public function query(): FQL\Query\Query
Returns a fresh Query bound to this stream. See the Query\Provider reference for the full fluent API.
use FQL\Stream\Json;
use FQL\Enum\Operator;

$results = Json::open('products.json')
    ->query()
    ->select('id', 'name', 'price')
    ->from('products')
    ->where('price', Operator::LESS_THAN, 50)
    ->limit(20)
    ->execute();