alanvdb / app
Personal app system
Installs: 8
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Language:Twig
Requires
- alanvdb/guzzle-psr7-factories: ^0.4.0
- alanvdb/middleware-dispatcher: ^1.0
- alanvdb/orm: ^0.2.0
- alanvdb/router: ^0.5.0
- alanvdb/server: ^0.3.0
- alanvdb/twig-factory: ^0.1.0
- alanvdb/validators: ^0.1.0
- psr/http-message: ^2.0
This package is auto-updated.
Last update: 2025-03-06 20:24:26 UTC
README
AlanVdb/App is a modular PHP framework designed for modern web application development, featuring PSR-compliant components, robust routing, and integration with Doctrine ORM and Twig templating.
Installation
To create a new project, use Composer:
composer create-project alanvdb/app your-project-name
Configuration
After installation, configure the environment variables in the .env
file located in the root directory of your project.
Example .env
File
# Debug Mode DEBUG_MODE="true" # Router Configuration ROUTES_CONFIG="config/routes.php" # Database Configuration: SQLite (default) DB_DRIVER="sqlite" DB_PATH="memory/database.sqlite" # Or using MySQL database driver (uncomment and configure): # DB_DRIVER="pdo_mysql" # DB_HOST="127.0.0.1" # DB_NAME="your_database" # DB_USER="your_username" # DB_PASSWORD="your_password" # Doctrine ORM Configuration ENTITY_DIRECTORIES="src/Model/Entity" MODEL_PROXY_NAMESPACE="Model\\Proxy" MODEL_PROXY_DIRECTORY="memory/cache/proxies" # Twig Configuration ACTIVATE_TEMPLATE_CACHE="false" TEMPLATES_DIRECTORY="../assets/views" RENDERER_CACHE_DIRECTORY="../memory/cache/templates"
Switching Between SQLite and MySQL
-
For SQLite:
- Keep the default values for
DB_DRIVER
andDB_PATH
.
- Keep the default values for
-
For MySQL:
- Uncomment and set values for:
DB_DRIVER
(usepdo_mysql
).DB_HOST
(e.g.,127.0.0.1
).DB_NAME
(your database name).DB_USER
(your MySQL username).DB_PASSWORD
(your MySQL password).
- Uncomment and set values for:
Routing
Routes are defined in config/routes.php
. Below is an example configuration:
<?php declare(strict_types=1); namespace App; use AlanVdb\Controller\MainController; use AlanVdb\Controller\BlogController; return [ ['home', 'GET', '/', [MainController::class, 'index']], ['blog', 'GET', '/blog', [BlogController::class, 'index']], ['blogPost', 'GET', '/blog/{slug}', [BlogController::class, 'show']], ];
Example Controller: MainController
The MainController
provides an example of how to handle HTTP requests and render templates using Twig. It includes a method to centralize common template parameters.
<?php declare(strict_types=1); namespace AlanVdb\Controller; use Psr\Http\Message\ResponseInterface; class MainController extends AbstractController { public function index(): ResponseInterface { $params = $this->getCommonTemplateParams(); $document = $this->twig->render('home.twig', $params); return $this->createResponse($document); } protected function getCommonTemplateParams(): array { return [ 'uriGenerator' => $this->request->getAttribute('uriGenerator'), ]; } }
Database Configuration and Commands
Create a Database Entity
Define your entities using PHP metadata attributes. Here's an example:
<?php declare(strict_types=1); namespace App\Model\Entity; use Doctrine\ORM\Mapping as ORM; #[ORM\Entity] #[ORM\Table(name: 'blogs')] class Blog { #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: 'integer')] private int $id; #[ORM\Column(type: 'string', length: 255)] private string $title; #[ORM\Column(type: 'text')] private string $content; #[ORM\Column(type: 'datetime')] private \DateTime $createdAt; // Getters and setters... }
Generate the Database Schema
After creating or updating your entities, run the following command to generate the database schema:
bin/doctrine orm:schema-tool:create
Update the Schema (If Needed)
If you modify an entity, update the database schema with:
bin/doctrine orm:schema-tool:update --force
Running the Application
Start the development server:
php -S localhost:8000 -t public
Visit http://localhost:8000
in your browser.
License
This project is licensed under the MIT License.