承接 alsocoder/apnaphp-framework 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

alsocoder/apnaphp-framework

最新稳定版本:v1.0.0

Composer 安装命令:

composer require alsocoder/apnaphp-framework

包简介

ApnaPHP Framework - A Next.js App Router style + Laravel inspired PHP framework

README 文档

README

Latest Version

A modern PHP framework inspired by Next.js App Router and Laravel, featuring file-based routing, Laravel-like ORM, and multiple database support.

🚀 Features

  • File-based Routing: Next.js App Router style routing with .apna.php files
  • Laravel-like ORM: Eloquent-inspired models with schema definition
  • Multiple Database Support: MySQL, MariaDB, PostgreSQL, MongoDB, SQLite
  • Auto-migration: Automatic schema creation from model definitions
  • Middleware Support: Hierarchical middleware system
  • Console Commands: Built-in CLI with php apna serve
  • Modern PHP: PHP 8.1+ with modern syntax and features

📦 Installation

Using Composer

composer create-project alsocoder/apnaphp my-app
cd my-app

Manual Installation

composer require alsocoder/apnaphp

🏃‍♂️ Quick Start

1. Create a New Project

composer create-project alsocoder/apnaphp my-app
cd my-app

2. Configure Database

Edit .env file:

DB_DRIVER=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=my_database
DB_USERNAME=root
DB_PASSWORD=password

3. Start Development Server

php apna serve

Your application will be available at http://localhost:3000

📁 Project Structure

my-app/
├── app/
│   ├── api/                 # API routes
│   │   └── users/
│   │       └── route.apna.php
│   ├── dashboard/           # Page routes
│   │   └── page.apna.php
│   └── layout.apna.php      # Layout files
├── config/
│   ├── app.php
│   └── database.php
├── models/
│   └── User.php
├── public/
│   └── index.php
└── storage/
    ├── cache/
    ├── logs/
    └── uploads/

🛣️ Routing

File-based Routing

Create routes by adding .apna.php files:

API Routes (app/api/*/route.apna.php):

<?php

namespace App\Api\Users;

use ApnaPHP\Routing\Request;
use ApnaPHP\Routing\Response;
use App\Models\User;

class UsersHandler
{
    public function GET(Request $request)
    {
        return Response::json([
            'success' => true,
            'users' => User::all()
        ]);
    }
    
    public function POST(Request $request)
    {
        $user = User::create($request->all());
        return Response::json([
            'success' => true,
            'user' => $user
        ], 201);
    }
    
    public function PUT(Request $request)
    {
        $id = $request->param('id');
        $user = User::find($id);
        $user->update($request->all());
        return Response::json([
            'success' => true,
            'user' => $user
        ]);
    }
    
    public function DELETE(Request $request)
    {
        $id = $request->param('id');
        $user = User::find($id);
        $user->delete();
        return Response::json([
            'success' => true,
            'message' => 'User deleted successfully'
        ]);
    }
}

Page Routes (app/*/page.apna.php):

<?php
$users = User::all();
?>
<!DOCTYPE html>
<html>
<head>
    <title>Users</title>
</head>
<body>
    <h1>Users</h1>
    <?php foreach ($users as $user): ?>
        <div><?= $user->name ?></div>
    <?php endforeach; ?>
</body>
</html>

🗄️ Database & Models

Model Definition

<?php

namespace App\Models;

use ApnaPHP\Database\Model;

class User extends Model
{
    protected $table = 'users';
    protected $autoMigrate = true;
    
    protected $schema = [
        'name' => 'required|type:string|length:255',
        'email' => 'required|unique|type:string|length:255',
        'phone' => 'nullable|type:string|length:20',
        'age' => 'type:integer|min:18|max:120|default:18',
        'status' => 'type:string|in:active,inactive|default:active'
    ];
    
    protected $fillable = ['name', 'email', 'phone', 'age'];
    protected $hidden = ['password'];
}

Database Operations

// Create
$user = User::create([
    'name' => 'John Doe',
    'email' => 'john@example.com'
]);

// Find
$user = User::find(1);
$user = User::where('email', 'john@example.com')->first();

// Update
$user->name = 'Jane Doe';
$user->save();

// Delete
$user->delete();

// Query Builder
$users = User::where('status', 'active')
    ->where('age', '>', 18)
    ->orderBy('name')
    ->limit(10)
    ->get();

🗃️ Database Support

MySQL/MariaDB

DB_DRIVER=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=my_app
DB_USERNAME=root
DB_PASSWORD=password

PostgreSQL

DB_DRIVER=postgresql
DB_HOST=localhost
DB_PORT=5432
DB_DATABASE=my_app
DB_USERNAME=postgres
DB_PASSWORD=password

MongoDB

DB_DRIVER=mongodb
DB_HOST=localhost
DB_PORT=27017
DB_DATABASE=my_app

SQLite

DB_DRIVER=sqlite
DB_DATABASE=storage/database/database.sqlite

🛠️ Console Commands

# Start development server
php apna serve

# Create new page
php apna make:page about

# Create new API route
php apna make:route users

# Create new model
php apna make:model Post

# Create new middleware
php apna make:middleware AuthMiddleware

# Create new migration
php apna make:migration create_posts_table

# List all routes
php apna routes

# Show version
php apna --version

# Show help
php apna help

🔧 Configuration

Application Config (config/app.php)

<?php

return [
    'name' => env('APP_NAME', 'ApnaPHP Application'),
    'env' => env('APP_ENV', 'production'),
    'debug' => env('APP_DEBUG', false),
    'url' => env('APP_URL', 'http://localhost'),
    'timezone' => env('APP_TIMEZONE', 'UTC'),
];

Database Config (config/database.php)

<?php

return [
    'default' => env('DB_DRIVER', 'mysql'),
    
    'connections' => [
        'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', 'localhost'),
            'port' => env('DB_PORT', 3306),
            'database' => env('DB_DATABASE', ''),
            'username' => env('DB_USERNAME', ''),
            'password' => env('DB_PASSWORD', ''),
        ],
        // ... other connections
    ],
];

🧪 Testing

# Run tests
composer test

# Run with coverage
composer test-coverage

# Static analysis
composer phpstan

# Code style check
composer cs-check

📚 Documentation

🤝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

📞 Support

Made with ❤️ by Also Coder (Dinesh Gupta)

统计信息

  • 总下载量: 16
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-10-08