Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC Implementation] Merge Router into Core #254

Merged
merged 9 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "leafs/leaf",
"description": "Simple, performant and powerful PHP micro-framework for rapid web app & API development",
"description": "Elegant PHP for modern developers",
"keywords": [
"microframework",
"rest",
Expand Down Expand Up @@ -33,7 +33,6 @@
"require": {
"php": "^7.4|^8.0",
"leafs/http": "*",
"leafs/router": "*",
"leafs/anchor": "*",
"leafs/exception": "*"
},
Expand Down
42 changes: 24 additions & 18 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@ public function __construct(array $userSettings = [])
protected function loadConfig(array $userSettings = [])
{
if (!empty($userSettings)) {
Config::set($userSettings);
Config::set(array_merge($userSettings, [
'mode' => _env('APP_ENV', Config::getStatic('mode')),
]));
}

$this->setupDefaultContainer();
$this->loadViewEngines();
}

protected function setupErrorHandler()
Expand Down Expand Up @@ -90,22 +91,6 @@ public function register($name, $value)
Config::singleton($name, $value);
}

/**
* This method loads all added view engines
*/
public function loadViewEngines()
{
$views = View::$engines;

if (!empty($views)) {
foreach ($views as $key => $value) {
Config::singleton($key, function () use ($value) {
return $value;
});
}
}
}

private function setupDefaultContainer()
{
Config::singleton('request', function () {
Expand Down Expand Up @@ -202,6 +187,27 @@ public function cors($options = [])
}
}

/**
* Add CSRF protection to your app
*
* @param array $options Config for csrf
*/
public function csrf($options = [])
{
if (!\class_exists('Leaf\Anchor\CSRF')) {
\trigger_error('CSRF module not found! Run `leaf install csrf` or `composer require leafs/csrf` to install the CSRF module. This is required to configure CSRF.');
}

if (!Anchor\CSRF::token()) {
Anchor\CSRF::init();
Anchor\CSRF::config($options);
}

$this->use(function () {
Anchor\CSRF::validate();
});
}

/**
* Create a route handled by websocket (requires Eien module)
*
Expand Down
2 changes: 1 addition & 1 deletion src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Config
'log.level' => null,
'log.enabled' => false,
'log.dir' => __DIR__ . '/../../../../storage/logs/',
'log.file' => 'log.txt',
'log.file' => 'app.log',
'log.open' => true,
'mode' => 'development',
'scripts' => [],
Expand Down
80 changes: 0 additions & 80 deletions src/Middleware.php

This file was deleted.

Loading
Loading