Import & Export

Importing Code

Importing Code to Stellify

Import individual PHP files, classes, and code snippets into Stellify using the Stellify Importer tool.

Overview

The Stellify Importer allows you to:

  • Import individual PHP files
  • Bring in external libraries
  • Add third-party code to your project
  • Parse and structure existing code

Unlike the Laravel Importer which imports entire projects, this tool is for selective imports.

Installation

Via Composer

composer global require stellify/importer

Via NPM (CLI tool)

npm install -g @stellify/importer

Via Download

Download the standalone binary from Stellify Releases.

Basic Usage

Import Single File

stellify-import file path/to/YourClass.php

The importer:

  1. Parses the PHP file
  2. Extracts class structure
  3. Uploads to your Stellify project
  4. Maintains namespace and imports

Import Multiple Files

stellify-import files path/to/directory/*.php

Or specify multiple paths:

stellify-import files \
  app/Services/EmailService.php \
  app/Services/PaymentService.php \
  app/Services/NotificationService.php

Import Directory

stellify-import directory app/Services

Recursively imports all PHP files in directory.

Configuration

Initial Setup

First run prompts for configuration:

stellify-import config

You'll be asked:

  • API URL: Default is https://api.stellisoft.com
  • API Token: Generate from Stellify settings
  • Project ID: Your project's UUID

Configuration saved to ~/.stellify/config.json.

Per-Project Configuration

Create .stellify.json in project root:

{
  "api_url": "https://api.stellisoft.com",
  "api_token": "your_token_here",
  "project_id": "your_project_uuid",
  "default_namespace": "App",
  "exclude": [
    "tests/*",
    "vendor/*"
  ]
}

Import Options

Namespace Mapping

Map local namespaces to Stellify structure:

stellify-import file MyClass.php --namespace="App\\Services"

Without this, importer uses the namespace from the file.

Overwrite Existing

Replace existing classes:

stellify-import file MyClass.php --force

Warning: Overwrites without backup. Use with caution.

Dry Run

Preview what would be imported:

stellify-import file MyClass.php --dry-run

Shows:

  • Files to be imported
  • Classes detected
  • Methods found
  • Potential conflicts

Skip Dependencies

Don't import use statements:

stellify-import file MyClass.php --skip-dependencies

Useful when dependencies already exist in Stellify.

What Gets Imported

Classes

Full class structure including:

  • Properties (public, protected, private)
  • Methods and their code
  • Constants
  • Traits used
  • Interfaces implemented
  • Documentation comments

Example:

// Your file: EmailService.php
namespace App\Services;

use App\Models\User;
use Illuminate\Support\Facades\Mail;

class EmailService
{
    private $from = 'noreply@example.com';

    public function sendWelcome(User $user)
    {
        Mail::to($user->email)->send(new WelcomeEmail($user));
    }
}

// Imported to Stellify:
Files → Services → EmailService
- Property: $from
- Method: sendWelcome(User $user)
- Uses: User, Mail

Traits

stellify-import file MyTrait.php

Traits imported with:

  • Methods
  • Properties
  • Documentation

Interfaces

stellify-import file MyInterface.php

Interfaces imported with:

  • Method signatures
  • Constants
  • Documentation

Enums (PHP 8.1+)

stellify-import file Status.php

Enums imported with:

  • Cases
  • Methods
  • Backed values

Advanced Usage

Import from URL

Import directly from a URL:

stellify-import url https://example.com/path/to/Class.php

Import from GitHub

Import from GitHub repository:

stellify-import github user/repo --file=src/MyClass.php

Or entire directory:

stellify-import github user/repo --directory=src/Services

Import Composer Package

Import specific classes from a Composer package:

stellify-import composer vendor/package --class=ClassName

Example:

stellify-import composer guzzlehttp/guzzle --class=Client

Handling Dependencies

Auto-Import Dependencies

Automatically import required classes:

stellify-import file MyClass.php --with-dependencies

Analyzes use statements and imports those too.

Dependency Resolution

If a class uses external classes:

use App\Models\User;
use App\Services\EmailService;

Importer:

  1. Checks if classes exist in Stellify
  2. If not, prompts to import them
  3. Or skips if --skip-dependencies flag used

Working with Composer Packages

Selective Import

Import specific classes from vendor:

stellify-import vendor-class "Vendor\\Package\\ClassName"

Example:

stellify-import vendor-class "Symfony\\Component\\HttpFoundation\\Request"

Package Index

List available classes in a package:

stellify-import list-package vendor/package

Common Packages

Some packages are pre-indexed for easy import:

  • guzzlehttp/guzzle
  • symfony/*
  • laravel/framework
  • monolog/monolog
stellify-import package guzzlehttp/guzzle

Code Transformation

PSR Compliance

Auto-format code to PSR-12:

stellify-import file MyClass.php --format-psr12

Namespace Conversion

Change namespace during import:

stellify-import file Legacy\\MyClass.php --target-namespace="App\\Modern"

Batch Import

From File List

Create import-list.txt:

app/Services/EmailService.php
app/Services/PaymentService.php
app/Helpers/StringHelper.php

Import all:

stellify-import batch import-list.txt

From Git Changes

Import only files changed in last commit:

stellify-import git-changed --commits=1

Or since a specific commit:

stellify-import git-changed --since=abc123

Error Handling

Syntax Errors

If file has syntax errors:

Error: Parse error in EmailService.php on line 42
Fix the syntax error and try again, or use --skip-errors

Options:

  • Fix the error locally
  • Use --skip-errors to continue
  • Use --validate first to check before importing

Conflicts

If class already exists:

Conflict: EmailService already exists in project
Options:
[1] Skip this file
[2] Overwrite (--force)
[3] Rename to EmailService_imported
[4] Show differences
[5] Abort import

Missing Dependencies

If required classes not found:

Warning: Class App\Models\User not found
Import User.php first, or use --skip-dependencies

Validation

Pre-Import Validation

Check files before importing:

stellify-import validate path/to/directory

Reports:

  • Syntax errors
  • Missing dependencies
  • Naming conflicts
  • Namespace issues

Post-Import Verification

Verify imported code:

stellify-import verify --class=EmailService

Checks:

  • Class structure matches original
  • All methods imported
  • Dependencies resolved

Integration with IDEs

PhpStorm

Add as External Tool:

  1. Settings → Tools → External Tools
  2. Add new tool "Import to Stellify"
  3. Program: stellify-import
  4. Arguments: file $FilePath$

Now right-click any file → External Tools → Import to Stellify

VSCode

Install extension (if available) or add task:

.vscode/tasks.json:

{
  "label": "Import to Stellify",
  "type": "shell",
  "command": "stellify-import",
  "args": ["file", "${file}"]
}

Command Reference

stellify-import file

Import single PHP file.

Syntax:

stellify-import file <path> [options]

Options:

--namespace=NS     Override namespace
--force           Overwrite existing
--dry-run         Preview only
--skip-dependencies  Don't import use statements
--with-dependencies  Import dependencies automatically
--format-psr12    Format to PSR-12

stellify-import directory

Import all PHP files in directory.

Syntax:

stellify-import directory <path> [options]

Options:

--recursive       Include subdirectories (default: true)
--exclude=PATTERN Exclude files matching pattern
--force           Overwrite existing files

stellify-import github

Import from GitHub repository.

Syntax:

stellify-import github <user/repo> [options]

Options:

--file=PATH       Import specific file
--directory=PATH  Import directory
--branch=NAME     Use specific branch (default: main)

stellify-import validate

Validate files before importing.

Syntax:

stellify-import validate <path>

Examples

Example 1: Import Helper Class

stellify-import file app/Helpers/StringHelper.php

Example 2: Import Service with Dependencies

stellify-import file app/Services/PaymentService.php --with-dependencies

Example 3: Import External Library

stellify-import github guzzle/guzzle --file=src/Client.php

Example 4: Batch Import Services

stellify-import directory app/Services --recursive

Example 5: Import with Namespace Change

stellify-import file old/LegacyClass.php --target-namespace="App\\Modern"

Best Practices

Before Importing

  1. Validate code - Ensure it's syntactically correct
  2. Check dependencies - Know what's required
  3. Review namespaces - Ensure they match your structure
  4. Backup - If overwriting existing code

During Import

  1. Use dry-run first - Preview changes
  2. Import dependencies - Don't skip required classes
  3. Handle conflicts - Review before overwriting
  4. Watch for errors - Check import logs

After Importing

  1. Test in Stellify - Run methods to verify
  2. Check relationships - Ensure dependencies work
  3. Update documentation - Note any changes
  4. Version control - Commit to your repo

Troubleshooting

Import Fails

Error: API authentication failed

  • Check API token in config
  • Regenerate token in Stellify
  • Verify token has import permissions

Error: Project not found

  • Check project ID in config
  • Ensure project exists
  • Verify you have access

Partial Import

Some files imported, others didn't:

stellify-import directory app/Services --verbose

Review detailed logs.

Dependency Issues

Classes not resolving:

stellify-import file MyClass.php --with-dependencies

Auto-imports required classes.

Next Steps


Need help? Check GitHub Issues or contact support.

Please be aware that our documentation is under construction.