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

Leaf MVC Core v4.x #23

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
[![Total Downloads](https://poser.pugx.org/leafs/mvc-core/downloads)](https://packagist.org/packages/leafs/mvc-core)
[![License](https://poser.pugx.org/leafs/mvc-core/license)](https://packagist.org/packages/leafs/mvc-core)

This is the heart of Leaf MVC. It serves as a bridge between Leaf and the MVC file structure. It provides a ton of functionality that makes it easy to build a full-blown MVC application with Leaf.
Leaf MVC Core is the heart of Leaf MVC and serves as bridge between Leaf, modules and the MVC file structure. It provides a ton of extra functionality like extra globals, classes and methods that help with separation of concerns and building a full-blown MVC application with Leaf.

## 📦 Installation

Expand All @@ -32,12 +32,9 @@ composer require leafs/mvc-core
MVC Core comes with:

- Controllers
- Api Controllers
- Database & Models
- Factories
- Models
- Schemas
- Database & Model functionalities
- Tons of MVC and module globals
- Autoloading directory files

Since you don't use this package on its own, the documentation is covered in the [Leaf MVC documentation](https://leafphp.dev/docs/mvc/).

Expand Down
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,16 @@
]
},
"minimum-stability": "dev",
"prefer-stable": true,
"prefer-stable": true,
"require": {
"leafs/leaf": "*",
"doctrine/dbal": "^3.2",
"vlucas/phpdotenv": "^5.4",
"illuminate/database": "^8.75",
"illuminate/events": "^8.75"
"illuminate/events": "^8.75",
"symfony/yaml": "^6.4"
},
"require-dev": {
"fakerphp/faker": "^1.24"
}
}
49 changes: 1 addition & 48 deletions src/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,54 +66,7 @@ public function id()
*/
public function view(string $view, array $data = [])
{
/// WILL REFACTOR IN NEXT VERSION

if (is_object($data)) {
$data = (array) $data;
}

if (ViewConfig('render')) {
if (ViewConfig('config')) {
call_user_func_array(ViewConfig('config'), [[
'views' => AppConfig('views.path'),
'cache' => AppConfig('views.cachePath'),
]]);
}

return ViewConfig('render')($view, $data);
}

$engine = ViewConfig('viewEngine');
$className = strtolower(get_class(new $engine));

$fullName = explode('\\', $className);
$className = $fullName[count($fullName) - 1];

if (\Leaf\Config::getStatic("views.$className")) {
if (ViewConfig('config')) {
call_user_func_array(ViewConfig('config'), [[
'views' => AppConfig('views.path'),
'cache' => AppConfig('views.cachePath'),
]]);
} else {
\Leaf\Config::get("views.$className")->configure(AppConfig('views.path'), AppConfig('views.cachePath'));
}

return \Leaf\Config::get("views.$className")->render($view, $data);
}

$engine = new $engine($engine);

if (ViewConfig('config')) {
call_user_func_array(ViewConfig('config'), [[
'views' => AppConfig('views.path'),
'cache' => AppConfig('views.cachePath'),
]]);
} else {
$engine->config(AppConfig('views.path'), AppConfig('views.cachePath'));
}

return $engine->render($view, $data);
return view($view, $data);
}

/**
Expand Down
54 changes: 38 additions & 16 deletions src/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static function loadApplicationConfig()
Config::getStatic('mvc.config.auth')['session'] ?? false
);

if ($csrfConfig['enabled'] ?? null !== null) {
if (($csrfConfig['enabled'] ?? null) !== null) {
$csrfEnabled = $csrfConfig['enabled'];
}

Expand All @@ -65,25 +65,47 @@ public static function loadApplicationConfig()
\Leaf\Vite::config('hotFile', 'public/hot');
}

Config::attachView(ViewConfig('viewEngine'), 'template');

if (ViewConfig('config')) {
call_user_func_array(ViewConfig('config'), [
app()->template(),
[
if (ViewConfig('viewEngine')) {
Config::attachView(ViewConfig('viewEngine'), 'template');

if (ViewConfig('config')) {
call_user_func_array(ViewConfig('config'), [
app()->template(),
[
'views' => AppConfig('views.path'),
'cache' => AppConfig('views.cachePath'),
]
]);
} else if (method_exists(app()->template(), 'configure')) {
app()->template()->configure([
'views' => AppConfig('views.path'),
'cache' => AppConfig('views.cachePath'),
]
]);
} else if (method_exists(app()->template(), 'configure')) {
app()->template()->configure([
'views' => AppConfig('views.path'),
'cache' => AppConfig('views.cachePath'),
]);
]);
}

if (is_callable(ViewConfig('extend'))) {
call_user_func(ViewConfig('extend'), app()->template());
}
}

if (DatabaseConfig('sync')) {
\Leaf\Database::initDb();
}

if (storage()->exists(LibPath())) {
static::loadLibs();
}

if (
class_exists('Leaf\Billing\Stripe') ||
class_exists('Leaf\Billing\PayStack') ||
class_exists('Leaf\Billing\LemonSqueezy')
) {
billing(Config::getStatic('mvc.config.billing'));
}

if (is_callable(ViewConfig('extend'))) {
call_user_func_array(ViewConfig('extend'), app()->template());
if (storage()->exists('app/index.php')) {
require 'app/index.php';
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static function connect()
static::$capsule->bootEloquent();

if (php_sapi_name() === 'cli') {
Schema::$capsule = static::$capsule;
Schema::setDbConnection(static::$capsule);
}
}

Expand Down
184 changes: 0 additions & 184 deletions src/Factory.php

This file was deleted.

Loading