Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laminas File Laravel Package

laminas/laminas-file

Laminas File provides file upload and transfer handling for Laminas applications. It includes HTTP upload adapters that manage uploaded files, expose metadata, and integrate with validators and filters for safe, flexible file processing.

Deep Wiki
Context7

Getting Started

laminas/laminas-file is a small, archived utility package. Its day-to-day value is narrow: it scans PHP files and tells you which classes are declared in them. It does not autoload, resolve PSR-4 namespaces, or register anything with Composer — it is a class-file locator, typically used by CLI tooling, legacy module discovery, or code-generation utilities.

Install it only if you are maintaining an existing consumer:

composer require laminas/laminas-file

Start by reading two files:

  • src/ClassFileLocator.php — the iterator that walks directories and filters to PHP files containing classes.
  • src/PhpClassFile.php — an SplFileInfo subclass that exposes the classes found in a file.

Minimal first use case — build an in-memory map of class name to file path:

use Laminas\File\ClassFileLocator;

$locator = new ClassFileLocator(__DIR__ . '/src');

$classMap = [];
foreach ($locator as $file) {
    foreach ($file->getClasses() as $className) {
        $classMap[$className] = $file->getPathname();
    }
}

var_export($classMap);

The locator is lazy: files are inspected as you iterate. For a realistic project, run this from a CLI command or build script, not from a web request.

Implementation Patterns

Build a classmap artifact once, then cache it. The locator tokenizes PHP files, so it is not cheap. Generate a JSON/PHP array classmap in CI or a console command and load that at runtime:

$classMap = json_decode(file_get_contents('var/classmap.json'), true);

Use it for interface/implementation discovery in small, controlled directories. Scan your own src/, filter the resulting class names, then verify with reflection before instantiating:

foreach ($locator as $file) {
    foreach ($file->getClasses() as $class) {
        if (!class_exists($class)) {
            continue;
        }
        $reflection = new ReflectionClass($class);
        if ($reflection->implementsInterface(MyHookInterface::class)) {
            $hooks[] = $reflection->newInstance();
        }
    }
}

Do not point this at vendor/ unless you deliberately want to discover third-party classes; the scan cost grows quickly.

Wrap the locator in a small service. Keep the package behind your own interface so replacing it later is a one-file change:

final class SourceClassMap
{
    public function build(string $directory): array
    {
        $map = [];
        foreach (new ClassFileLocator($directory) as $file) {
            foreach ($file->getClasses() as $class) {
                $map[$class] = $file->getRealPath();
            }
        }
        return $map;
    }
}

Use PhpClassFile as a normal SplFileInfo. Once you have a result you can call getPathname(), getRealPath(), getMTime(), and other standard methods — useful for cache invalidation or reporting.

Integrate with legacy Zend/Laminas module tooling carefully. If an existing application already depends on this package, isolate the call sites and document that the dependency is archived. Do not introduce it into new code solely for class discovery; Composer’s classmap generator or a short Symfony Finder + tokenizer script covers most modern use cases.

Prefer the underlying scanner for custom needs. If you need more than “which classes are in this file,” use Laminas\Code\Scanner\FileScanner directly rather than contorting the locator.

Gotchas and Tips

  • The package is archived. There will be no new features or security fixes. Pin the exact version, and plan a fork or replacement. The BSD-3-Clause license makes forking viable.
  • It locates; it does not load. Finding a class name and file path does not make the class autoloadable. You still need Composer autoloading, an explicit require, or a custom autoloader.
  • Tokenization is the cost. Every candidate PHP file is scanned. Exclude tests, fixtures, generated code, and vendor directories. Cache aggressively.
  • Multiple classes per file are possible. getClasses() returns a collection; never assume one class per file or use the filename as the class name.
  • Interfaces, traits, and enums may not behave as you expect. The scanner separates classes from interfaces and traits; verify what your version returns for interface-only or trait-only files. Older releases may predate enum support.
  • Malformed PHP can surface scanner warnings or exceptions. Run scans in a controlled CLI context, catch exceptions around unreadable directories, and avoid printing raw parser warnings into user-facing output.
  • Symlinks and hidden directories are easy to miss. The default recursive iteration behavior may not follow symlinks; set iterator flags explicitly if your tree relies on them.
  • Conditional declarations and class_alias are invisible. A class declared inside an if block or aliased dynamically will not be reliably discovered by static token scanning.
  • Case sensitivity matters. Class names come from tokens; filesystem paths may be case-insensitive on some platforms. Normalize before comparing.
  • Debugging tip: when a file is unexpectedly skipped, inspect it with token_get_all() or FileScanner directly. Also run composer why laminas/laminas-file to understand what is actually pulling the dependency in.
  • Extension point: subclass ClassFileLocator and override its acceptance logic if you need custom file filtering. Keep such subclasses small and covered by tests, since upstream is frozen.
  • Replacement path: for most modern projects, Composer’s classmap generation, symfony/finder plus token_get_all(), or roave/better-reflection is a better-supported choice.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
coleus/frame
thtg88/journalism
filagora/filagora-ai-forums
rlacerda83/query-parser
socialdept/atp-orm
cboxdk/laravel-assistant-client
socialdept/atp-resolver
socialdept/tenant-domains
tautvydasr/blade-class-names
socialdept/color-scales
maherelgamil/controller
coleus/widgets
coleus/table
coleus/users
coleus/music
coleus/health
coleus/calendar
coleus/notes
coleus/support
coleus/settings