ptheofan/yii2-hosts-component
Composer 安装命令:
composer require ptheofan/yii2-hosts-component
包简介
A Yii2 component to help you manage domains and hosts throughout your app accross multiple environments.
README 文档
README
Easily manage your domains and subdomains across multiple environments
In your config (example /common/main-local.php)
'components' => [ 'host' => [ 'class' => \ptheofan\components\Hosts::class, 'config' => [ 'storage' => [ 'http' => false, // set to false by default 'https' => true, // this is by default set to true 'hostname' => 'storage.example.com', // the domain of interest ], ], ], ],
Then you can access the following
echo Yii::$app->host->storage->url(); // will return https://storage.example.com/ echo Yii::$app->host->storage->url('/avatars'); // will return https://storage.example.com/avatars echo Yii::$app->host->storage->url('/avatars/avatar.png'); // will return https://storage.example.com/avatars/avatar.png
To support autocomplete you have two options
- Extend the Hosts class with your own component and add @property annotations
- Create a mock file and mark the original file as text-only (if your IDE supports it). Then add the @property annotations you want to the class.
Here's a simple example of the first method
// @file /common/components/Hosts.php /** * @property Host $storage */ class Hosts extends \ptheofan\components\Hosts { } // @file /common/config/main-local.php 'components' => [ 'host' => [ 'class' => \common\components\Hosts::class, 'config' => [ 'storage' => [ 'http' => false, // set to false by default 'https' => true, // this is by default set to true 'hostname' => 'storage.example.com', // the domain of interest ], ], ], ], // if you have properly configured the stubs for autocomplete then you should get autocomplete when you write Yii::$app->host-> // (autocomplete here all the Hosts annnotated @properties)
统计信息
- 总下载量: 30
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2020-12-31