Joywork/import/document/target/TargetFactory.php
2026-05-22 21:21:54 +03:00

32 lines
836 B
PHP

<?php
class TargetFactory
{
/**
* @param $id
* @param $type
* @return DocTarget
* @throws TargetNotFoundException
*/
public function getTarget($id, $type)
{
switch ($type) {
case DocTarget::TYPE_APARTMENT:
return Apartment::findOne($id);
case DocTarget::TYPE_BLOCK:
return Block::findOne($id);
case DocTarget::TYPE_BLOCK_PROGRESS:
if ($model = Block::findOne($id)) {
return new BlockProgressImageFacade($model);
}
case DocTarget::TYPE_BLOCK_PLUS:
if ($model = Block::findOne($id)) {
return new BlockPlusFacade($model);
}
break;
}
throw new TargetNotFoundException;
}
}