phpdominicana/lightwave
最新稳定版本:0.0.5
Composer 安装命令:
composer require phpdominicana/lightwave
包简介
Simple php starter kit
README 文档
README
This is a simple PHP starter kit created by the PHP dominicana community. It is designed to help you get started with PHP development quickly. It includes a simple web server, a simple router It is designed to be simple and easy to use.
Installation
A few simple steps are needed to get this application up and running:
The next step assumes that composer is available in your PATH
composer create-project phpdominicana/lightwave [project-name]
cd [project-name]
Copy the .env.example file to .env and update the database connection settings.
cp .env.example .env
Usage with PHP native server
To start the PHP native server, run the following command:
sh server.sh
Add new routes
Routes are defined in the routes/web.php file. This file is loaded by the RouteServiceProvider.
To define routes, you can use the $router object, which is an instance of Phpdominicana\Lightwave\Router. It provides simple methods for common HTTP verbs:
<?php // routes/web.php use Phpdominicana\Lightwave\Controllers\HelloController; use Phpdominicana\Lightwave\Controllers\HomeController; use Phpdominicana\Lightwave\Router; /** @var Router $router */ // Example: GET route with a parameter $router->get('/hello/{name}', [HelloController::class, 'index']); // Example: GET route for the homepage $router->get('/', [HomeController::class, 'index']); // Example: POST route // $router->post('/users', [UserController::class, 'store']); // Example: PUT route // $router->put('/users/{id}', [UserController::class, 'update']); // Example: DELETE route // $router->delete('/users/{id}', [UserController::class, 'destroy']);
Controller Structure and Dependency Injection
Controller methods referenced in your routes can receive dependencies in two main ways:
-
Route Parameters: Any parameters defined in your route path (e.g.,
{name}in/hello/{name}) will be passed to your controller method as arguments with matching names.// In HelloController.php public static function index(string $name): Response { // $name will contain the value from the URL return new Response("Hello {$name}"); }
-
Service Container: If your controller method type-hints
Pimple\Psr11\Container(or its interfacePsr\Container\ContainerInterface), the application's service container will be injected. You can use this to resolve other services, like the view renderer.// In HomeController.php use Pimple\Psr11\Container; use Symfony\Component\HttpFoundation\Response; public static function index(Container $container): Response { $view = $container->get('view'); // Assuming 'view' service is registered return new Response($view->render('welcome.twig')); }
How to connect to a database using eloquent ORM
Install eloquent ORM
composer require illuminate/database
Add the EloquenServiceProvider to the src/Providers/AppServiceProvider class to the config/app.php file in the providers array.
'providers' => [ \Phpdominicana\Lightwave\Providers\AppServiceProvider::class, \Phpdominicana\Lightwave\Providers\TwigServiceProvider::class, \Phpdominicana\Lightwave\Providers\RouteServiceProvider::class, \Phpdominicana\Lightwave\Providers\EloquentServiceProvider::class ],
Then you can create you model and extend the Illuminate\Database\Eloquent\Model class.
<?php namespace Phpdominicana\Lightwave\Models; use Illuminate\Database\Eloquent\Model; class User extends Model { protected $table = 'users'; protected $fillable = ['name', 'email', 'password']; }
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-06-21