PHPackages                             dmvdigital/phpsfc - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. dmvdigital/phpsfc

ActiveLibrary

dmvdigital/phpsfc
=================

PHP Single File Components: CSS, JS, and HTML sections in one PHP file, Vue-SFC style.

v1.0.0(yesterday)20MITPHP ^8.1

Since Jul 19Compare

[ Source](https://github.com/dmvdigital/phpsfc)[ Packagist](https://packagist.org/packages/dmvdigital/phpsfc)[ RSS](/packages/dmvdigital-phpsfc/feed)WikiDiscussions Synced today

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

phpsfc
======

[](#phpsfc)

[![tests](https://github.com/dmvdigital/phpsfc/actions/workflows/tests.yml/badge.svg)](https://github.com/dmvdigital/phpsfc/actions/workflows/tests.yml)[![Packagist Version](https://camo.githubusercontent.com/f548c9bc974977259c79698140fc548f5d0595b6f49c1e43a3fe5be03f9f42ea/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f646d766469676974616c2f706870736663)](https://packagist.org/packages/dmvdigital/phpsfc)[![License](https://camo.githubusercontent.com/b8cadaa967891081f8f165695470689986c028821dd8a040132f6e661795dc0d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c7565)](LICENSE)

**PHP Single File Components**: CSS, JS, and HTML sections in one `.php` file, Vue-SFC style, no build step.

```

.__self { padding: 1rem; }

Hello,
```

```
$engine = new Phpsfc\Engine($componentsDir, $cacheDir);
echo $engine->render('widgets/hello', ['name' => 'World']);
```

Install
-------

[](#install)

```
composer require dmvdigital/phpsfc

```

Requires PHP 8.1+.

For the full method reference, file-format grammar, caching internals, and security model, see [DOCUMENTATION.md](DOCUMENTATION.md). Using an AI coding agent to write components? Point it at [AGENTS.md](AGENTS.md) first.

Quickstart
----------

[](#quickstart)

A component is referenced by its path, extension omitted, no separately invented name:

```
$engine->render('sections/hero-animated', ['title' => 'Hello']);
$engine->component('widgets/card')->set('title', 'Getting Started');
```

A page needs a layout's shell but also needs to hand its own sections into that shell, that's what `extends`/`load` and `slot()`/`block()`/`files()` are for:

```

page body
```

```
