Framework developed in "pure" PHP by valuing the ease of working with PHP version 8.2.1 Object Object Programming (POO) . This framework is made up of Model View Controller (MVC) architecture that promotes easy modularity, scalability and maintenance of web systems.
#framework #php #mvc
composer install
php cli -d set
php cli -d load
Main doubts about the framework:
The scheme of your database should be in the database/schema folder, where all table files must be separated into the ASC creation order.
Up and Down methods are defined for interaction with terminal commands, ie UP method serves to climb this interaction to the bank, while the Down method to drop this interaction to the bank. To define a new table you must follow the standardization below the UP method , where to set new columns the table must only assign a new variable $ table by calling a method of the desired data type.
Example UP Method:
public function up(): void
{
(new Database)->create('nomeDaTabela', function(Blueprint $table) {
$table->id();
$table->varchar('nomeDaColuna', 100)->notNull();
});
}
Down Method Example:
public function down(): void
{
(new Database)->dropIfExists('nomeDaTabela');
}
Data insertion files should be in the database/information folder, where all table files must be separated into ASC Creation Order.
As with table creation, you must also define the up and down methods .
Example UP Method:
public function up(): void
{
(new Database('nomeDaTabela'))->insert([
'nomeDaColuna' => 'valor a ser inserido'
]);
}
Down Method Example:
public function down(): void
{
(new Database('nomeDaTabela'))->delete('id = 1 ');
}
.
| Base | Command | Argument | Function |
|---|---|---|---|
| PHP CLI | -DB | set | Loads database/schema tables in the database. |
| PHP CLI | -DB | Drop | Drop the database/schema tables in the database. |
| PHP CLI | -DB | reset | Recharge the database/schema tables in the database. |
| PHP CLI | -DB | load | Insert the information database/information to the database. |
| PHP CLI | -DB | fresh | Removes database/information information from the database. |
| Base | Command | Argument | Function |
|---|---|---|---|
| PHP CLI | -BUILD | controller | Creates a new controller in the app/Controller folder. |
| PHP CLI | -BUILD | model | Creates a new model in the app/Model/Entity folder. |
| PHP CLI | -BUILD | table | Creates a new table in the database/schema folder. |
Utility: To make it easier if you put the argumento:diretorio will be created a new renamed file.
.
Framework routes are in the application routes folder.
EXAMPLE COMMON ROUND GET:
$obRouter->get('/url/exemplo', [
function($request) {
return new Response(200, PagesHomeController::get($request));
}
]);
Example Dynamic Put Route:
$obRouter->put('/url/exemplo/{id}', [
function($request, $id) {
return new Response(200, PagesHomeController::edit($request, $id));
}
]);
Example Rota with Middleware Post:
$obRouter->post('/url/exemplo', [
'middlewares' => [
'basic-auth'
],
function($request) {
return new Response(200, PagesHomeController::set($request));
}
]);
.
Requisitions have some methods that can be accessed by Controller by default:
How to access these methods?
GetPostvars example:
public function metodoExemplo(Request $request): void
{
$request->getPostVars();
}
.
Models should be inside the app/Model/Entity folder.
Every model has 4 methods by default:
Declaration of a Model Class: Every model must be generated to hold a specific table.
Class Example:
class Post
{
public int $id; // coluna id associada no banco
public string $title; // coluna title associada no banco
public string $content; // coluna content associada no banco
public function create(): bool
{
$this->id = (new Database('post'))->insert([
'title' => $this->title, // referenciando nome da coluna com o valor
'content' => $this->content
]);
return true;
}
}
Example Create Method:
public function create(): bool
{
$this->id = (new Database('nomeDaTabela'))->insert([
'nomeDaColuna' => $this->atributoDaClasse
]);
return true;
}
Example UPDATE METHOD:
public function update(): bool
{
return (new Database('nomeDaTabela'))->update('nomeDaColuna = '.$this->atributoDaClasse, [
'nomeDaColuna' => $this->atributoDaClasse
]);
}
Example Delete Method:
public function delete(): bool
{
return (new Database('nomeDaTabela'))->securityDelete('nomeDaColuna = '.$this->atributoDaClasse);
}
EXAMPLE GET METHOD:
public static function getTableName(
string $where = null,
string $order = null,
string $limit = null,
string $fields = '*'
): PDOStatement
{
return (new Database('nomeDaTabela'))->select($where, $order, $limit, $fields);
}
.
Middleware is the intermediaries of the route and are in the app/Http/Middleware folder of the application, they are configured in the include/app.php file where one must specify a single name for each middleware.
All middleware must have a default method:
Middleware Example:
class MiddlewareExemplo
{
private function checkStatus(Request $request): void
{
$vars = $request->getPostVars();
if ($vars['status'] == 'error') {
throw new Exception("A página está com erro");
}
}
public function handle(Request $request, Closure $next): Response
{
$this->checkStatus($request); // se o status não estiver com erro carrega a aplicação
return $next($request);
}
}
Setting Middleware:
MiddlewareQueue::setMap([
'middleware-exemplo' => AppHttpMiddlewareMiddlewareExemplo::class
]);
.
View serves to render variables declared in the HTML to be replaced by content from the database.
Example rendering View content:
public static function getPage(): string
{
// diretorio da pasta: resources/view
return View::render('pasta/exemploArquivoHtml', [
'nomeDaVariavel' => $conteudoAlterado
]);
}
.
Controllers should be inside the app/Controller folder.
Every controller has 5 methods by default:
EXAMPLE GET METHOD:
public static function get(): array
{
$itens = [];
$results = EntityExemplo::getExemplos(); // model Exemplo
while($obExemplo = $results->fetchObject(EntityExemplo::class)) {
$itens[] = [
'nomeDaColuna' => $obExemplo->atributoDaClasse
];
}
return $itens;
}
EXAMPLE POST METHOD:
public static function set(Request $request): bool
{
$vars = $request->getPostVars();
$obExemplo = new EntityExemplo;
$obExemplo->atributoDaClasse = $vars['valorPost'];
$obExemplo->create();
return true;
}
Example Delete Method:
public static function delete(Request $request, int $id): bool
{
$vars = $request->getPostVars();
$obExemplo = EntityExemplo::getExemplos('nomeDaColuna = '.$id); // busca o valor pelo id
$obExemplo->delete();
return true;
}
The framework configuration file is in the includes/app.php folder of the application.
In the app.php file is configured: