-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathOkFileHandlerFactory.php
More file actions
111 lines (96 loc) · 3.65 KB
/
OkFileHandlerFactory.php
File metadata and controls
111 lines (96 loc) · 3.65 KB
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
/**
* TechDivision\Import\Handlers\OkFileHandlerFactory
*
* PHP version 7
*
* @author Tim Wagner <t.wagner@techdivision.com>
* @copyright 2020 TechDivision GmbH <info@techdivision.com>
* @license https://opensource.org/licenses/MIT
* @link https://github.com/techdivision/import
* @link http://www.techdivision.com
*/
namespace TechDivision\Import\Handlers;
use TechDivision\Import\Loaders\LoaderFactoryInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use TechDivision\Import\Adapter\FilesystemAdapterFactoryInterface;
use TechDivision\Import\Configuration\SubjectConfigurationInterface;
/**
* A .OK file handler factory implementation.
*
* @author Tim Wagner <t.wagner@techdivision.com>
* @copyright 2020 TechDivision GmbH <info@techdivision.com>
* @license https://opensource.org/licenses/MIT
* @link https://github.com/techdivision/import
* @link http://www.techdivision.com
*/
class OkFileHandlerFactory implements HandlerFactoryInterface
{
/**
* The DI container instance.
*
* @var \Symfony\Component\DependencyInjection\ContainerInterface
*/
private $container;
/**
* The loader factory instance used to create the loader for the proposed .OK filenames.
*
* @var \TechDivision\Import\Loaders\LoaderFactoryInterface
*/
private $loaderFactory;
/**
* Initialize the factory with the DI container instance.
*
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container The DI container instance
* @param \TechDivision\Import\Loaders\LoaderFactoryInterface $loaderFactory The loader factory instance used to create the loader for the proposed .OK filenames
*/
public function __construct(
ContainerInterface $container,
LoaderFactoryInterface $loaderFactory
) {
$this->container = $container;
$this->loaderFactory = $loaderFactory;
}
/**
* Return's the container instance.
*
* @return \Symfony\Component\DependencyInjection\ContainerInterface The container instance
*/
protected function getContainer() : ContainerInterface
{
return $this->container;
}
/**
* Return's the loader factory instance.
*
* @return \TechDivision\Import\Loaders\LoaderFactoryInterface The loader factory instance
*/
protected function getLoaderFactory() : LoaderFactoryInterface
{
return $this->loaderFactory;
}
/**
* Create's and return's a new handler instance.
*
* @param \TechDivision\Import\Configuration\SubjectConfigurationInterface|null $subject The subject configuration instance
*
* @return \TechDivision\Import\Handlers\HandlerInterface|null The new handler instance
*/
public function createHandler(?SubjectConfigurationInterface $subject = null) : HandlerInterface
{
// load the proposed .OK file loader
$proposedOkFileLoader = $this->getLoaderFactory()->createLoader($subject);
// load the filesystem adapter instance
$filesystemAdapter = $this->getContainer()->get($subject->getFilesystemAdapter()->getId());
// query whether or not we've a factory instance
if ($filesystemAdapter instanceof FilesystemAdapterFactoryInterface) {
$filesystemAdapter = $filesystemAdapter->createFilesystemAdapter($subject);
}
// create a new .OK file handler instance
$handler = new OkFileHandler();
$handler->setLoader($proposedOkFileLoader);
$handler->setFilesystemAdapter($filesystemAdapter);
// return the new .OK file handler instance
return $handler;
}
}