question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

make import_namespace detect composer.json

See original GitHub issue

Hi, thanks for this great plugin. It really help me building Laravel app. I have a sugestion. Is is possible for this plugin to read a configuration for namespace in composer.json file?

When using Laravel, default composer.json autoload told that all folder in App directory should be namescaped in app. But, when I use import_namespace this plugin give a full directory url.

Eg. when I run from /User/me/Code/laravel/app/entity/model.php. It should be App\Entity\Model based on composer.json autoload configuration. But, it give me User\me\Code\laravel\app\entity\model.

Here is sample composer.json files:

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "laravel/framework": "5.0.*",
        "league/commonmark": "0.7.*",
        "barryvdh/laravel-ide-helper": "~2.0"
    },
    "require-dev": {
        "phpunit/phpunit": "~4.0",
        "phpspec/phpspec": "~2.1"
    },
    "autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\\": "app/"
        }
    },
    "autoload-dev": {
        "classmap": [
            "tests/TestCase.php"
        ]
    },
    "scripts": {
        "post-install-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "post-update-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "post-create-project-cmd": [
            "php -r \"copy('.env.example', '.env');\"",
            "php artisan key:generate"
        ]
    },
    "config": {
        "preferred-install": "dist"
    }
}

The configuration for namespace is this line:

....
       "psr-4": {
            "App\\": "app/"
        }
....

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:17 (5 by maintainers)

github_iconTop GitHub Comments

5reactions
subdesigncommented, Jul 15, 2016

Added to User Settings the following line and prefix is inserted before the generated part:

 "namespace_prefix": "App",
4reactions
erichardcommented, Oct 11, 2019

Great news everybody !

I finally get it working thanks to code provided by @flashios09 and @dakira.

I will tag this as 2.0 as it’s a huge step forward. You can try the 2.0 release by cloning this repository and checkout the psr4-support branch.

I will test it for a couple of days/weeks before release.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Adding namespace to imported third-party package in ...
Adding namespace to imported third-party package in Composer ... I am importing a third-party package into my project using composer. The composer ......
Read more >
The composer.json schema
Under the psr-4 key you define a mapping from namespaces to paths, relative to the package root. When autoloading a class like Foo\\Bar\\Baz...
Read more >
External dependencies & autoload with Composer
Create the file <module name>/composer.json and paste: ... The classes defined in a namespace can be detected if you ask Composer to scan...
Read more >
Autoloading & Namespaces in PHP - Daggerhart Lab
Enter, the use keyword ... The use keyword “imports” a given namespace into the current context, allowing you to make use of its...
Read more >
Adding a Custom Class - Laracasts
You can create any custom class inside your ./app directory without changing anything in your composer.json file, as long the namespace is correct....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found