Helpers

Introduction

The Streams Platform includes a variety of global "helper" PHP functions. Many of these functions are used by the platform itself; however, you are free to use them in your own applications if you find them convenient.

This documentation assumes you are familiar with Laravel helpers.

app_storage_path

The app_storage_path function returns the fully qualified path to the application's unique storage directory. You may also use the app_path function to generate a fully qualified path to a file relative to the application directory:

$path = app_storage_path();

$path = app_storage_path('addons/redirects/routes.php');

str_humanize

The str_humanize function returns humanized string.

str_humanize('example_slug');
// example slug

str_humanize('ExampleClass');
// example class

parse

The parse function returns a parsed string using simple dot value parsing.

parse($string, $data);

echo parse('Welcome {username}', $user);

The parse Twig function simulates render function below.

render

The render function returns a rendered template string with optional payload data using the view engine.

render($template, $payload);

echo render('Welcome {{ user().username }}');

filesize_for_humans

The filesize_for_humans returns the provided bytes as a human readable filesize string.

 filesize_for_humans($bytes, $decimals = 2)

 echo filesize_for_humans(5000000, 1);
 // 500 kB