PHP code example of broneq / minifw
1. Go to this page and download the library: Download broneq/minifw library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
broneq / minifw example snippets
use MiniFwSample\Config\Sample;
toloader();
$autoloader->registerNamespace('MiniFw', __DIR__.'/pathtovendor');
$autoloader->registerNamespace('SomeOtherNameSpace', __DIR__.'/otherdir');
try {
new Sample();
} catch (Exception $e) {
http_response_code(500);
echo 'FATAL: ' . $e->getMessage();
}
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();
}
}
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);
}
}