Exception 'yii\base\InvalidConfigException' with message 'Missing required parameter "location" when instantiating "shop\manage\payment\cloudPayments\CloudPaymentsPaymentCreator".'
Параметр передаётся в метод
get()
\Yii::$container->get($class, [], $params);
Распечатка
$params
:
array(1) {
["location"]=>
string(2) "EU"
}
Конструктор класса
CloudPaymentsPaymentCreator
:
class CloudPaymentsPaymentCreator implements PaymentCreator
{
const LOCATION_USA = "USA";
const LOCATION_EU = "EU";
private $location;
public function __construct($location)
{
$this->location = $location;
}
Полный код функции с использованием контейнера
public static function create($method)
{
foreach (self::$map as $receiptMethod => $classParams) {
if ($method === $receiptMethod) {
/**
* @var $class
* @var $params
*/
extract(self::prepareParams($classParams));
echo "\n\n";
var_dump($params);
echo "\n";
return \Yii::$container->get($class, [], $params);
}
}
throw new \DomainException("Unsupported payment system");
}
protected static function prepareParams($classParams)
{
return is_array($classParams) ? $classParams : ['class' => $classParams, 'params' => []];
}