This repository has been archived by the owner on Feb 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Container.php
111 lines (92 loc) · 3.05 KB
/
Container.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
use Shopware\Components\Api\Manager;
use TEiling\Scd16\Resource\ArticleResourceInterface;
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
use TEiling\Scd16\Cache\CacheInterface;
use TEiling\Scd16\Cache\ShopwareCache;
class Shopware_Plugins_Core_Scd16_Container
{
/** @var ArticleResourceInterface */
private $articleResource;
/** @var Zend_Db_Adapter_Abstract */
private $db;
/**
* @var \Symfony\Component\DependencyInjection\ContainerInterface $container
*/
private $container;
/**
* @var Zend_Cache_Core $cache
*/
private $cache;
/**
* Shopware_Plugins_Core_Scd16_Container constructor.
*
* @param ArticleResourceInterface $articleResource
* @param Zend_Db_Adapter_Abstract $db
* @param CacheInterface $cache
*
* @throws \Exception
* @throws \Zend_Cache_Exception
* @throws \Symfony\Component\DependencyInjection\Exception\BadMethodCallException
*/
public function __construct(
ArticleResourceInterface $articleResource = null,
Zend_Db_Adapter_Abstract $db = null,
CacheInterface $cache = null
) {
$this->articleResource = $articleResource ?? Manager::getResource('Article');
$this->db = $db ?? Shopware()->Db();
$this->cache = $cache ?? new ShopwareCache(Shopware()->Cache());
$cacheId = 'Scd16_Core_Container';
if ($this->cache->test($cacheId)) {
eval('?>' . $this->cache->load($cacheId));
$container = new Scd16ServiceContainer();
} else {
$container = $this->createContainer();
$container->compile();
$dumper = new PhpDumper($container);
$dumpParams = [
'class' => 'Scd16ServiceContainer',
];
$this->cache->save($dumper->dump($dumpParams), $cacheId, ['Shopware_Plugin'], 3600);
}
$container->set('article_res', $this->articleResource);
$container->set('db', $this->db);
$this->container = $container;
}
/**
* creates a Container
*
* @param string $dir
*
* @return \Symfony\Component\DependencyInjection\ContainerBuilder
* @throws Exception
*/
public function createContainer($dir = __DIR__)
{
$instance = new \Symfony\Component\DependencyInjection\ContainerBuilder();
$loader = new \Symfony\Component\DependencyInjection\Loader\XmlFileLoader(
$instance,
new \Symfony\Component\Config\FileLocator(realpath($dir))
);
$loader->load('container.xml');
$instance->setParameter(
'config.path.image',
Shopware()->Plugins()->Core()->Scd16()->Path() . '_vImages/'
);
$instance->setParameter(
'config.path.csv',
Shopware()->Plugins()->Core()->Scd16()->Path() . 'tests/fixtures/shopexport.csv'
);
return $instance;
}
/**
* @param $id
*
* @return mixed
*/
public function get($id)
{
return $this->container->get($id);
}
}