ptheofan/yii2-hosts-component 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

  1. Extend the Hosts class with your own component and add @property annotations
  2. 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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2020-12-31

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固