Yii2: build command does not work anymore in 2.1

Created on 9 Apr 2018  路  4Comments  路  Source: yiisoft/yii2

What steps will reproduce the problem?

git checkout 2.1
$ build/build

This is Yii version 2.1.0-dev.

The following commands are available:

- help                        Provides help information about console commands.
    help/index (default)      Displays available commands or the detailed information
    help/list                 List all available controllers and actions in machine readable format.
    help/list-action-options  List all available options for the $action in machine readable format.
    help/usage                Displays usage information for $action.


To see the help of each command, enter:

  build help <command-name>

What is the expected result?

It should list all other commands from build/controllers directory.

What do you get instead?

see above.

Additional info

config code looks correct to me, so it seems something is broken:

https://github.com/yiisoft/yii2/blob/9ba943c4ad40436e79e3c955e5bc19a5ff919f34/build/build#L32-L39

| Q | A
| ---------------- | ---
| Yii version | 2.1-dev
| PHP version |
| Operating system |

bug

Most helpful comment

That's probably because Yii's autoloading has been removed, so settings alias (Yii::setAlias('@yii/build', __DIR__);) no longer affects autoloading. yii\build namespace should be added to composer.json autoloading rules.

All 4 comments

Function class_exists() returns false for controllers classes here:

https://github.com/yiisoft/yii2/blob/b62077d58108db449e413eb27bafddb72d14eba4/framework/console/controllers/HelpController.php#L277-L290

It seems like class autoloading doesn't work.

That's probably because Yii's autoloading has been removed, so settings alias (Yii::setAlias('@yii/build', __DIR__);) no longer affects autoloading. yii\build namespace should be added to composer.json autoloading rules.

I see, so whenever I want to introduce a new namespace in a project one needs to run a composer command? Not sure I like this...

I see, so whenever I want to introduce a new namespace in a project one needs to run a composer command? Not sure I like this...

No, you can also dynamically add namespaces.

For example this issue can be fixed with:

foreach ($composerAutoload as $autoload) {
    if (file_exists($autoload)) {
        $autoloader = require $autoload;
        $autoloader->setPsr4("yii\\build\\", __DIR__);
        $vendorPath = dirname($autoload);
        break;
    }
}

Pay attention to these lines:

...
        $autoloader = require $autoload;
        $autoloader->setPsr4("yii\\build\\", __DIR__);
...

In this case, you do not need to edit composer.json.


But I think that adding lines to composer.json is a cleaner and more explicit way to declare a new namespace in the case of build app.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sobit picture sobit  路  3Comments

chaintng picture chaintng  路  3Comments

jpodpro picture jpodpro  路  3Comments

AstRonin picture AstRonin  路  3Comments

Locustv2 picture Locustv2  路  3Comments