Skip to content

Commit e8b1792

Browse files
authored
Merge pull request #27 from leafsphp/feat/schema-module
Feat/schema module
2 parents cd1d9d5 + f45f90a commit e8b1792

File tree

329 files changed

+18464
-621
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

329 files changed

+18464
-621
lines changed

README.md

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,21 @@
1111
[![Total Downloads](https://poser.pugx.org/leafs/mvc-core/downloads)](https://packagist.org/packages/leafs/mvc-core)
1212
[![License](https://poser.pugx.org/leafs/mvc-core/license)](https://packagist.org/packages/leafs/mvc-core)
1313

14-
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.
14+
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, console commands and methods that help with separation of concerns and building a full-blown MVC application with Leaf.
1515

16-
## 📦 Installation
16+
It ships with all Leaf MVC applications and is not meant to be used on its own.
1717

18-
You can quickly get leaf mvc core up and running with the leaf cli
19-
20-
```sh
21-
leaf install mvc-core
22-
```
23-
24-
or with composer
25-
26-
```bash
27-
composer require leafs/mvc-core
28-
```
29-
30-
## 🧩 Components
18+
## 🧩 Features
3119

3220
MVC Core comes with:
3321

34-
- Controllers
35-
- Database & Model functionalities
36-
- Tons of MVC and module globals
22+
- Base Controllers
23+
- Shortcuts for views and layouts
24+
- Console commands for generating files/layouts/modules
25+
- Automatic module loading
26+
- Config loading for MVC apps
3727
- Autoloading directory files
38-
39-
Since you don't use this package on its own, the documentation is covered in the [Leaf MVC documentation](https://leafphp.dev/docs/mvc/).
28+
- Basically everything that gives Leaf it's MVC superpowers
4029

4130
## 💬 Stay In Touch
4231

composer.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@
3535
"prefer-stable": true,
3636
"require": {
3737
"leafs/leaf": "*",
38-
"vlucas/phpdotenv": "^5.4",
39-
"illuminate/database": "^8.75|^10.0|^12.0",
40-
"illuminate/events": "^8.75|^10.0|^12.0",
41-
"symfony/yaml": "^5.4|^6.4",
42-
"leafs/db": "*"
38+
"vlucas/phpdotenv": "*",
39+
"illuminate/support": "*",
40+
"illuminate/database": "*",
41+
"illuminate/events": "*",
42+
"symfony/yaml": "*",
43+
"leafs/db": "*",
44+
"leafs/sprout": "^0.7.0"
4345
},
4446
"require-dev": {
4547
"fakerphp/faker": "^1.24"

src/Commands/AppDownCommand.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Leaf\Commands;
4+
5+
use Leaf\Sprout\Command;
6+
7+
class AppDownCommand extends Command
8+
{
9+
protected $signature = 'app:down';
10+
protected $description = 'Place app in maintenance mode';
11+
protected $help = 'Set app in maintenance mode';
12+
13+
protected function handle()
14+
{
15+
$file = getcwd() . DIRECTORY_SEPARATOR . '.env';
16+
17+
$fileContent = file_get_contents($file);
18+
$fileContent = str_replace(
19+
['APP_DOWN=false', 'APP_DOWN = false'],
20+
'APP_DOWN=true',
21+
$fileContent
22+
);
23+
24+
file_put_contents($file, $fileContent);
25+
26+
$this->comment('App now running in down mode...');
27+
$this->info('You might need to restart your server to see changes');
28+
29+
return 0;
30+
}
31+
}

src/Commands/AppUpCommand.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Leaf\Commands;
4+
5+
use Leaf\Sprout\Command;
6+
7+
class AppUpCommand extends Command
8+
{
9+
protected $signature = 'app:up';
10+
protected $description = 'Remove app from maintenance mode';
11+
protected $help = 'Set app in normal mode';
12+
13+
protected function handle()
14+
{
15+
$env = getcwd() . DIRECTORY_SEPARATOR . '.env';
16+
17+
$envContent = file_get_contents($env);
18+
$envContent = str_replace(
19+
['APP_DOWN=true', 'APP_DOWN = true'],
20+
'APP_DOWN=false',
21+
$envContent
22+
);
23+
24+
file_put_contents($env, $envContent);
25+
26+
$this->comment('App is now out of down mode...');
27+
$this->info('You might need to restart your server to see changes');
28+
29+
return 0;
30+
}
31+
}

src/Commands/ConfigLibCommand.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace Leaf\Commands;
4+
5+
use Leaf\Sprout\Command;
6+
7+
class ConfigLibCommand extends Command
8+
{
9+
protected $signature = 'config:lib';
10+
protected $description = 'Setup Leaf MVC to use external libraries';
11+
protected $help = 'Setup Leaf MVC to use external libraries';
12+
13+
protected function handle()
14+
{
15+
$directory = getcwd() . DIRECTORY_SEPARATOR . LibPath();
16+
17+
if (!\Leaf\FS\Directory::exists($directory)) {
18+
\Leaf\FS\Directory::create($directory);
19+
}
20+
21+
$this->comment('lib folder setup successfully!');
22+
23+
return 0;
24+
}
25+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace Leaf\Commands;
4+
5+
use Leaf\Sprout\Command;
6+
7+
class ConfigPublishCommand extends Command
8+
{
9+
protected $signature = 'config:publish {config? : Config file to publish}';
10+
protected $description = 'Publish config files to your project';
11+
protected $help = 'Publish config files to your project';
12+
13+
protected function handle()
14+
{
15+
$configDir = getcwd() . DIRECTORY_SEPARATOR . ConfigPath();
16+
17+
if (!\Leaf\FS\Directory::exists($configDir)) {
18+
\Leaf\FS\Directory::create($configDir);
19+
}
20+
21+
$config = $this->argument('config');
22+
$configFiles = \Leaf\FS\Directory::files(__DIR__ . '/stubs/config');
23+
24+
foreach ($configFiles as $file) {
25+
if ($config && $file !== "$config.php") {
26+
continue;
27+
}
28+
29+
\Leaf\FS\File::copy(
30+
__DIR__ . "/stubs/config/$file",
31+
getcwd() . DIRECTORY_SEPARATOR . ConfigPath($file),
32+
['recursive' => true, 'overwrite' => true]
33+
);
34+
}
35+
36+
$this->comment('Config published successfully!');
37+
38+
return 0;
39+
}
40+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace Leaf\Commands;
4+
5+
use Leaf\Sprout\Command;
6+
use Illuminate\Support\Str;
7+
8+
class DeleteControllerCommand extends Command
9+
{
10+
protected $signature = 'd:controller {controller : The name of the controller}';
11+
protected $description = 'Delete a controller';
12+
protected $help = 'Delete a controller';
13+
14+
protected function handle()
15+
{
16+
$controller = Str::studly($this->argument('controller'));
17+
18+
if (!strpos($controller, 'Controller')) {
19+
$controller = str::plural($controller);
20+
$controller .= 'Controller';
21+
}
22+
23+
$controllerFile = getcwd() . DIRECTORY_SEPARATOR . ControllersPath("$controller.php");
24+
25+
if (!\Leaf\FS\File::exists($controllerFile)) {
26+
$this->error("$controller doesn't exist!");
27+
return 1;
28+
}
29+
30+
if (!\Leaf\FS\File::delete($controllerFile)) {
31+
$this->error("Couldn't delete $controllerFile, you might need to remove it manually.");
32+
return 1;
33+
}
34+
35+
$this->comment("$controller deleted successfully");
36+
37+
return 0;
38+
}
39+
}

src/Commands/DevToolsCommand.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
namespace Leaf\Commands;
4+
5+
use Leaf\Sprout\Command;
6+
7+
class DevToolsCommand extends Command
8+
{
9+
protected $signature = 'devtools:install';
10+
protected $description = 'Install the Leaf PHP devtools';
11+
protected $help = 'Install the leaf PHP Dev tools';
12+
13+
protected function handle()
14+
{
15+
$this->comment('Installing leaf devtools...');
16+
17+
if (sprout()->composer()->install('leafs/devtools')->getExitCode() !== 0) {
18+
$this->error('Failed to install leaf devtools via composer. Please run "composer require leafs/devtools" manually.');
19+
return 1;
20+
}
21+
22+
$this->comment('Installing leaf devtools routes...');
23+
24+
$rootFilePath = getcwd() . DIRECTORY_SEPARATOR . PublicPath('index.php');
25+
$rootFile = str_replace(
26+
"/*
27+
|--------------------------------------------------------------------------
28+
| Install the devtools
29+
|--------------------------------------------------------------------------
30+
|
31+
| Add Leaf devtools routes and config
32+
|
33+
*/
34+
\Leaf\DevTools::install();",
35+
'',
36+
\Leaf\FS\File::read($rootFilePath)
37+
);
38+
39+
$rootFile = str_replace(
40+
["require dirname(__DIR__) . '/vendor/autoload.php';", 'require "$appPath/vendor/autoload.php"'],
41+
"require dirname(__DIR__) . '/vendor/autoload.php';
42+
43+
/*
44+
|--------------------------------------------------------------------------
45+
| Install the devtools
46+
|--------------------------------------------------------------------------
47+
|
48+
| Add Leaf devtools routes and config
49+
|
50+
*/
51+
\Leaf\DevTools::install();",
52+
$rootFile
53+
);
54+
55+
$rootFile = str_replace("\n\n\n", "\n", $rootFile);
56+
57+
\Leaf\FS\File::write($rootFilePath, $rootFile);
58+
59+
$this->info('Leaf devtools installed successfully!');
60+
61+
return 0;
62+
}
63+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace Leaf\Commands;
4+
5+
use Leaf\Sprout\Command;
6+
7+
class EnvGenerateCommand extends Command
8+
{
9+
protected $signature = 'env:generate';
10+
protected $description = 'Generate .env file';
11+
protected $help = 'Generate .env file';
12+
13+
protected function handle()
14+
{
15+
$envFile = getcwd() . DIRECTORY_SEPARATOR . '.env';
16+
$envExampleFile = getcwd() . DIRECTORY_SEPARATOR . '.env.example';
17+
18+
if (file_exists($envFile)) {
19+
$this->error('.env already exists');
20+
return 1;
21+
}
22+
23+
if (file_exists($envExampleFile)) {
24+
if (\Leaf\FS\File::copy($envExampleFile, $envFile) || \Leaf\FS\File::copy(__DIR__ . '/stubs/.env.stub', $envFile)) {
25+
$this->comment('.env generated successfully!');
26+
return 0;
27+
}
28+
}
29+
30+
$this->error('Couldn\'t generate env file');
31+
32+
return 1;
33+
}
34+
}

src/Commands/EnvSetCommand.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
namespace Leaf\Commands;
4+
5+
use Leaf\Sprout\Command;
6+
7+
class EnvSetCommand extends Command
8+
{
9+
protected $signature = 'env:set
10+
{key : The environment variable key}
11+
{value : The environment variable value}';
12+
protected $description = 'Set a new environment variable for your app';
13+
protected $help = 'Set a new environment variable in the .env file and update .env.example if it exists.';
14+
15+
protected function handle()
16+
{
17+
$envFile = getcwd() . DIRECTORY_SEPARATOR . '.env';
18+
19+
if (!file_exists($envFile)) {
20+
$this->comment('No .env file found. Generating one...');
21+
22+
if (sprout()->process('php leaf env:generate')->run() !== 0) {
23+
$this->error('Couldn\'t generate .env file. Please run `php leaf env:generate` first.');
24+
return 1;
25+
}
26+
}
27+
28+
\Leaf\FS\File::write($envFile, function ($env) {
29+
$key = $this->argument('key');
30+
$value = $this->argument('value');
31+
32+
if (strpos($env, $key) !== false) {
33+
$this->info("$key already exists, updating value...");
34+
$env = preg_replace("/^$key=(.*)/m", "$key=$value", $env);
35+
} else {
36+
$this->info("Setting new environment variable: $key");
37+
$env .= "\n$key=$value\n";
38+
}
39+
40+
return $env;
41+
});
42+
43+
if (file_exists($envExampleFile = getcwd() . DIRECTORY_SEPARATOR . '.env.example')) {
44+
\Leaf\FS\File::write($envExampleFile, function ($envExample) {
45+
$key = $this->argument('key');
46+
47+
if (strpos($envExample, $key) === false) {
48+
$envExample .= "\n$key=\n";
49+
}
50+
51+
return $envExample;
52+
});
53+
}
54+
55+
$this->info("Environment updated successfully.");
56+
57+
return 0;
58+
}
59+
}

0 commit comments

Comments
 (0)