Everything base on Interface and Trait


(mr_a_ton) #1

with Interface and Trait, we can seamless integrated 3th party library to Yii

for example
we have “3thparty/DiviceDetect” library, and integrated to Yii

yii/base/ComponentInterface , yii/base/ComponentTrait

we can create new yii component like this :

class 3thparty/yii/DiviceDetect 
   extend 3thparty/DiviceDetect 
   implement yii/base/ComponentInterface
{
   use yii/base/ComponentTrait;

}

next we can check like this

if ($cls instanceof yii/base/ComponentInterface) {
    echo "yes";
}

(Alexander Makarov) #2

We’re getting rid of components in Yii 3. Basically any class would be OK to register as a service (component).