Closed kids-return closed 5 years ago
The autoloading feature is very useful when developing extensions meant for vendor
in another folder or when creating extensions.
Forgive me for not understanding, can you tell me your opinion? 🥺 or 👍 👎
@kids-return Sorry, I didn't understand. Can you please give more explanation of your idea.
@kids-return There's no simply yes or no from my side. I was just pointing out a useful feature at the moment, which should be kept, if there's no better alternative. It looks like your proposal touches that part.
before
'aliases' => yii\base\Aliases#9
(
[yii\base\Aliases:aliases] => [
'@yii' => [
'@yii/widgets' => '/data/wwwroot/yii3/vendor/yiisoft/view/src/widgets'
'@yii/web/tests' => '/data/wwwroot/yii3/vendor/yiisoft/yii-web/tests'
'@yii/web' => '/data/wwwroot/yii3/vendor/yiisoft/yii-web/src'
'@yii/view' => '/data/wwwroot/yii3/vendor/yiisoft/view/src/view'
'@yii/tests' => '/data/wwwroot/yii3/vendor/yiisoft/yii-core/tests'
'@yii/swiftmailer' => '/data/wwwroot/yii3/vendor/yiisoft/yii-swiftmailer/src'
'@yii/rest' => '/data/wwwroot/yii3/vendor/yiisoft/yii-rest/src'
'@yii/log' => '/data/wwwroot/yii3/vendor/yiisoft/log/src'
'@yii/jquery' => '/data/wwwroot/yii3/vendor/yiisoft/yii-jquery/src'
'@yii/di' => '/data/wwwroot/yii3/vendor/yiisoft/di/src'
'@yii/db/tests' => '/data/wwwroot/yii3/vendor/yiisoft/db/tests'
'@yii/db' => '/data/wwwroot/yii3/vendor/yiisoft/db/src'
'@yii/console' => '/data/wwwroot/yii3/vendor/yiisoft/yii-console/src'
'@yii/captcha' => '/data/wwwroot/yii3/vendor/yiisoft/yii-captcha/src'
'@yii/cache/tests' => '/data/wwwroot/yii3/vendor/yiisoft/cache/tests'
'@yii/cache' => '/data/wwwroot/yii3/vendor/yiisoft/cache/src'
'@yii/bootstrap4' => '/data/wwwroot/yii3/vendor/yiisoft/yii-bootstrap4/src'
'@yii/app' => '/data/wwwroot/yii3/vendor/yiisoft/yii-base-cli/src'
'@yii/activerecord/tests' => '/data/wwwroot/yii3/vendor/yiisoft/active-record/tests'
'@yii/activerecord' => '/data/wwwroot/yii3/vendor/yiisoft/active-record/src'
'@yii' => '/data/wwwroot/yii3/vendor/yiisoft/yii-core/src'
]
'@Psr' => [
'@Psr/SimpleCache' => '/data/wwwroot/yii3/vendor/psr/simple-cache/src'
'@Psr/Log' => '/data/wwwroot/yii3/vendor/psr/log/Psr/Log'
'@Psr/Http/Message' => '/data/wwwroot/yii3/vendor/psr/http-message/src'
'@Psr/Container' => '/data/wwwroot/yii3/vendor/psr/container/src'
]
'@Doctrine' => [
'@Doctrine/Common/Lexer' => '/data/wwwroot/yii3/vendor/doctrine/lexer/lib/Doctrine/Common/Lexer'
]
'@Egulias' => [
'@Egulias/EmailValidator' => '/data/wwwroot/yii3/vendor/egulias/email-validator/EmailValidator'
]
'@Dotenv' => '/data/wwwroot/yii3/vendor/vlucas/phpdotenv/src'
'@hiqdev' => [
'@hiqdev/composer/config' => '/data/wwwroot/yii3/vendor/hiqdev/composer-config-plugin/src'
]
'@root' => '/data/wwwroot/yii3'
'@vendor' => '/data/wwwroot/yii3/vendor'
'@public' => '/data/wwwroot/yii3/public'
'@runtime' => '/data/wwwroot/yii3/runtime'
'@bower' => '/data/wwwroot/yii3/vendor/bower-asset'
'@npm' => '/data/wwwroot/yii3/vendor/npm-asset'
'@app' => '/data/wwwroot/yii3/vendor/yiisoft/yii-base-cli/src'
'@web' => ''
]
)
after
'aliases' => yii\base\Aliases#9
(
[yii\base\Aliases:aliases] => [
'@root' => '/data/wwwroot/yii3'
'@vendor' => '@root/vendor'
'@public' => '@root/public'
'@runtime' => '@root/runtime'
'@bower' => '@vendor/bower-asset'
'@npm' => '@vendor/npm-asset'
'@app' => '/data/wwwroot/yii3/vendor/yiisoft/yii-base-cli/src'
'@web' => '/'
'@yii' => '/data/wwwroot/yii3/vendor/yiisoft/yii-core/src'
'@yiisoft' => '/data/wwwroot/yii3/vendor/yiisoft'
'@vendor2' => '/data/wwwroot/yii3/vendor2/yiisoft'
]
)
'psrAliases' => yii\base\PsrAliases#9
(
[yii\base\Aliases:aliases] => [
'@yii' => [
0 => '/data/wwwroot/yii3/vendor/yiisoft/yii-core/src'
]
'@yii/tests' => [
0 => '/data/wwwroot/yii3/vendor/yiisoft/yii-core/tests'
]
'@yii/rest' => [
0 => '/data/wwwroot/yii3/vendor/yiisoft/yii-rest/src'
]
'@yii/view' => [
0 => '/data/wwwroot/yii3/vendor/yiisoft/view/src/view'
]
'@yii/widgets' => [
0 => '/data/wwwroot/yii3/vendor/yiisoft/view/src/widgets'
]
'@Psr/Http/Message' => [
0 => '/data/wwwroot/yii3/vendor/psr/http-message/src'
]
'@yii/web' => [
0 => '/data/wwwroot/yii3/vendor/yiisoft/yii-web/src'
]
'@yii/web/tests' => [
0 => '/data/wwwroot/yii3/vendor/yiisoft/yii-web/tests'
]
'@yii/console' => [
0 => '/data/wwwroot/yii3/vendor/yiisoft/yii-console/src'
]
'@Psr/Container' => [
0 => '/data/wwwroot/yii3/vendor/psr/container/src'
]
'@yii/di' => [
0 => '/data/wwwroot/yii3/vendor/yiisoft/di/src'
]
'@Psr/Log' => [
0 => '/data/wwwroot/yii3/vendor/psr/log/Psr/Log'
]
'@yii/log' => [
0 => '/data/wwwroot/yii3/vendor/yiisoft/log/src'
]
'@Psr/SimpleCache' => [
0 => '/data/wwwroot/yii3/vendor/psr/simple-cache/src'
]
'@yii/cache' => [
0 => '/data/wwwroot/yii3/vendor/yiisoft/cache/src'
]
'@yii/cache/tests' => [
0 => '/data/wwwroot/yii3/vendor/yiisoft/cache/tests'
]
'@yii/db' => [
0 => '/data/wwwroot/yii3/vendor/yiisoft/db/src'
]
'@yii/db/tests' => [
0 => '/data/wwwroot/yii3/vendor/yiisoft/db/tests'
]
'@yii/activerecord' => [
0 => '/data/wwwroot/yii3/vendor/yiisoft/active-record/src'
]
'@yii/activerecord/tests' => [
0 => '/data/wwwroot/yii3/vendor/yiisoft/active-record/tests'
]
'@yii/jquery' => [
0 => '/data/wwwroot/yii3/vendor/yiisoft/yii-jquery/src'
]
'@yii/captcha' => [
0 => '/data/wwwroot/yii3/vendor/yiisoft/yii-captcha/src'
]
'@yii/bootstrap4' => [
0 => '/data/wwwroot/yii3/vendor/yiisoft/yii-bootstrap4/src'
]
'@Doctrine/Common/Lexer' => [
0 => '/data/wwwroot/yii3/vendor/doctrine/lexer/lib/Doctrine/Common/Lexer'
]
'@Egulias/EmailValidator' => [
0 => '/data/wwwroot/yii3/vendor/egulias/email-validator/EmailValidator'
]
'@yii/swiftmailer' => [
0 => '/data/wwwroot/yii3/vendor/yiisoft/yii-swiftmailer/src'
]
'@Dotenv' => [
0 => '/data/wwwroot/yii3/vendor/vlucas/phpdotenv/src'
]
'@hiqdev/composer/config' => [
0 => '/data/wwwroot/yii3/vendor/hiqdev/composer-config-plugin/src'
]
'@yii/app' => [
0 => '/data/wwwroot/yii3/vendor/yiisoft/yii-base-web/src'
1 => '/data/wwwroot/yii3/vendor/yiisoft/yii-base-cli/src'
]
]
)
'@yii/app' => [
0 => '/data/wwwroot/yii3/vendor/yiisoft/yii-base-web/src'
1 => '/data/wwwroot/yii3/vendor/yiisoft/yii-base-cli/src'
]
modify This behavior is wrong
'@yii/app' => '/data/wwwroot/yii3/vendor/yiisoft/yii-base-cli/src'
composer support! what if the user needs to use multiple directories?
old
yii migrate/up --migration-path=@leonsw/wallet/migrations,@leonsw/user/migrations,@leonsw/post/migrations,@leonsw/tag/migrations
now
yii migrate/up --migration-path=@leonsw/migrations
use $psrAliases->get('@leonsw/migrations')
Can get multiple directories
I think this is the right thing.
Aliases are used to represent file paths or URLs so that you don't have to hard-code absolute paths or URLs in your project. An alias must start with the @ character to be differentiated from normal file paths and URLs. Alias defined without leading @ will be prefixed with @ character.
I suggest you look at the above again.
i18n
$psrAliases->get('@leonsw/messages')
Done.
According to the definition of the alias for the document, the alias should only be used to handle
Paths
andURLs
. The value of thealias
can only be astring
See: https://www.yiiframework.com/doc/guide/2.0/en/concept-aliasesAnd Composer Autoload Psr map can be an array After separation, we will be able to implement more useful features and comply with
Psr
E.g: Supports multiple directories withnamespace
, which can be used for migration and base template combination. Of course there are many See: https://github.com/yiisoft/db/issues/29#issuecomment-440586266I think can add an
PsrAliases.php
file. You can use it like the alias component. The property is read-only, and the content inside is completely generated according to composerThe original alias is configured by
config
.Because aliases are basically only used for paths, it will be more intuitive.
Users can configure custom aliases based on their own needs. I am working on the relevant changes, and if I allow me to perfect it. And submit
PR
. Is there a good suggestion if you name it?