Search by

phore / filesystem

dermatthes

Acces files layer

Package info

github.com/phore/phore-filesystem

Homepage

pkg:composer/phore/filesystem

Statistics

Installs: 13 822

Dependents: 36

Suggesters: 1

Stars: 1

Open Issues: 0

1.1.2 2026-09-11 12:53 UTC

This package is auto-updated.

Last update: 2026-09-29 23:04:06 UTC


README

Actions Status

File access functions

Version 2

Version 2 requires PHP 8.5 or newer and introduces explicit filesystem security policies. New filesystem entry points follow symbolic links by default, matching normal filesystem behavior. With rootDir set, resolved symlink targets must stay inside that root. Root-bound objects carry their security context through derived files, directories, walks and streams.

The current v1 release line remains v1.1.x; this pull request prepares v2.0.0.

  • Working with sub-paths
  • Checking symbolic links

Installation

composer require phore/filesystem:^2.0

Security-first usage

$root = phore_dir('/srv/site/docs', [
    'rootDir' => '/srv/site/docs',
]);

$page = $root->withSubPath('index.md')->asFile();
echo $page->get_contents();

The default is followSymlinks=true. Set rootDir when access must stay inside a bounded tree; symlinks may then be followed only when their resolved target remains inside that root. Use followSymlinks=false for an explicit no-symlink policy.

General usage

echo phore_uri("/tmp/some.file")->withDirName();

will result in

/tmp

Subpath

echo phore_uri("/tmp")->withSubPath("./some/other/file")
/tmp/some/other/file

Assertions

phore_uri("/tmp")->assertIsFile()->assertIsWritable();

Reading YAML

phore_uri("/tmp/somefile.yml")->assertFile()->get_yaml();

Front matter files

Jekyll-style YAML front matter can be read together with the remaining content:

$document = phore_file("post.md")->get_front_matter();
echo $document->header["title"];
echo $document->content;

Pass a class name to hydrate the header when phore/hydrator is installed:

$document = phore_file("post.md")->get_front_matter(PostHeader::class);
echo $document->header->title;

Create or replace a front matter file with put_front_matter():

phore_file("post.md")->put_front_matter(
    new \Phore\FileSystem\FrontMatterFile(null, ["title" => "Example"], "Content")
);

Tempoary Files

Will be unlinked when object destructs.

$file = new PhoreTempFile();