for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace hipanel\modules\finance\models\factories;
use hipanel\modules\finance\models\ModelGroupPrice;
use hipanel\modules\finance\models\Price;
use yii\base\InvalidConfigException;
/**
* Class PriceModelFactory builds objects, that must be children of [[Price]] class
* using short class name. See definitions in $map property.
*
* @author Dmytro Naumenko <[email protected]>
*/
class PriceModelFactory
{
* @var array
protected $map = [
'Price' => Price::class,
'ModelGroupPrice' => ModelGroupPrice::class,
'SinglePrice' => Price::class,
];
* @param string $name
* @return Price
* @throws InvalidConfigException
public function build($name)
if (!isset($this->map[$name])) {
throw new InvalidConfigException('Can not create model for class ' . $name);
}
return new $this->map[$name]();
* @return array
public function getMap(): array
return $this->map;