PHPackages                             responsive-sk/slim4-paths - 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. [Framework](/categories/framework)
4. /
5. responsive-sk/slim4-paths

ActiveLibrary[Framework](/categories/framework)

responsive-sk/slim4-paths
=========================

Complete path management solution for PHP applications with zero dependencies, built-in filesystem operations, enhanced security, framework presets (Laravel, Slim4, Mezzio), and comprehensive validation

6.1.0(3mo ago)08011MITPHPPHP ^8.1

Since May 25Pushed 3mo agoCompare

[ Source](https://github.com/responsive-sk/slim4-paths)[ Packagist](https://packagist.org/packages/responsive-sk/slim4-paths)[ RSS](/packages/responsive-sk-slim4-paths/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (3)Versions (10)Used By (1)

Slim4 Paths - Enhanced Path Management
======================================

[](#slim4-paths---enhanced-path-management)

A comprehensive, secure path management package for PHP applications with advanced features for modern web development.

Features
--------

[](#features)

- **Framework Presets** - Laravel, Slim 4, Mezzio/Laminas presets
- **Secure Path Joining** - Prevents path traversal attacks
- **50+ Predefined Paths** - Framework-specific directory structures
- **Cross-Platform Compatibility** - Works on Windows, Linux, macOS
- **Auto-Directory Creation** - Automatic directory structure setup
- **Security Validation** - Input validation and path sanitization
- **Framework Agnostic** - Works with any PHP framework
- **Orbit CMS Support** - Built-in support for content management
- **Module System Integration** - Advanced module path resolution

Installation
------------

[](#installation)

```
composer require responsive-sk/slim4-paths
```

Framework Presets
-----------------

[](#framework-presets)

**NEW in v3.0** Use framework-specific directory presets for instant setup:

### Laravel Preset

[](#laravel-preset)

```
use ResponsiveSk\Slim4Paths\Paths;

$paths = Paths::withPreset('laravel', __DIR__);

// Laravel-specific paths
echo $paths->get('app');           // /path/to/app
echo $paths->get('controllers');   // /path/to/app/Http/Controllers
echo $paths->get('models');        // /path/to/app/Models
echo $paths->get('views');         // /path/to/resources/views
echo $paths->get('storage');       // /path/to/storage
echo $paths->get('migrations');    // /path/to/database/migrations
echo $paths->get('uploads');       // /path/to/storage/app/public
```

### Slim 4 Preset

[](#slim-4-preset)

```
$paths = Paths::withPreset('slim4', __DIR__);

// Slim 4-specific paths
echo $paths->get('src');           // /path/to/src
echo $paths->get('handlers');      // /path/to/src/Handler
echo $paths->get('actions');       // /path/to/src/Action
echo $paths->get('templates');     // /path/to/templates
echo $paths->get('cache');         // /path/to/var/cache
echo $paths->get('logs');          // /path/to/var/log
echo $paths->get('uploads');       // /path/to/var/uploads
```

### Mezzio/Laminas Preset

[](#mezziolaminas-preset)

```
$paths = Paths::withPreset('mezzio', __DIR__);
// or
$paths = Paths::withPreset('laminas', __DIR__);

// Mezzio-specific paths
echo $paths->get('src');           // /path/to/src
echo $paths->get('handlers');      // /path/to/src/Handler
echo $paths->get('modules');       // /path/to/modules
echo $paths->get('data');          // /path/to/data
echo $paths->get('content');       // /path/to/content
echo $paths->get('database');      // /path/to/data/database
```

### Available Presets

[](#available-presets)

```
// Get all available presets
$presets = Paths::getAvailablePresets();
// ['laravel', 'slim4', 'mezzio', 'laminas']

// Get preset information
$info = Paths::getPresetInfo();
foreach ($info as $key => $preset) {
    echo "{$key}: {$preset['name']} - {$preset['description']}\n";
}
```

Basic Usage
-----------

[](#basic-usage)

```
use ResponsiveSk\Slim4Paths\Paths;

// Initialize with base path and configuration
$paths = new Paths('/path/to/project', [
    'templates' => '/path/to/project/templates',
    'content' => '/path/to/project/content',
    // ... more paths
]);

// Basic path access
$templatePath = $paths->templates();
$configPath = $paths->config();
$publicPath = $paths->public();
```

Convenience Methods
-------------------

[](#convenience-methods)

### `Paths::fromHere(__DIR__, $levelsUp = 3)`

[](#pathsfromhere__dir__-levelsup--3)

Convenience method to create a `Paths` instance from the current file location. Useful in modular systems.

```
use ResponsiveSk\Slim4Paths\Paths;

// From a file at src/Modules/Core/SomeClass.php, go up 3 levels to project root
$paths = Paths::fromHere(__DIR__, 3);

// From a file at src/Services/SomeService.php, go up 2 levels to project root
$paths = Paths::fromHere(__DIR__, 2);

// Use resolved paths
$dbPath = $paths->storage('database.db');
$logPath = $paths->logs('app.log');
```

**Benefits:**

- ✅ More expressive than manual path construction
- ✅ Less error-prone than counting `../` manually
- ✅ Works in tests, CLI, without DI containers
- ✅ Automatic path validation with clear error messages

### `Paths::fromEnv($envVar = 'APP_BASE_PATH')`

[](#pathsfromenvenvvar--app_base_path)

Create a `Paths` instance from an environment variable. Useful for applications that need environment-based configuration.

```
// Set environment variable
putenv('APP_BASE_PATH=/path/to/project');

// Create Paths instance from environment
$paths = Paths::fromEnv();

// Or use custom environment variable
putenv('BASE_PATH=/custom/path');
$paths = Paths::fromEnv('BASE_PATH');
```

Environment-based Usage
-----------------------

[](#environment-based-usage)

Combine environment-based initialization with existing path methods:

```
// Environment-based initialization
$paths = Paths::fromEnv(); // or Paths::fromHere(__DIR__, 3)

// Use existing path methods
$paths->base();                    // Project root: /path/to/project
$paths->public();                  // Public directory: /path/to/project/public
$paths->config();                  // Config directory: /path/to/project/config
$paths->src();                     // Source directory: /path/to/project/src

// Configured paths work as expected
$paths->storage('database.db');    // /path/to/project/var/storage/database.db
$paths->logs('app.log');           // /path/to/project/var/logs/app.log
```

Core Path Methods
-----------------

[](#core-path-methods)

### Basic Directories

[](#basic-directories)

```
$paths->base()          // Project root directory
$paths->config()        // Configuration directory
$paths->src()           // Source code directory
$paths->public()        // Public web directory
$paths->var()           // Variable/runtime directory
$paths->vendor()        // Vendor directory
```

### Template System

[](#template-system)

```
$paths->templates()                    // Main templates directory
$paths->views()                        // Views directory
$paths->layouts('main.php')            // Layout templates
$paths->partials('header.php')         // Partial templates
```

### Content Management (Orbit CMS)

[](#content-management-orbit-cms)

```
$paths->content()                      // Content root directory
$paths->articles('post.md')            // Article files
$paths->orbit()                        // Orbit database directory
$paths->orbitDatabase('app')           // Orbit database file (app.db)
```

### Module System

[](#module-system)

```
$paths->moduleConfig('Core/Storage')           // Module config file
$paths->moduleRoutes('Core/Template')          // Module routes file
$paths->moduleTemplates('Optional/Blog')       // Module templates directory
```

### Asset Management

[](#asset-management)

```
$paths->css('app.css')             // CSS files
$paths->js('main.js')              // JavaScript files
$paths->images('logo.png')         // Image files
$paths->fonts('roboto.woff2')      // Font files
$paths->media('video.mp4')         // Media files
```

### Development Tools

[](#development-tools)

```
$paths->docs('api.md')             // Documentation files
$paths->scripts('deploy.sh')       // Script files
$paths->bin('console')             // Executable files
$paths->tests('UserTest.php')      // Test files
```

### Security &amp; Storage

[](#security--storage)

```
$paths->keys('private.key')        // Security keys
$paths->exports('data.json')       // Export files
$paths->imports('import.csv')      // Import files
$paths->logs('app.log')            // Log files
$paths->cache('views')             // Cache files
$paths->storage('uploads')         // Storage files
```

### Localization

[](#localization)

```
$paths->lang('en', 'messages.php')     // Language files
$paths->translations('app.po')          // Translation files
$paths->locales()                       // Locales directory
```

Secure Path Joining
-------------------

[](#secure-path-joining)

The `getPath()` method provides secure path joining with built-in protection against path traversal attacks:

```
// Secure path joining
$safePath = $paths->getPath($baseDir, $relativePath);

// Automatic validation
try {
    $maliciousPath = $paths->getPath('/safe/dir', '../../../etc/passwd');
} catch (InvalidArgumentException $e) {
    // Path traversal detected and blocked
    echo $e->getMessage(); // "Path traversal detected in: ../../../etc/passwd"
}
```

### Security Features

[](#security-features)

- **Path Traversal Protection** - Detects and blocks `..` sequences
- **Home Directory Protection** - Blocks `~` access
- **Input Validation** - Validates all path components
- **Cross-Platform Safety** - Handles different directory separators

Configuration
-------------

[](#configuration)

### Basic Configuration

[](#basic-configuration)

```
$config = [
    'base_path' => '/path/to/project',
    'paths' => [
        'templates' => '/path/to/project/templates',
        'content' => '/path/to/project/content',
        'public' => '/path/to/project/public',
        // ... more paths
    ]
];

$paths = new Paths($config['base_path'], $config['paths']);
```

Framework Integration
---------------------

[](#framework-integration)

### Slim Framework

[](#slim-framework)

```
use ResponsiveSk\Slim4Paths\Paths;
use Slim\Factory\AppFactory;

$app = AppFactory::create();

// Add Paths to container
$container = $app->getContainer();
$container->set(Paths::class, function() {
    $config = require 'config/paths.php';
    return new Paths($config['base_path'], $config['paths']);
});

// Use in routes
$app->get('/template/{name}', function ($request, $response, $args) {
    $paths = $this->get(Paths::class);
    $templatePath = $paths->templates($args['name'] . '.php');

    if (!file_exists($templatePath)) {
        throw new \Slim\Exception\HttpNotFoundException($request);
    }

    // Render template...
});
```

Orbit CMS Integration
---------------------

[](#orbit-cms-integration)

This package includes built-in support for Orbit-style content management:

```
// Article management
$articlePath = $paths->articles('getting-started.md');
$articlesDir = $paths->articles();

// Database management
$appDb = $paths->orbitDatabase('app');      // var/orbit/app.db
$markDb = $paths->orbitDatabase('mark');    // var/orbit/mark.db
$cacheDb = $paths->orbitDatabase('cache');  // var/orbit/cache.db

// Content organization
$contentRoot = $paths->content();           // content/
$docsContent = $paths->content('docs');     // content/docs/
```

Module System Support
---------------------

[](#module-system-support)

Advanced module path resolution for modular applications:

```
// Module configuration
$storageConfig = $paths->moduleConfig('Core/Storage');
// Result: src/Modules/Core/Storage/config.php

// Module routes
$templateRoutes = $paths->moduleRoutes('Core/Template');
// Result: src/Modules/Core/Template/routes.php

// Module templates
$blogTemplates = $paths->moduleTemplates('Optional/Blog');
// Result: src/Modules/Optional/Blog/templates/

$blogArticleTemplate = $paths->moduleTemplates('Optional/Blog', 'article.php');
// Result: src/Modules/Optional/Blog/templates/article.php
```

Security Best Practices
-----------------------

[](#security-best-practices)

### Always Use Secure Path Joining

[](#always-use-secure-path-joining)

```
// Good - secure path joining
$filePath = $paths->getPath($baseDir, $userInput);

// Bad - vulnerable to path traversal
$filePath = $baseDir . '/' . $userInput;
```

### Validate User Input

[](#validate-user-input)

```
function loadUserFile(Paths $paths, string $filename)
{
    // Validate filename
    if (!preg_match('/^[a-zA-Z0-9_-]+\.txt$/', $filename)) {
        throw new InvalidArgumentException('Invalid filename');
    }

    // Use secure path joining
    $filePath = $paths->getPath($paths->uploads(), $filename);

    return file_get_contents($filePath);
}
```

### Directory Traversal Protection

[](#directory-traversal-protection)

The package automatically protects against common attacks:

```
// These will throw InvalidArgumentException
$paths->getPath('/safe/dir', '../../../etc/passwd');
$paths->getPath('/safe/dir', '~/sensitive/file');
$paths->getPath('/safe/dir', 'file/../../../etc/passwd');
```

Testing
-------

[](#testing)

```
use PHPUnit\Framework\TestCase;
use ResponsiveSk\Slim4Paths\Paths;

class PathsTest extends TestCase
{
    public function testSecurePathJoining()
    {
        $paths = new Paths('/project', ['uploads' => '/project/uploads']);

        // Valid path
        $validPath = $paths->getPath($paths->uploads(), 'file.txt');
        $this->assertEquals('/project/uploads/file.txt', $validPath);

        // Invalid path should throw exception
        $this->expectException(InvalidArgumentException::class);
        $paths->getPath($paths->uploads(), '../../../etc/passwd');
    }
}
```

Requirements
------------

[](#requirements)

- PHP 8.1 or higher
- No additional dependencies

License
-------

[](#license)

MIT License

Contributing
------------

[](#contributing)

1. Fork the repository
2. Create a feature branch
3. Add tests for new functionality
4. Ensure all tests pass
5. Submit a pull request

Changelog
---------

[](#changelog)

### Version 2.0.0

[](#version-200)

- Added 30+ predefined path methods
- Enhanced security with path traversal protection
- Added Orbit CMS support
- Added module system integration
- Added comprehensive test coverage
- Breaking changes from 1.x (see migration guide)

### Version 1.0.0

[](#version-100)

- Initial release
- Basic path management functionality

###  Health Score

42

—

FairBetter than 89% of packages

Maintenance88

Actively maintained with recent releases

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~37 days

Recently: every ~56 days

Total

8

Last Release

91d ago

Major Versions

v1.0.0 → 2.0.02025-06-19

2.2.0 → 3.0.02025-07-12

3.0.0 → 5.0.02025-07-12

5.0.0 → 6.0.02025-07-14

### Community

Maintainers

![](https://www.gravatar.com/avatar/a9ca94d5516a8f930325df47de8418a33caf484280105d108a693533c73d4699?d=identicon)[evan70](/maintainers/evan70)

---

Top Contributors

[![evan70](https://avatars.githubusercontent.com/u/67433?v=4)](https://github.com/evan70 "evan70 (7 commits)")

---

Tags

laminaslaravelmezzionativephpslim4phpfilesystemframeworklaravellaminasvalidationsecurityslimpathscmsmezziofile-operationssanitizationslim4zero-dependenciespresetsorbitpath-traversalencoding-protection

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/responsive-sk-slim4-paths/health.svg)

```
[![Health](https://phpackages.com/badges/responsive-sk-slim4-paths/health.svg)](https://phpackages.com/packages/responsive-sk-slim4-paths)
```

###  Alternatives

[slim/php-view

Render PHP view scripts into a PSR-7 Response object.

2739.7M92](/packages/slim-php-view)[kompo/kompo

Laravel &amp; Vue.js FullStack Components for Rapid Application Development

11812.4k21](/packages/kompo-kompo)[dragon-code/support

Support package is a collection of helpers and tools for any project.

238.7M100](/packages/dragon-code-support)[luyadev/luya

LUYA is a scalable web framework and content management system with the goal to please developers, clients and users alike.

8086.9k2](/packages/luyadev-luya)[phphleb/webrotor

Asynchronous PHP web server for shared hosting

631.5k1](/packages/phphleb-webrotor)[gdg-tangier/cloud-pubsub

Google Cloud pub-sub for laravel

5054.9k](/packages/gdg-tangier-cloud-pubsub)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
