mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-30 05:00:51 +08:00
45 lines
1.1 KiB
PHP
45 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace WooCommerce\PayPalCommerce\Vendor\Dhii\Container;
|
|
|
|
use WooCommerce\PayPalCommerce\Vendor\Dhii\Collection\WritableMapFactoryInterface;
|
|
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
class DataStructureBasedFactory implements DataStructureBasedFactoryInterface
|
|
{
|
|
/**
|
|
* @var WritableMapFactoryInterface
|
|
*/
|
|
protected $containerFactory;
|
|
public function __construct(WritableMapFactoryInterface $containerFactory)
|
|
{
|
|
$this->containerFactory = $containerFactory;
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function createContainerFromArray(array $structure): ContainerInterface
|
|
{
|
|
$map = [];
|
|
foreach ($structure as $key => $value) {
|
|
if (is_object($value)) {
|
|
$value = get_object_vars($value);
|
|
}
|
|
|
|
if (is_array($value)) {
|
|
$value = $this->createContainerFromArray($value);
|
|
}
|
|
|
|
$map[$key] = $value;
|
|
}
|
|
|
|
$container = $this->containerFactory->createContainerFromArray($map);
|
|
return $container;
|
|
}
|
|
}
|