fernet / fernet
The Fernet Framework
Installs: 53
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 0
Open Issues: 0
Language:CSS
Type:project
Requires
- fakerphp/faker: ^1.14
- fernet/doctrine: ^0.3
- fernet/framework: ^0.3
README
A component based PHP Framework.
Set up
To install use composer create project command:
composer create-project fernet/fernet /path/to/app
You can use the php built in server to run the app:
php -S 127.0.0.1:14567 -t public
Then go to 127.0.0.1:14567.
Component
Fernet component are inspired by React component. They are a PHP class with a __toString method that returns the HTML the component will render. The class needs to be created in the src/Component/ folder. The namespace should be App\Component. Let's create a simple component that said Hi.
src/Component/Hello.php
<?php declare(strict_types=1); namespace App\Component; class Hello { public string $name; public function __toString(): string { return "<p>Hi {$this->name}!</p>"; } }
To use this new component go to the file src/Component/App.php and use it like a custom HTML tag.
// There are more code here, let's focus only on the toString method public function __toString(): string { \ob_start(); ?> <html lang="en"> <body> <p>Check out this very original example</p> <Hello name="World" /> </body> </html><?php return \ob_get_clean(); }
The functions ob_start and ob_get_clean are used to get the printed code. We used this trick when we have a lot of HTML to render. Like many other things used in Fernet this is PHP native. The rest of course is old plain HTML.