diff --git a/README.md b/README.md index dad5e70..baa52c0 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ # PHPapp Framework -**PHPapp** is a lightweight PHP framework designed for quick and efficient web application development. It follows the MVC (Model-View-Controller) architecture and provides core components for database interaction, session management, request handling, and more. +**PHPapp** is a lightweight PHP framework designed for quick and efficient web application development. It follows the MVC (Model-View-Controller) architecture and provides core components for data management, routing, and user interaction. > [@and-ri](https://github.com/and-ri): -> Hello everyone! I am very excited to share with you a version of my PHP framework. Maybe it is far from such giants as Laravel or Yii, but it has become very convenient for me. Especially for quick deployment of small web applications or prototypes. +> Hello everyone! I am very excited to share with you a version of my PHP framework. Maybe it is far from such giants as Laravel or Yii, but it has become very convenient for me. Especially for quick prototyping and small applications. > > I will be happy for any contribution :) @@ -11,8 +11,10 @@ - **MVC Architecture:** Clean separation of concerns with models, views, and controllers to organize code logically. - **Core Components:** Includes essential libraries for handling sessions, database connections, request processing, and URL routing. +- **Migration System:** Built-in system for managing database schema changes and versioning. +- **Installer:** Interactive installer for quick setup, including `.env` generation, Composer installation, and database migration execution. - **Easy to Install and Configure:** Minimal setup required for developers to get started quickly. - + ## Requirements - PHP 8+ @@ -39,7 +41,9 @@ composer install ``` -4. Create `.env` file +4. Run the installer: + Open `http://yourdomain.com/installer.php` in your browser and follow the on-screen instructions to set up the database and configuration. + 5. Done! ## Core Components @@ -55,7 +59,7 @@ - **app.php**: Manages the application lifecycle, including initialization and configuration. - **db.php**: Provides methods for database queries and connection handling. - **env.php**: Handles environment variables and configuration settings. -- **google_auth.php**: This file handles the Google authentication process for the application. +- **google_auth.php**: Handles the Google authentication process for the application. - **language.php**: Loads and manages language files for multi-language support. - **load.php**: Loads models and controllers dynamically. - **pagination.php**: Provides simple pagination functionality. @@ -65,6 +69,11 @@ - **staticfile.php**: Serves static files (CSS, JS, images). - **url.php**: Generates URLs and manages routing. +### New Features + +- **Migration System:** Manage database schema changes with ease. Use `php migrate.php migrate` to apply migrations, `php migrate.php rollback` to undo the last migration, and `php migrate.php status` to check migration status. +- **Interactive Installer:** Quickly set up your application by providing database and web configuration details in a user-friendly web installer. + ## License -This project is licensed under the MIT License. +This project is licensed under the MIT License. \ No newline at end of file diff --git a/migrate.php b/migrate.php new file mode 100644 index 0000000..8bf7dbc --- /dev/null +++ b/migrate.php @@ -0,0 +1,88 @@ +query(" + CREATE TABLE IF NOT EXISTS migrations ( + id INT AUTO_INCREMENT PRIMARY KEY, + migration VARCHAR(255), + applied_at DATETIME + ) + "); + + $appliedMigrations = array_column( + $db->query("SELECT migration FROM migrations", true), + 'migration' + ); + + $files = glob(__DIR__ . '/migrations/*.php'); + foreach ($files as $file) { + $migrationName = basename($file, '.php'); + if (!in_array($migrationName, $appliedMigrations)) { + require_once $file; + $migration = new Migration(); + $migration->up($db); + $db->query("INSERT INTO migrations (migration, applied_at) VALUES ('$migrationName', NOW())"); + echo "Applied: $migrationName\n"; + } + } +} + +function rollback($db) { + echo "Rolling back last migration...\n"; + + $lastMigration = $db->query("SELECT migration FROM migrations ORDER BY id DESC LIMIT 1")[0]['migration'] ?? null; + + if ($lastMigration) { + require_once __DIR__ . "/migrations/$lastMigration.php"; + $migration = new Migration(); + $migration->down($db); + $db->query("DELETE FROM migrations WHERE migration = '$lastMigration'"); + echo "Rolled back: $lastMigration\n"; + } else { + echo "No migrations to roll back.\n"; + } +} + +function migrationStatus($db) { + echo "Migration status:\n"; + + $migrations = $db->query("SELECT migration, applied_at FROM migrations ORDER BY applied_at", true); + foreach ($migrations as $migration) { + echo "Applied: {$migration['migration']} at {$migration['applied_at']}\n"; + } + + $files = glob(__DIR__ . '/migrations/*.php'); + foreach ($files as $file) { + $migrationName = basename($file, '.php'); + if (!in_array($migrationName, array_column($migrations, 'migration'))) { + echo "Pending: $migrationName\n"; + } + } +} \ No newline at end of file diff --git a/migrations/template.php b/migrations/template.php new file mode 100644 index 0000000..14974ed --- /dev/null +++ b/migrations/template.php @@ -0,0 +1,11 @@ + + + +
+ + +