/** * Returns entity type for object or class. * * @param object|string $entity * @param bool $asString * @return string */ public function getEntityType($entity, $asString = true) { $entityClass = is_object($entity) ? get_class($entity) : $entity; foreach ($this->_entityTypes as $type) { if ($type->getClass() === $entityClass) { $entityType = $type; break; } } if (!isset($entityType)) { $entityType = new EntityType($entityClass, $entityClass); } return $asString ? $entityType->getType() : $entityType; }
/** * Registers page type. * * @param EntityType $type */ public function registerPageType($type) { $baseClass = Page::className(); if ($type->getClass() !== $baseClass && !is_subclass_of($type->getClass(), $baseClass)) { throw new InvalidParamException("Class '{$type->getClass()}' must extend '{$baseClass}'"); } $type->setGroup('page'); Yii::$app->get('typesRegister')->registerEntityType($type); }