1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kaliop\eZWorkflowEngineBundle\Core\Loader; |
4
|
|
|
|
5
|
|
|
use Kaliop\eZMigrationBundle\Core\Loader\Filesystem as BaseLoader; |
6
|
|
|
use Kaliop\eZWorkflowEngineBundle\API\Value\WorkflowDefinition; |
7
|
|
|
use Kaliop\eZMigrationBundle\API\ConfigResolverInterface; |
8
|
|
|
use Symfony\Component\HttpKernel\KernelInterface; |
9
|
|
|
|
10
|
|
|
class Filesystem extends BaseLoader |
11
|
|
|
{ |
12
|
|
|
public function __construct(KernelInterface $kernel, $versionDirectoryParameter = 'Workflows', ConfigResolverInterface $configResolver = null) |
13
|
|
|
{ |
14
|
|
|
$this->versionDirectory = $configResolver ? $configResolver->getParameter($versionDirectoryParameter) : $versionDirectoryParameter; |
15
|
|
|
$this->kernel = $kernel; |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @param array $paths either dir names or file names |
20
|
|
|
* @param bool $returnFilename return either the |
21
|
|
|
* @return WorkflowDefinition[]|string[] migrations definitions. key: name, value: contents of the definition, as string or file path |
22
|
|
|
* @throws \Exception |
23
|
|
|
*/ |
24
|
|
|
protected function getDefinitions(array $paths = array(), $returnFilename = false) |
25
|
|
|
{ |
26
|
|
|
// if no paths defined, we look in all bundles |
27
|
|
|
if (empty($paths)) { |
28
|
|
|
$paths = array(); |
29
|
|
|
/** @var $bundle \Symfony\Component\HttpKernel\Bundle\BundleInterface */ |
30
|
|
|
foreach ($this->kernel->getBundles() as $bundle) |
31
|
|
|
{ |
32
|
|
|
$path = $bundle->getPath() . "/" . $this->versionDirectory; |
33
|
|
|
if (is_dir($path)) { |
34
|
|
|
$paths[] = $path; |
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
$definitions = array(); |
40
|
|
|
foreach ($paths as $path) { |
41
|
|
|
if (is_file($path)) { |
42
|
|
|
$definitions[basename($path)] = $returnFilename ? $path : new WorkflowDefinition( |
43
|
|
|
basename($path), |
44
|
|
|
$path, |
45
|
|
|
file_get_contents($path) |
46
|
|
|
); |
47
|
|
|
} elseif (is_dir($path)) { |
48
|
|
|
foreach (new \DirectoryIterator($path) as $file) { |
49
|
|
|
if ($file->isFile()) { |
50
|
|
|
$definitions[$file->getFilename()] = |
51
|
|
|
$returnFilename ? $file->getRealPath() : new WorkflowDefinition( |
52
|
|
|
$file->getFilename(), |
53
|
|
|
$file->getRealPath(), |
54
|
|
|
file_get_contents($file->getRealPath()) |
55
|
|
|
); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
} else { |
59
|
|
|
throw new \Exception("Path '$path' is neither a file nor directory"); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
ksort($definitions); |
63
|
|
|
|
64
|
|
|
return $definitions; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|