puko/console
最新稳定版本:0.4.0
Composer 安装命令:
composer require puko/console
包简介
Advanced console util that make pukoframework get things done on the fly.
README 文档
README
Advanced CLI utility that makes the Puko Framework development experience faster and more efficient.
Installation
composer require puko/console --dev
Requirements
- PHP 7.2.5+
- Symfony Console 5.4
- Supported Databases: MySQL, PostgreSQL, SQL Server
Usage
php puko <command> [options] [arguments]
Quick Start
# Show version php puko --version # Show help php puko --help # List all commands php puko list
Commands
Setup Commands
| Command | Description |
|---|---|
setup:db [schema] |
Connect to database and generate models |
setup:secure |
Generate encryption configuration |
setup:auth <name> |
Generate authentication plugin |
setup:controller <type> <name> |
Generate controller (view or service) |
setup:model <action> <name> <schema> |
Interactive model wizard |
Examples
# Setup database php puko setup:db main # Generate encryption config php puko setup:secure # Generate auth plugin php puko setup:auth UsersAuth # Generate controller php puko setup:controller view HomeController php puko setup:controller service UserService # Create model (interactive) php puko setup:model add User main
Routes Commands
| Command | Description |
|---|---|
routes:list |
List all registered routes |
routes:resort |
Sort routes alphabetically |
routes:dir |
Display routes with directories |
routes:view <action> <url> |
Add view route |
routes:service <action> <url> |
Add service (API) route |
routes:crud <schema/table> |
Generate full CRUD service |
routes:console <action> <path> |
Add console route |
routes:socket <action> <path> |
Add WebSocket route |
routes:error <action> |
Set error handler |
routes:lost <action> |
Set 404 handler |
Examples
# List routes php puko routes:list # Add view route php puko routes:view add /home # Add service route php puko routes:service add /api/users # Generate CRUD for table php puko routes:crud main/users
Generate Commands
| Command | Description |
|---|---|
generate:db |
Create database from models (reverse engineer) |
generate:ui |
Generate DataTables UI components |
Examples
# Reverse engineer: create DB from models php puko generate:db # Generate UI components php puko generate:ui
Refresh Commands
| Command | Description |
|---|---|
refresh:db [schema] |
Reload database schema and regenerate models |
php puko refresh:db main
Other Commands
| Command | Description |
|---|---|
serve [port] |
Start PHP built-in server (default: 4000) |
language <directory> |
Build localization files |
element:add <name> |
Generate view element |
element:download <name> |
Download element from repository |
cli <path> |
Execute PHP in console mode |
tests |
Run PHPUnit tests |
Examples
# Start server php puko serve php puko serve 8080 # Build language files php puko language controller/user # Create element php puko element:add DataTable # Run tests php puko tests
Options
| Option | Description |
|---|---|
-h, --help |
Display help for a command |
-q, --quiet |
Do not output any message |
-V, --version |
Display application version |
--ansi |
Force ANSI output |
--no-ansi |
Disable ANSI output |
-n, --no-interaction |
Do not ask interactive questions |
-v, -vv, -vvv |
Increase verbosity |
Project Structure
After using Puko Console, your project will have:
project/
├── config/
│ ├── database.php # Database configuration
│ ├── routes.php # Route definitions
│ ├── encryption.php # Security config
│ └── init.php # Console config
├── controller/ # Service controllers
├── plugins/
│ ├── auth/ # Authentication plugins
│ ├── controller/ # View controllers
│ ├── elements/ # UI elements
│ └── model/ # Model definitions
├── model/ # Model contracts
├── assets/
│ ├── html/ # HTML templates
│ ├── scripts/ # JavaScript files
│ ├── ui/ # UI components
│ └── master/ # Localization files
└── tests/
└── unit/ # Unit tests
PHPDoc Annotations
Puko Console uses PHPDoc annotations for model introspection:
/** * #Table users */ class Users extends Model { /** * #Column id * #PrimaryKey */ public $id = 0; /** * #Column name * #VarChar(100) not null */ public $name = ''; }
Supported Annotations
#Table [name]- Table name#Column [name]- Column definition#PrimaryKey- Primary key field#VarChar(size),#Int,#Text, etc. - Data types
Migration Commands
Database migration system supporting MySQL, PostgreSQL, and SQL Server.
| Command | Description |
|---|---|
migrate:make <name> |
Create new migration file |
migrate:run |
Run pending migrations |
migrate:rollback |
Rollback last migration |
migrate:reset |
Rollback ALL migrations |
migrate:status |
Show migration status |
Migration Make Options
| Option | Description |
|---|---|
--create |
Create a new table |
--table |
Specify table name |
Examples
# Create migration for new table php puko migrate:make create_users_table php puko migrate:make create_users_table --create users # Create migration to modify existing table php puko migrate:make add_email_to_users_table --table users # Run all pending migrations php puko migrate:run # Run specific number of migrations php puko migrate:run --step=3 # Rollback last migration php puko migrate:rollback # Rollback multiple migrations php puko migrate:rollback --step=2 # Rollback ALL migrations php puko migrate:reset # Check migration status php puko migrate:status
Migration File Structure
<?php use pukoconsole\migration\Schema; use pukoconsole\migration\Blueprint; class CreateUsersTable { public function up(): void { Schema::create('users', function (Blueprint $table) { $table->id(); $table->string('name'); $table->string('email')->unique(); $table->timestamps(); }); } public function down(): void { Schema::drop('users'); } }
Blueprint API
// Column types $table->id(); // Primary key auto-increment $table->bigId(); // Bigint primary key $table->string('name', 100); // VARCHAR $table->text('description'); // TEXT $table->integer('age'); // INT $table->bigInteger('quantity'); // BIGINT $table->decimal('price', 8, 2); // DECIMAL $table->boolean('active'); // BOOLEAN/TINYINT $table->date('created_at'); // DATE $table->dateTime('updated_at'); // DATETIME $table->timestamp('expires_at'); // TIMESTAMP $table->binary('data'); // BLOB $table->json('options'); // JSON $table->uuid('uuid'); // UUID // Modifiers $table->string('name')->nullable(); // Allow NULL $table->string('name')->default('Anon'); // DEFAULT value $table->string('email')->unique(); // UNIQUE constraint $table->integer('votes')->unsigned(); // UNSIGNED $table->primary(); // Primary key // Special $table->foreignId('user_id')->references('id')->on('users'); $table->timestamps(); // created_at and updated_at $table->softDeletes(); // deleted_at
Configuration
The console reads from src/config/init.php:
<?php return [ 'version' => '1.0.0', 'repo' => 'https://api.github.com/repos/velliz/puko-elements/contents' ];
Upgrading from Old Version
The command syntax has changed from the old format:
| Old Syntax | New Syntax |
|---|---|
php puko setup db main |
php puko setup:db main |
php puko routes list |
php puko routes:list |
php puko generate db |
php puko generate:db |
php puko serve 8080 |
php puko serve 8080 |
php puko version |
php puko --version |
License
MIT License - Copyright (c) 2018 Didit Velliz
统计信息
- 总下载量: 5.78k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 3
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-11-09