|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace MaglMarkdown\Service; |
|
4
|
|
|
|
|
5
|
|
|
use Interop\Container\ContainerInterface; |
|
6
|
|
|
use Interop\Container\Exception\ContainerException; |
|
7
|
|
|
use Zend\ServiceManager\Exception\ServiceNotCreatedException; |
|
8
|
|
|
use Zend\ServiceManager\Exception\ServiceNotFoundException; |
|
9
|
|
|
use Zend\ServiceManager\FactoryInterface; |
|
10
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class MarkdownFactory |
|
14
|
|
|
* |
|
15
|
|
|
* @package MaglMarkdown\Service |
|
16
|
|
|
*/ |
|
17
|
|
|
class MarkdownFactory implements FactoryInterface |
|
18
|
|
|
{ |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Create service |
|
22
|
|
|
* |
|
23
|
|
|
* @param ServiceLocatorInterface $serviceLocator |
|
24
|
|
|
* @return Markdown |
|
25
|
|
|
*/ |
|
26
|
1 |
|
public function createService(ServiceLocatorInterface $serviceLocator) |
|
27
|
|
|
{ |
|
28
|
1 |
|
return $this->create($serviceLocator); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Create an object |
|
33
|
|
|
* |
|
34
|
|
|
* @param ContainerInterface $container |
|
35
|
|
|
* @param string $requestedName |
|
36
|
|
|
* @param null|array $options |
|
37
|
|
|
* @return Markdown |
|
38
|
|
|
* @throws \Interop\Container\Exception\NotFoundException |
|
39
|
|
|
* @throws ServiceNotFoundException if unable to resolve the service. |
|
40
|
|
|
* @throws ServiceNotCreatedException if an exception is raised when |
|
41
|
|
|
* creating a service. |
|
42
|
|
|
* @throws ContainerException if any other error occurs |
|
43
|
|
|
*/ |
|
44
|
|
|
public function __invoke(ContainerInterface $container, $requestedName, array $options = null) |
|
45
|
|
|
{ |
|
46
|
|
|
return $this->create($container); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @param ServiceLocatorInterface|ContainerInterface $container |
|
51
|
|
|
* @return Markdown |
|
52
|
|
|
*/ |
|
53
|
1 |
|
protected function create($container) |
|
54
|
|
|
{ |
|
55
|
1 |
|
if (!$container instanceof ServiceLocatorInterface && !$container instanceof ContainerInterface) { |
|
56
|
|
|
throw new \InvalidArgumentException('Invalid container to create service'); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
1 |
|
$em = null; |
|
60
|
1 |
|
$markdownAdapter = $container->get('MaglMarkdown\MarkdownAdapter'); |
|
61
|
|
|
|
|
62
|
|
|
// get / inject eventmanager only if cache is enabled |
|
63
|
1 |
|
$config = $container->get('config'); |
|
64
|
1 |
|
$cacheEnabled = $config['magl_markdown']['cache_enabled']; |
|
65
|
1 |
|
if ($cacheEnabled) { |
|
66
|
|
|
$em = $container->get('application')->getEventManager(); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
1 |
|
return new Markdown($markdownAdapter, $em); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|