yiisoft / yii-bootstrap5

Yii Framework Bootstrap 5 support
https://www.yiiframework.com/
BSD 3-Clause "New" or "Revised" License
63 stars 19 forks source link

Create virtual package yii-bootstrap #19

Closed Mister-42 closed 3 years ago

Mister-42 commented 4 years ago

Hello devs,

Would you please consider creating a virtual package yii-bootstrap, that both yii-bootstrap4 and yii-bootstrap5 'provide' to? That way we can require yii-bootstrap and leave it up to the individual devs to choose a version.

samdark commented 4 years ago

What's the benefit? How would the widget or whatever package use the bootstrap then? Would that mean that we should maintain 100% compatibility of APIs of version 4 and version 5?

Mister-42 commented 4 years ago

A dev can determine what version is installed apply accordingly. The API can change however you want it, it is up to the devs to implement it corrently for all versions if they choose to do so.

if (class_exists('Yiisoft\Yii\Bootstrap4\Accordion')) {
    // Show version v4
} elseif (class_exists('Yiisoft\Yii\Bootstrap5\Accordion')) {
    // Show version v5
}

or if the API is still the same this can be used

$version = class_exists('Yiisoft\Yii\Bootstrap4\Nav') ? 'Bootstrap4' : 'Bootstrap5';
$breadcrumbs = '\Yiisoft\Yii\\' . $version . '\Breadcrumbs';
echo $breadcrumbs::widget()
    ->encodeLabels(false)
    ->homeLink(['label' => _('Home'), 'url' => $url->generate('site/index'), 'class' => 'text-decoration-none'])
    ->links($this->params['breadcrumbs'] ?? []);

Ugly examples, but I think you get the drift.

The only alternative I have as a dev now is to create 2 different packages for each version.

samdark commented 3 years ago

Sounds alright. Let's do it in both bootstrap4 and bootstrap5.