Skip to content

Latest commit

Β 

History

History
102 lines (92 loc) Β· 5.26 KB

File metadata and controls

102 lines (92 loc) Β· 5.26 KB

Developer Documentation

This document provides a guide for developers who want to contribute to the CodeIgniter to Laravel Migration Tool.

Project Structure

The project follows a standard Laravel structure, with the core logic located in the app directory.

app/
β”œβ”€β”€ Console/
β”‚   └── Commands/
β”‚       └── MigrateCodeIgniterApp.php   # The main Artisan command that kicks off the migration.
β”œβ”€β”€ Contracts/
β”‚   β”œβ”€β”€ CIAnalyzerInterface.php         # Contract for analyzing a CodeIgniter project.
β”‚   β”œβ”€β”€ CIConverterInterface.php        # Contract for converting CodeIgniter components to Laravel.
β”‚   β”œβ”€β”€ CIMigrationCoordinatorInterface.php # Contract for coordinating the entire migration process.
β”‚   └── NodeProcessorInterface.php      # Contract for processing individual PHP parser nodes.
β”œβ”€β”€ Enums/
β”‚   β”œβ”€β”€ CIVersion.php                   # Enum for CodeIgniter versions.
β”‚   └── LaravelDatabaseDriver.php       # Enum for Laravel database drivers.
β”œβ”€β”€ Factories/
β”‚   β”œβ”€β”€ CIConfigProcessorFactory.php
β”‚   β”œβ”€β”€ CIControllerProcessorFactory.php
β”‚   β”œβ”€β”€ CIDatabaseProcessorFactory.php
β”‚   β”œβ”€β”€ CIModelProcessorFactory.php
β”‚   └── CIRouteProcessorFactory.php
β”œβ”€β”€ Http/
β”‚   └── ...                             # Standard Laravel HTTP kernel.
β”œβ”€β”€ Models/
β”‚   └── ...                             # Standard Laravel models.
β”œβ”€β”€ Providers/
β”‚   β”œβ”€β”€ AppServiceProvider.php
β”‚   └── ConverterServiceProvider.php    # Binds the analyzer and converter implementations.
β”œβ”€β”€ Services/
β”‚   β”œβ”€β”€ FileHandlerService.php          # Handles file system operations.
β”‚   β”œβ”€β”€ LaravelProjectService.php       # Manages the creation and modification of the new Laravel project.
β”‚   β”œβ”€β”€ LaravelProjectSetupService.php  # Sets up a new Laravel project.
β”‚   β”œβ”€β”€ LogService.php                  # Handles logging.
β”‚   β”œβ”€β”€ PromptService.php               # Handles user prompts.
β”‚   β”œβ”€β”€ StatusBarService.php            # Manages the progress bar display.
β”‚   β”œβ”€β”€ Abstracts/
β”‚   β”‚   └── BaseCIMigrationService.php
β”‚   β”œβ”€β”€ Analyzers/
β”‚   β”‚   β”œβ”€β”€ AbstractCIAnalyzerService.php # Base class for analyzers.
β”‚   β”‚   β”œβ”€β”€ CI2AnalyzerService.php
β”‚   β”‚   β”œβ”€β”€ CI3AnalyzerService.php
β”‚   β”‚   └── CI4AnalyzerService.php
β”‚   β”œβ”€β”€ API/
β”‚   β”‚   β”œβ”€β”€ APICIProjectPreparationService.php
β”‚   β”‚   └── APIMigrationService.php
β”‚   β”œβ”€β”€ CLI/
β”‚   β”‚   └── CLIMigrationService.php
β”‚   β”œβ”€β”€ Converters/
β”‚   β”‚   β”œβ”€β”€ AbstractCIConverterService.php # Base class for converters.
β”‚   β”‚   β”œβ”€β”€ CI2ConverterService.php
β”‚   β”‚   β”œβ”€β”€ CI3ConverterService.php
β”‚   β”‚   └── CI4ConverterService.php
β”‚   β”œβ”€β”€ Coordinators/
β”‚   β”‚   β”œβ”€β”€ AbstractCIMigrationCoordinatorService.php
β”‚   β”‚   β”œβ”€β”€ CI3MigrationCoordinatorService.php
β”‚   β”‚   └── CIMigrationCoordinatorService.php # The main service that orchestrates the migration.
β”‚   β”œβ”€β”€ Parsers/
β”‚   β”‚   β”œβ”€β”€ AbstractParserVisitor.php
β”‚   β”‚   β”œβ”€β”€ GenericNodeVisitor.php
β”‚   β”‚   └── NodeProcessors/               # Contains the logic for processing different types of PHP code.
β”‚   β”‚       β”œβ”€β”€ CIConfigNodeProcessorBase.php
β”‚   β”‚       β”œβ”€β”€ CIControllerNodeProcessorBase.php
β”‚   β”‚       β”œβ”€β”€ CIDatabaseNodeProcessorBase.php
β”‚   β”‚       β”œβ”€β”€ CIModelNodeProcessorBase.php
β”‚   β”‚       β”œβ”€β”€ CIRouteNodeProcessorBase.php
β”‚   β”‚       β”œβ”€β”€ CI2/
β”‚   β”‚       β”œβ”€β”€ CI3/
β”‚   β”‚       └── CI4/
β”‚   └── Utility/
β”‚       └── PhpFileParser.php           # A wrapper around nikic/php-parser.
β”œβ”€β”€ Support/
β”‚   β”œβ”€β”€ DatabaseConnectionConfig.php
β”‚   └── DirectoryManager.php
└── Traits/
    β”œβ”€β”€ HasConsoleOutput.php
    β”œβ”€β”€ HasDirectories.php
    └── HasStatusBar.php

Core Concepts

The migration process is broken down into three main phases:

  1. Analysis: The CIAnalyzerInterface implementations scan the CodeIgniter project to identify its structure, version, and components (controllers, models, routes, etc.).
  2. Conversion: The CIConverterInterface implementations take the information from the analysis phase and convert the CodeIgniter components to their Laravel equivalents. This is where the bulk of the work happens.
  3. Coordination: The CIMigrationCoordinatorInterface implementations orchestrate the entire process, from creating the new Laravel project to running the analysis and conversion steps.

The conversion process itself is further broken down by using the nikic/php-parser library to parse the PHP code and then using a series of NodeProcessorInterface implementations to process the different types of nodes in the AST. This allows for a very granular and extensible approach to the conversion.

How to Contribute

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Write your code. Be sure to follow the existing code style and conventions.
  4. Write tests for your code. This is important!
  5. Submit a pull request.