https://github.com/broneq/minifw
MiniFw - Mini framework inspired by Phalcon framework
https://github.com/broneq/minifw
framework framework-php php7
Last synced: 11 months ago
JSON representation
MiniFw - Mini framework inspired by Phalcon framework
- Host: GitHub
- URL: https://github.com/broneq/minifw
- Owner: broneq
- License: mit
- Created: 2018-09-24T19:14:40.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-02-22T08:07:07.000Z (almost 7 years ago)
- Last Synced: 2025-01-12T13:24:47.453Z (about 1 year ago)
- Topics: framework, framework-php, php7
- Language: PHP
- Size: 19.5 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
README
**MiniFw - Mini framework inspired by Phalcon framework**
Framework inspired by Phalcon to do simple thinks on not dedicated servers.
**Usage**
composer install broneq/miniFW
```
use MiniFwSample\Config\Sample;
include __DIR__.'/Lib/Autoloader.php';
$autoloader = new \MiniFw\Lib\Autoloader();
$autoloader->registerNamespace('MiniFw', __DIR__.'/pathtovendor');
$autoloader->registerNamespace('SomeOtherNameSpace', __DIR__.'/otherdir');
try {
new Sample();
} catch (Exception $e) {
http_response_code(500);
echo 'FATAL: ' . $e->getMessage();
}
```
*Sample config*
```
namespace MiniFwSample\Config;
use MiniFw\Lib\Auth;
use MiniFw\Lib\Db;
use MiniFw\Lib\Di\BaseConfig;
use MiniFw\Lib\Di\Dependency;
use MiniFw\Lib\Router;
use MiniFw\Lib\View;
class Sample extends BaseConfig
{
/**
* Sample constructor.
* @throws \Exception
*/
public function __construct()
{
$this->addDependency((new Dependency('auth', Auth::class))
->addCall('addUser', 'broneq', 'sha1password')
->addCall('authRequest'));
//
$this->addDependency((new Dependency('router', Router::class))
->addParameter('\'MiniFwSample\Controller\\')
->addCall('registerNotFoundAction', function () {
header("HTTP/1.0 404 Not Found");
echo "Page not found.\n";
die();
})
->addCall('registerDefaultController', 'index')
->addCall('handle', $_GET)
);
//
$this->addDependency((new Dependency('db', Db::class))
->addParameter(__DIR__ . '/../db.sqlite'));
//
$this->addDependency((new Dependency('view', View::class))
->addParameter(__DIR__ . '/../tpl'));
//
//
$this->autorun('auth');
$this->autorun('router');
$this->autorun('view');
//
$this->build();
}
}
```
*Sample controller*
```
class File extends BaseController
{
public function indexAction(): void
{
$this->view->render('file/list', ['data' => ['title'=>'test']);
}
}
```
*Sample model*
```
class InquiryFile extends BaseModel
{
public $inquiry_id;
public $title;
public $file_name;
public $file;
protected function sanitize(): void
{
if ($this->id) {
$this->id = (int)$this->id;
}
$this->inquiry_id = (int)$this->inquiry_id;
if (!$this->inquiry_id) {
throw new \ErrorException('No inquiry_id provided');
}
$this->title = strip_tags(trim($this->title), ENT_QUOTES);
$this->file_name = strip_tags(trim($this->file_name), ENT_QUOTES);
}
}
```
*Issues*
If you are using PHP running in CGI mode you have to add rule to your .htaccess file:
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]