PHPackages                             ramphor/rake - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. ramphor/rake

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ramphor/rake
============

Rake 2.0 core crawling/migration library

1.3.5(10mo ago)3270[3 issues](https://github.com/ramphor/rake-php/issues)4MITPHPPHP &gt;=7.4CI passing

Since Oct 9Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/ramphor/rake-php)[ Packagist](https://packagist.org/packages/ramphor/rake)[ RSS](/packages/ramphor-rake/feed)WikiDiscussions v2.x Synced 6d ago

READMEChangelog (9)Dependencies (8)Versions (13)Used By (4)

RAKE CORE FRAMEWORK
===================

[](#rake-core-framework)

**Phiên bản:** 3.0 **Ngày tạo:** 2025 **Tác giả:** Development Team

---

📋 MỤC LỤC
---------

[](#-mục-lục)

1. [Tổng quan Rake Core](#t%E1%BB%95ng-quan-rake-core)
2. [Triết lý thiết kế](#tri%E1%BA%BFt-l%C3%BD-thi%E1%BA%BFt-k%E1%BA%BF)
3. [Kiến trúc Framework](#ki%E1%BA%BFn-tr%C3%BAc-framework)
4. [Các thành phần cốt lõi](#c%C3%A1c-th%C3%A0nh-ph%E1%BA%A7n-c%E1%BB%91t-l%C3%B5i)
5. [Tài liệu kỹ thuật](#t%C3%A0i-li%E1%BB%87u-k%E1%BB%B9-thu%E1%BA%ADt)
6. [Development Guidelines](#development-guidelines)

---

🎯 TỔNG QUAN RAKE CORE
---------------------

[](#-tổng-quan-rake-core)

### Mục tiêu dự án

[](#mục-tiêu-dự-án)

Rake Core là **framework tổng quát** cho việc xây dựng ứng dụng, không phụ thuộc vào platform cụ thể nào. Framework này cung cấp:

- **Platform Agnostic**: Không phụ thuộc vào WordPress, Laravel, hay platform cụ thể nào
- **Modular Architecture**: Kiến trúc module hóa với các thành phần độc lập
- **Flow-based Design**: Mọi thứ phải thấy được luồng xử lý và có thể visualize
- **Dependency Injection**: Container pattern cho quản lý dependencies
- **Event-driven**: Hệ thống event-driven với logging toàn diện
- **Extensible**: Dễ dàng mở rộng và tùy chỉnh

### Vai trò trong hệ sinh thái

[](#vai-trò-trong-hệ-sinh-thái)

```
┌─────────────────────────────────────────────────────────────┐
│                    RAKE ECOSYSTEM                          │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│  ┌─────────────────┐    ┌─────────────────┐    ┌─────────┐ │
│  │   RAKE CORE     │    │   RAKE WORDPRESS│    │ RAKE    │ │
│  │   FRAMEWORK     │◄───┤    ADAPTER      │    │ OTHER   │ │
│  │                 │    │                 │    │ ADAPTERS│ │
│  │ • Container     │    │ • WP Database   │    │ • Laravel│ │
│  │ • Kernel        │    │ • WP Hooks      │    │ • Symfony│ │
│  │ • Bootstrapper  │    │ • WP Admin      │    │ • Custom │ │
│  │ • Facade        │    │ • WP Security   │    │ • Platform│ │
│  │ • Migration     │    │ • WP Cache      │    │ • Specific│ │
│  │ • Logging       │    │ • WP Config     │    │ • Adapters│ │
│  └─────────────────┘    └─────────────────┘    └─────────┘ │
│                                                             │
│  ┌─────────────────┐    ┌─────────────────┐    ┌─────────┐ │
│  │   CRAWFLOW      │    │   CRAWFLOW CLI  │    │ CRAWFLOW│ │
│  │   PLUGIN        │    │    TOOL         │    │  CORE   │ │
│  │                 │    │                 │    │         │ │
│  │ • WordPress UI  │    │ • Command Line  │    │ • Engine│ │
│  │ • Visual Editor │    │ • Batch Process │    │ • API   │ │
│  │ • Admin Panel   │    │ • Scripts       │    │ • Core  │ │
│  └─────────────────┘    └─────────────────┘    └─────────┘ │
└─────────────────────────────────────────────────────────────┘

```

### Công nghệ sử dụng

[](#công-nghệ-sử-dụng)

- **PHP 8.1+**: Ngôn ngữ chính
- **PSR-4**: Autoloading standard
- **PSR-3**: Logger interface
- **PSR-11**: Container interface
- **Composer**: Dependency management
- **Monolog**: Logging library

---

🎨 TRIẾT LÝ THIẾT KẾ
-------------------

[](#-triết-lý-thiết-kế)

### Platform Agnostic Philosophy

[](#platform-agnostic-philosophy)

Rake Core được thiết kế theo triết lý **"Platform Agnostic"** - không phụ thuộc vào platform cụ thể nào:

```
┌─────────────────────────────────────────────────────────────┐
│                    RAKE CORE FRAMEWORK                    │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│  ┌─────────────────┐  ┌─────────────────┐  ┌─────────────┐ │
│  │   CONTAINER     │  │     KERNEL      │  │ BOOTSTRAPPER│ │
│  │                 │  │                 │  │             │ │
│  │ • DI Container  │  │ • App Lifecycle │  │ • Service   │ │
│  │ • Service Locator│  │ • Request Handle│  │ • Provider  │ │
│  │ • Dependency Mgmt│  │ • Response Gen  │  │ • Bootstrap │ │
│  │ • Singleton Mgmt│  │ • Error Handle  │  │ • Register  │ │
│  └─────────────────┘  └─────────────────┘  └─────────────┘ │
│                                                             │
│  ┌─────────────────┐  ┌─────────────────┐  ┌─────────────┐ │
│  │    FACADE       │  │   MIGRATION     │  │   LOGGING   │ │
│  │                 │  │                 │  │             │ │
│  │ • Static Access │  │ • Schema Mgmt   │  │ • PSR-3     │ │
│  │ • Service Proxy │  │ • Version Track │  │ • Monolog   │ │
│  │ • Easy API      │  │ • Auto Migrate  │  │ • Daily Logs│ │
│  │ • Clean Interface│  │ • Rollback      │  │ • CLI Output│ │
│  └─────────────────┘  └─────────────────┘  └─────────────┘ │
└─────────────────────────────────────────────────────────────┘

```

### Design Patterns Applied

[](#design-patterns-applied)

- **Dependency Injection**: Container pattern cho quản lý dependencies
- **Service Locator**: Truy cập services thông qua container
- **Factory Pattern**: Service factory, component factory
- **Builder Pattern**: Configuration builder, service builder
- **Chain of Responsibility**: Middleware chain, processor chain
- **Strategy Pattern**: Service strategy, handler strategy
- **Adapter Pattern**: Platform adapter, service adapter
- **Command Pattern**: Console commands, queue commands
- **State Pattern**: Application state, service state
- **Decorator Pattern**: Service decorator, middleware decorator
- **Observer/Event Bus**: Event-driven architecture

### Flow-based Architecture

[](#flow-based-architecture)

Rake Core được xây dựng theo triết lý **"Flow-based Architecture"** - mọi thứ phải thấy được luồng xử lý:

```
┌─────────────────┐    ┌─────────────────┐    ┌─────────────────┐
│   REQUEST       │───▶│   KERNEL        │───▶│   RESPONSE      │
│                 │    │                 │    │                 │
│ • Input Data    │    │ • Process       │    │ • Output Data   │
│ • Parameters    │    │ • Transform     │    │ • Status Code   │
│ • Headers       │    │ • Validate      │    │ • Headers       │
│ • Context       │    │ • Execute       │    │ • Body          │
└─────────────────┘    └─────────────────┘    └─────────────────┘
         │                       │                       │
         │                       │                       │
         ▼                       ▼                       ▼
┌─────────────────┐    ┌─────────────────┐    ┌─────────────────┐
│   VALIDATION    │    │   EXECUTION     │    │   LOGGING       │ │
│                 │    │                 │    │                 │ │
│ • Input Check   │    │ • Service Call  │    │ • Request Log   │ │
│ • Schema Valid  │    │ • Business Logic│    │ • Response Log  │ │
│ • Security Check│    │ • Data Process  │    │ • Error Log     │ │
│ • Permission    │    │ • State Change  │    │ • Performance   │ │
└─────────────────┘    └─────────────────┘    └─────────────────┘

```

---

🏗️ KIẾN TRÚC FRAMEWORK
----------------------

[](#️-kiến-trúc-framework)

### Package Structure

[](#package-structure)

```
rake/
├── src/
│   ├── Container/             # Dependency Injection
│   │   ├── Container.php      # Main container
│   │   ├── ContainerInterface.php
│   │   └── ServiceProvider.php
│   ├── Kernel/                # Application Kernels
│   │   ├── AbstractKernel.php
│   │   ├── ConsoleKernel.php
│   │   ├── HttpKernel.php
│   │   └── KernelInterface.php
│   ├── Bootstrapper/          # Service Bootstrappers
│   │   ├── BootstrapperInterface.php
│   │   ├── CoreBootstrapper.php
│   │   └── ServiceBootstrapper.php
│   ├── Facade/                # Facade Pattern
│   │   ├── Facade.php
│   │   ├── Logger.php
│   │   └── Database.php
│   ├── Migration/             # Database Migration
│   │   ├── MigrationManager.php
│   │   ├── SchemaGenerator.php
│   │   └── MigrationInterface.php
│   ├── Logging/               # Logging System
│   │   ├── LoggerManager.php
│   │   ├── LogInterface.php
│   │   └── LogFormatter.php
│   └── Database/              # Database Abstraction
│       ├── DatabaseAdapterInterface.php
│       ├── DatabaseConfig.php
│       └── DatabaseDriverManager.php
├── schema_definitions/        # Database Schemas
├── composer.json
└── README.md

```

### Core Components

[](#core-components)

#### 1. **Container (Dependency Injection)**

[](#1-container-dependency-injection)

```
// Main container for dependency management
class Container
{
    private array $services = [];
    private array $singletons = [];
    private array $resolved = [];

    public function bind(string $abstract, $concrete): void;
    public function singleton(string $abstract, $concrete): void;
    public function make(string $abstract): mixed;
    public function has(string $abstract): bool;
    public function resolve($concrete): mixed;
}
```

#### 2. **Kernel (Application Lifecycle)**

[](#2-kernel-application-lifecycle)

```
// Abstract kernel for application lifecycle
abstract class AbstractKernel
{
    protected Container $container;
    protected array $bootstrappers = [];

    abstract public function bootstrap(): void;
    abstract public function handle($request): mixed;
    abstract public function terminate($request, $response): void;
}
```

#### 3. **Bootstrapper (Service Registration)**

[](#3-bootstrapper-service-registration)

```
// Service bootstrapper interface
interface BootstrapperInterface
{
    public function bootstrap(Container $container): void;
    public function register(Container $container): void;
    public function boot(Container $container): void;
}
```

#### 4. **Facade (Static Access)**

[](#4-facade-static-access)

```
// Base facade class
abstract class Facade
{
    protected static Container $container;

    public static function setContainer(Container $container): void;
    public static function getFacadeAccessor(): string;
    public static function __callStatic(string $method, array $arguments): mixed;
}
```

#### 5. **Migration (Database Management)**

[](#5-migration-database-management)

```
// Migration manager
class MigrationManager
{
    private DatabaseAdapterInterface $adapter;
    private SchemaGenerator $generator;

    public function runMigrations(): array;
    public function rollbackMigrations(): array;
    public function getMigrationStatus(): array;
    public function createMigration(string $name): string;
}
```

#### 6. **Logging (PSR-3 Implementation)**

[](#6-logging-psr-3-implementation)

```
// Logger manager
class LoggerManager
{
    private LoggerInterface $logger;
    private array $config;

    public function log($level, string $message, array $context = []): void;
    public function emergency(string $message, array $context = []): void;
    public function alert(string $message, array $context = []): void;
    public function critical(string $message, array $context = []): void;
    public function error(string $message, array $context = []): void;
    public function warning(string $message, array $context = []): void;
    public function notice(string $message, array $context = []): void;
    public function info(string $message, array $context = []): void;
    public function debug(string $message, array $context = []): void;
}
```

---

🔧 CÁC THÀNH PHẦN CỐT LÕI
------------------------

[](#-các-thành-phần-cốt-lõi)

### 1. **Dependency Injection Container**

[](#1-dependency-injection-container)

#### Container Interface

[](#container-interface)

```
interface ContainerInterface
{
    public function bind(string $abstract, $concrete): void;
    public function singleton(string $abstract, $concrete): void;
    public function make(string $abstract): mixed;
    public function has(string $abstract): bool;
    public function resolve($concrete): mixed;
    public function call($callback, array $parameters = []): mixed;
}
```

#### Service Registration

[](#service-registration)

```
// Bind interface to implementation
$container->bind(DatabaseInterface::class, MySQLDatabase::class);

// Bind singleton
$container->singleton(LoggerInterface::class, Logger::class);

// Bind with closure
$container->bind('config', function() {
    return new Config(['debug' => true]);
});
```

#### Service Resolution

[](#service-resolution)

```
// Resolve service
$logger = $container->make(LoggerInterface::class);

// Resolve with parameters
$service = $container->make(Service::class, ['param' => 'value']);

// Call method with dependency injection
$result = $container->call([$service, 'method'], ['param' => 'value']);
```

### 2. **Kernel System**

[](#2-kernel-system)

#### Abstract Kernel

[](#abstract-kernel)

```
abstract class AbstractKernel
{
    protected Container $container;
    protected array $bootstrappers = [];
    protected array $middleware = [];

    public function __construct(Container $container)
    {
        $this->container = $container;
        $this->bootstrap();
    }

    abstract public function bootstrap(): void;
    abstract public function handle($request): mixed;
    abstract public function terminate($request, $response): void;

    protected function runBootstrappers(): void
    {
        foreach ($this->bootstrappers as $bootstrapper) {
            $this->container->make($bootstrapper)->bootstrap($this->container);
        }
    }
}
```

#### Console Kernel

[](#console-kernel)

```
class ConsoleKernel extends AbstractKernel
{
    protected array $commands = [];

    public function handle($input, $output = null): int
    {
        // Handle console command
        $command = $this->resolveCommand($input);
        return $command->execute($input, $output);
    }

    protected function bootstrap(): void
    {
        $this->runBootstrappers();
        $this->registerCommands();
    }
}
```

#### HTTP Kernel

[](#http-kernel)

```
class HttpKernel extends AbstractKernel
{
    protected array $middleware = [];

    public function handle($request): Response
    {
        // Handle HTTP request
        $response = $this->sendRequestThroughRouter($request);
        return $this->prepareResponse($response);
    }

    protected function bootstrap(): void
    {
        $this->runBootstrappers();
        $this->registerMiddleware();
    }
}
```

### 3. **Bootstrapper System**

[](#3-bootstrapper-system)

#### Bootstrapper Interface

[](#bootstrapper-interface)

```
interface BootstrapperInterface
{
    public function bootstrap(Container $container): void;
    public function register(Container $container): void;
    public function boot(Container $container): void;
}
```

#### Core Bootstrapper

[](#core-bootstrapper)

```
class CoreBootstrapper implements BootstrapperInterface
{
    public function register(Container $container): void
    {
        // Register core services
        $container->singleton(ContainerInterface::class, Container::class);
        $container->singleton(LoggerInterface::class, Logger::class);
        $container->singleton(DatabaseAdapterInterface::class, DatabaseAdapter::class);
    }

    public function boot(Container $container): void
    {
        // Boot core services
        $logger = $container->make(LoggerInterface::class);
        $logger->info('Core services booted');
    }

    public function bootstrap(Container $container): void
    {
        $this->register($container);
        $this->boot($container);
    }
}
```

### 4. **Facade System**

[](#4-facade-system)

#### Base Facade

[](#base-facade)

```
abstract class Facade
{
    protected static Container $container;

    public static function setContainer(Container $container): void
    {
        static::$container = $container;
    }

    public static function getFacadeAccessor(): string
    {
        throw new RuntimeException('Facade does not implement getFacadeAccessor method.');
    }

    public static function __callStatic(string $method, array $arguments): mixed
    {
        $instance = static::$container->make(static::getFacadeAccessor());
        return $instance->$method(...$arguments);
    }
}
```

#### Logger Facade

[](#logger-facade)

```
class Logger extends Facade
{
    protected static function getFacadeAccessor(): string
    {
        return LoggerInterface::class;
    }
}

// Usage
Logger::info('Application started');
Logger::error('An error occurred', ['context' => 'data']);
```

### 5. **Migration System**

[](#5-migration-system)

#### Migration Manager

[](#migration-manager)

```
class MigrationManager
{
    private DatabaseAdapterInterface $adapter;
    private SchemaGenerator $generator;
    private array $migrations = [];

    public function runMigrations(): array
    {
        $results = [];

        foreach ($this->migrations as $migration) {
            try {
                $this->runMigration($migration);
                $results[] = ['migration' => $migration, 'status' => 'success'];
            } catch (Exception $e) {
                $results[] = ['migration' => $migration, 'status' => 'failed', 'error' => $e->getMessage()];
            }
        }

        return $results;
    }

    public function rollbackMigrations(): array
    {
        // Rollback migrations
        return [];
    }

    public function getMigrationStatus(): array
    {
        // Get migration status
        return [];
    }
}
```

#### Schema Generator

[](#schema-generator)

```
class SchemaGenerator
{
    private DatabaseAdapterInterface $adapter;

    public function createTable(string $table, array $schema): bool
    {
        $sql = $this->generateCreateTableSQL($table, $schema);
        return $this->adapter->query($sql);
    }

    public function dropTable(string $table): bool
    {
        $sql = "DROP TABLE IF EXISTS {$table}";
        return $this->adapter->query($sql);
    }

    private function generateCreateTableSQL(string $table, array $schema): string
    {
        // Generate CREATE TABLE SQL
        return "CREATE TABLE {$table} (...)";
    }
}
```

### 6. **Logging System**

[](#6-logging-system)

#### Logger Manager

[](#logger-manager)

```
class LoggerManager implements LoggerInterface
{
    private LoggerInterface $logger;
    private array $config;

    public function __construct(array $config = [])
    {
        $this->config = $config;
        $this->initializeLogger();
    }

    public function log($level, string $message, array $context = []): void
    {
        $this->logger->log($level, $message, $context);
    }

    public function emergency(string $message, array $context = []): void
    {
        $this->log(LogLevel::EMERGENCY, $message, $context);
    }

    public function alert(string $message, array $context = []): void
    {
        $this->log(LogLevel::ALERT, $message, $context);
    }

    public function critical(string $message, array $context = []): void
    {
        $this->log(LogLevel::CRITICAL, $message, $context);
    }

    public function error(string $message, array $context = []): void
    {
        $this->log(LogLevel::ERROR, $message, $context);
    }

    public function warning(string $message, array $context = []): void
    {
        $this->log(LogLevel::WARNING, $message, $context);
    }

    public function notice(string $message, array $context = []): void
    {
        $this->log(LogLevel::NOTICE, $message, $context);
    }

    public function info(string $message, array $context = []): void
    {
        $this->log(LogLevel::INFO, $message, $context);
    }

    public function debug(string $message, array $context = []): void
    {
        $this->log(LogLevel::DEBUG, $message, $context);
    }
}
```

---

📚 TÀI LIỆU KỸ THUẬT
-------------------

[](#-tài-liệu-kỹ-thuật)

### Tài liệu chi tiết

[](#tài-liệu-chi-tiết)

📖 [`docs/technical-documentation.md`](docs/technical-documentation.md)

**Nội dung:**

- Container (Dependency Injection)
- Kernel System
- Bootstrapper System
- Database Migration
- Logging System
- Facade Pattern
- Development Guidelines

### Code Examples

[](#code-examples)

#### Container Usage

[](#container-usage)

```
// Create container
$container = new Container();

// Register services
$container->singleton(LoggerInterface::class, Logger::class);
$container->bind(DatabaseInterface::class, MySQLDatabase::class);

// Resolve services
$logger = $container->make(LoggerInterface::class);
$database = $container->make(DatabaseInterface::class);

// Use services
$logger->info('Service resolved successfully');
```

#### Kernel Usage

[](#kernel-usage)

```
// Create kernel
$container = new Container();
$kernel = new ConsoleKernel($container);

// Handle command
$input = new ArgvInput();
$output = new ConsoleOutput();
$exitCode = $kernel->handle($input, $output);
```

#### Facade Usage

[](#facade-usage)

```
// Set container
Facade::setContainer($container);

// Use facades
Logger::info('Application started');
Database::query('SELECT * FROM users');
```

#### Migration Usage

[](#migration-usage)

```
// Create migration manager
$adapter = new DatabaseAdapter();
$manager = new MigrationManager($adapter);

// Run migrations
$results = $manager->runMigrations();

// Check status
$status = $manager->getMigrationStatus();
```

---

🛠️ DEVELOPMENT GUIDELINES
-------------------------

[](#️-development-guidelines)

### Coding Standards

[](#coding-standards)

#### PSR-12 Compliance

[](#psr-12-compliance)

```
