1. Go to this page and download the library: Download responsive-sk/slim4-paths library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
// 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";
}
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();
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');
// 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 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