PHPackages                             ptheofan/yii2-hosts-component - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. ptheofan/yii2-hosts-component

ActiveYii2-extension

ptheofan/yii2-hosts-component
=============================

A Yii2 component to help you manage domains and hosts throughout your app accross multiple environments.

v1.0.1(5y ago)030BSD-3-ClausePHPPHP &gt;=7.4.0

Since Dec 31Pushed 5y ago1 watchersCompare

[ Source](https://github.com/ptheofan/yii2-hosts-component)[ Packagist](https://packagist.org/packages/ptheofan/yii2-hosts-component)[ RSS](/packages/ptheofan-yii2-hosts-component/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (1)Versions (3)Used By (0)

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)
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

1955d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/791932127b0c9e049f88475ebe52eacf5e79d20bc1de1b819a644f285f61d1f2?d=identicon)[ptheofan](/maintainers/ptheofan)

---

Top Contributors

[![ptheofan](https://avatars.githubusercontent.com/u/880939?v=4)](https://github.com/ptheofan "ptheofan (2 commits)")

### Embed Badge

![Health badge](/badges/ptheofan-yii2-hosts-component/health.svg)

```
[![Health](https://phpackages.com/badges/ptheofan-yii2-hosts-component/health.svg)](https://phpackages.com/packages/ptheofan-yii2-hosts-component)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M2.6k](/packages/craftcms-cms)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
