Switch between bootstrap RTL and LTR packages dynamically

No idea if there’s a more idiomatic solution, but here is one way to do it, using ArrayAccess interface. But really, a package definition should be a class, not an associative array… (hopefully fixed in later versions of Yii?).

Main reason why this hack is needed is because multiple packages rely on “bootstrap”, but since our app supports many languages - Arabic and Hebrew amongst the RTL ones - “bootstrap” must be both the RTL and LTR version.

    'bootstrap' => new class() implements ArrayAccess {
        private $value = [
            'devBaseUrl' => 'assets/bootstrap_5/',
            'basePath' => 'bootstrap',
            'css' => [
                'build/css/bootstrap_5.min.css',
            ],
            'js' => [
                'build/js/bootstrap_5.min.js',
            ]
        ];
        public function offsetExists($offset) {
            return isset($this->value[$offset]);
        }
        public function offsetGet($offset) {
            $this->setRtl();
            return $this->value[$offset];
        }
        public function offsetSet($offset, $value) {
            $this->value[$offset] = $value;
        }
        public function offsetUnset($offset) {
            unset($this->value[$offset]);
        }
        private function setRtl() {
            $dir = (getLanguageRTL(App()->getLanguage())) ? 'rtl' : 'ltr';
            if ($dir == "rtl") {
                $this->value['css'] = [
                    'build/css/bootstrap_5-rtl.min.css',
                ];
            }
        }
    },