VOOZH about

URL: https://deepwiki.com/hypervel/foundation/2.3-application-paths-and-environment-detection

⇱ Application Paths and Environment Detection | hypervel/foundation | DeepWiki


Loading...
Last indexed: 7 February 2026 (101eff)
Menu

Application Paths and Environment Detection

Purpose and Scope

This document covers the path resolution system and environment detection mechanisms provided by the Application class. These facilities enable the application to locate framework directories (such as config, storage, resources) and determine the current execution environment (such as local, production, or testing).

For information about the Application container's dependency injection capabilities, see Application Container and Dependency Injection. For details about configuration loading and bootstrapping, see Configuration System and Config Provider.


Path Resolution Architecture

The Application class provides a hierarchical path resolution system where all directory paths are derived from a configurable base path. Each path method follows a consistent pattern: it constructs an absolute path by joining the base path with a predefined subdirectory name.

Base Path Configuration

The base path represents the root directory of the application installation. It is set during Application instantiation and can be modified using the setBasePath() method.

src/Application.php82-90

Base Path Initialization:


Sources: src/Application.php82-90 src/Application.php160-165 src/Contracts/Application.php31-40

The setBasePath() method normalizes the path by removing trailing slashes, ensuring consistent path construction across different operating systems.

src/Application.php160-165

Standard Directory Paths

The Application class defines methods for resolving standard framework directories. Each method accepts an optional relative path parameter that is appended to the directory's base location.

MethodBase DirectoryExample UsageTypical Purpose
basePath(){base}$app->basePath('composer.json')Root directory access
path(){base}/app$app->path('Models/User.php')Application code
configPath(){base}/config$app->configPath('app.php')Configuration files
databasePath(){base}/database$app->databasePath('migrations')Database files
langPath(){base}/lang$app->langPath('en')Translation files
publicPath(){base}/public$app->publicPath('index.php')Web-accessible files
resourcePath(){base}/resources$app->resourcePath('views')Asset files
storagePath(){base}/storage$app->storagePath('logs')Runtime storage

Sources: src/Application.php170-244 src/Contracts/Application.php42-82

Path Construction Implementation

All path methods use a common construction pattern implemented through the joinPaths() method:

src/Application.php249-252

This method delegates to the join_paths() helper from the Hypervel\Filesystem package, which handles cross-platform path joining with proper directory separator normalization.

Path Resolution Flow:


Sources: src/Application.php170-252 src/Contracts/Application.php84-87

View Path Configuration Override

Unlike other path methods, viewPath() supports configuration-based customization through the view.config.view_path configuration key. This allows applications to override the default resources/views directory location.

src/Application.php228-236

View Path Resolution:


Sources: src/Application.php228-236 src/Contracts/Application.php72-77

This configuration override mechanism demonstrates how framework paths can be customized without modifying application code, supporting non-standard project structures or deployment requirements.


Environment Detection System

The Application class provides methods for detecting and querying the current execution environment. All environment detection functionality delegates to the Hypervel\Support\Environment service, which is resolved from the application container.

Environment Service Delegation

Environment detection methods retrieve the Environment service instance and delegate to its methods:

src/Application.php259-290

Environment Detection Architecture:


Sources: src/Application.php259-306 src/Contracts/Application.php89-119

Environment Query Methods

The Application class provides both generic and specific environment checking methods:

Generic Environment Detection:

src/Application.php259-266

The environment() method serves two purposes:

  • Without arguments: Returns the current environment name as a string
  • With arguments: Checks if the current environment matches any of the provided environment names, returning a boolean

Predefined Environment Checks:

src/Application.php271-282

These convenience methods provide named checks for common environments:

  • isLocal(): Checks if environment is 'local'
  • isProduction(): Checks if environment is 'production'

Test and Debug Detection:

src/Application.php295-306

  • runningUnitTests(): Returns true if environment is 'testing'
  • hasDebugModeEnabled(): Delegates to Environment::isDebug() to check debug mode status

Environment Detection Usage Patterns

The environment detection system supports multiple usage patterns for conditional logic:

Pattern 1: Direct Environment Name Retrieval


Pattern 2: Single Environment Check


Pattern 3: Multiple Environment Check


Pattern 4: Named Convenience Methods


Sources: src/Application.php259-306 src/Contracts/Application.php89-119


Application Namespace Detection

The Application class provides automatic namespace detection by analyzing the composer.json file's PSR-4 autoload configuration. This enables the framework to determine the application's root namespace.

src/Application.php671-687

Namespace Detection Algorithm:


Sources: src/Application.php671-687 src/Contracts/Application.php202-206

The detection algorithm:

  1. Returns the cached namespace if already detected
  2. Reads and parses composer.json from the base path
  3. Iterates through PSR-4 autoload mappings
  4. Compares the real path of each autoload path against $app->path()
  5. When a match is found, caches and returns the corresponding namespace
  6. Throws RuntimeException if no matching namespace is found

This mechanism allows framework components to dynamically construct fully-qualified class names without hardcoding the application namespace.


Path and Environment Method Summary

Complete Method Reference

Path Resolution Methods:

MethodSignatureReturnsDescription
setBasePath()setBasePath(string $basePath): static$thisSets the application base path
basePath()basePath(string $path = ''): stringAbsolute pathResolves path relative to base
path()path(string $path = ''): stringAbsolute pathResolves path in app/ directory
configPath()configPath(string $path = ''): stringAbsolute pathResolves path in config/ directory
databasePath()databasePath(string $path = ''): stringAbsolute pathResolves path in database/ directory
langPath()langPath(string $path = ''): stringAbsolute pathResolves path in lang/ directory
publicPath()publicPath(string $path = ''): stringAbsolute pathResolves path in public/ directory
resourcePath()resourcePath(string $path = ''): stringAbsolute pathResolves path in resources/ directory
viewPath()viewPath(string $path = ''): stringAbsolute pathResolves path in configured view directory
storagePath()storagePath(string $path = ''): stringAbsolute pathResolves path in storage/ directory
joinPaths()joinPaths(string $basePath, string $path = ''): stringAbsolute pathJoins path segments with proper separators

Environment Detection Methods:

MethodSignatureReturnsDescription
environment()environment(...$environments): bool|stringstring or boolGets or checks environment
isLocal()isLocal(): boolboolChecks if environment is 'local'
isProduction()isProduction(): boolboolChecks if environment is 'production'
detectEnvironment()detectEnvironment(): stringstringRetrieves current environment name
runningUnitTests()runningUnitTests(): boolboolChecks if environment is 'testing'
hasDebugModeEnabled()hasDebugModeEnabled(): boolboolChecks if debug mode is enabled

Namespace Detection Methods:

MethodSignatureReturnsDescription
getNamespace()getNamespace(): stringstringDetects application namespace from composer.json

Sources: src/Application.php160-290 src/Application.php671-687 src/Contracts/Application.php31-119 src/Contracts/Application.php202-206


Integration with Framework Components

The path resolution and environment detection systems are used throughout the Hypervel framework:

Path Resolution Usage:


Environment Detection Usage:


Sources: src/Application.php170-306

These systems provide a centralized, consistent interface for framework components to access application resources and adapt behavior based on the execution environment, ensuring proper separation of concerns and maintainability across the framework.