Sophisticated, Lightweight and Simple

Jump to docs navigation
Edit on GitHub

Note: You are currently reading the documentation for Bolt 3.0. Looking for the documentation for Bolt 3.2 instead?

Extending » Filesystem Layer » Using file type handlers

Getting a file with an image handler

    /** @var \Bolt\Filesystem\Handler\ImageInterface $file */
    $file = $filesystem->getImage($path);


Variable Type Description
$path string Relative path to the file

Specific file type handler

To use a specific HandlerInterface for the object returned by get, you can pass in an instance of a \Bolt\Filesystem\Handler\HandlerInterface class.

e.g. Someone gave you a JSON file called, and you wish for it to be handled natively as a JSON file:

    /** @var \Bolt\Filesystem\Handler\HandlerInterface $handler */
    $handler = \Bolt\Filesystem\Handler\JsonFile();

    $object = $filesystem->get('relative/path/', $handler);

    // As $object is a JSON handled file, we can parse it to PHP.
    $data = $object->parse();

    $data['updated'] = time();

    // We can also dump the updated PHP array back to a JSON file.

Couldn't find what you were looking for? We are happy to help you in the forum, on Slack or on IRC.
Spotted a typo, or have something to add? Edit this page on GitHub.