1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the php-phantomjs. |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace JonnyW\PhantomJs\Procedure; |
11
|
|
|
|
12
|
|
|
use Symfony\Component\Config\FileLocator; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* PHP PhantomJs |
16
|
|
|
* |
17
|
|
|
* @author Jon Wenmoth <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
class ProcedureLoaderFactory implements ProcedureLoaderFactoryInterface |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Procedure factory. |
23
|
|
|
* |
24
|
|
|
* @var \JonnyW\PhantomJs\Procedure\ProcedureFactoryInterface |
25
|
|
|
* @access protected |
26
|
|
|
*/ |
27
|
|
|
protected $procedureFactory; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Internal constructor. |
31
|
|
|
* |
32
|
|
|
* @access public |
33
|
|
|
* @param \JonnyW\PhantomJs\Procedure\ProcedureFactoryInterface $procedureFactory |
34
|
|
|
*/ |
35
|
3 |
|
public function __construct(ProcedureFactoryInterface $procedureFactory) |
36
|
|
|
{ |
37
|
3 |
|
$this->procedureFactory = $procedureFactory; |
38
|
3 |
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Create procedure loader instance. |
42
|
|
|
* |
43
|
|
|
* @access public |
44
|
|
|
* @param string $directory |
45
|
|
|
* @return \JonnyW\PhantomJs\Procedure\ProcedureLoader |
46
|
|
|
*/ |
47
|
5 |
|
public function createProcedureLoader($directory) |
48
|
|
|
{ |
49
|
5 |
|
$procedureFactory = $this->procedureFactory; |
50
|
5 |
|
$fileLocator = $this->createFileLocator($directory); |
51
|
|
|
|
52
|
4 |
|
$procedureLoader = new ProcedureLoader( |
53
|
4 |
|
$procedureFactory, |
54
|
|
|
$fileLocator |
55
|
4 |
|
); |
56
|
|
|
|
57
|
4 |
|
return $procedureLoader; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Create file locator instance. |
62
|
|
|
* |
63
|
|
|
* @access protected |
64
|
|
|
* @param string $directory |
65
|
|
|
* @return \Symfony\Component\Config\FileLocator |
66
|
|
|
* @throws \InvalidArgumentException |
67
|
|
|
*/ |
68
|
5 |
|
protected function createFileLocator($directory) |
69
|
|
|
{ |
70
|
5 |
|
if (!is_dir($directory) || !is_readable($directory)) { |
71
|
1 |
|
throw new \InvalidArgumentException(sprintf('Could not create procedure loader as directory does not exist or is not readable: "%s"', $directory)); |
72
|
|
|
} |
73
|
|
|
|
74
|
4 |
|
return new FileLocator($directory); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|