Extension Details
.novaextension/extension2x.png)
- PHP Namespace (resolver)
- by Foxleeay
- 9 Recent Installs | 9 Total Installs
- Import selected PHP classes by resolving their namespace from the workspace.
- Repository
- Bug Reports
-
Read Files
-
This extension is allowed to:
Readme
PHP Namespace Resolver
Experimental release. Unexpected bugs may occur while the extension is being tested and refined.
Features
- Resolve a selected PHP class name by searching the workspace for matching
.phpfiles. - Read the namespace from each matched file and build the corresponding
usestatement. - Prompt a choice palette when a class name is defined in multiple files, so you can pick the right namespace.
- Insert generated imports directly below the current file's
namespacedeclaration, or just below the<?phptag when no namespace is present. - Skip imports that are already present in the current file.
Commands
Import Class
- Searches the workspace for
.phpfiles that define the selected class name. - If a single match is found, its
usestatement is inserted automatically. - If multiple matches are found (same class name, different namespaces), a choice palette lets you select which one to import.
- Recommended for everyday use.
Import All Classes
- Recursively scans the entire workspace for all
.phpfiles that define the selected class name. - Builds and inserts a
usestatement for each match found, skipping imports that already exist. - Useful in projects with modular structure or multiple implementations of the same class name.
Usage
- Select a PHP class name in a PHP file (for example
User). - Run either:
Import Classto import a matching class (choosing from a palette if several are found), orImport All Classesto import all matching classes in the workspace.- The generated
usestatements are added under thenamespaceline in the current file. If the file has no namespace, they are placed just below the<?phptag with a blank separating line.
Limitations
Import All Classesmay lead to conflicting imports if multiple files define homonymous classes.- Alias handling (
use Foo as Bar;) and advanced conflict resolution are not yet implemented. - The resolver relies on standard
namespacedeclarations and may fail on unconventional file layouts.
Release Notes
Version 1.2
Import Classnow prompts a choice palette when the selected class name matches multiple files with different namespaces, letting you pick which one to import.- When only one match is found,
Import Classimports it directly without prompting. - Import statements are now inserted right after the current file's
namespacedeclaration; if no namespace is present, they are inserted just below the<?phptag with a blank separating line. - Added cancellation feedback ("Import cancelled") when the choice palette is dismissed.
Version 1.1
- Added
Import All Classescommand that scans the entire workspace and imports all matching classes for the selected name. - Kept
Import Classcommand behavior limited to the first matching class. - Improved documentation in README to describe both commands and current limitations.
Version 1.0
Initial release