1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the ONGR package. |
5
|
|
|
* |
6
|
|
|
* (c) NFQ Technologies UAB <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace ONGR\ElasticsearchBundle\Service; |
13
|
|
|
|
14
|
|
|
use ONGR\ElasticsearchBundle\Generator\DocumentGenerator; |
15
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
16
|
|
|
use Symfony\Component\HttpKernel\Bundle\BundleInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Generate Service |
20
|
|
|
*/ |
21
|
|
|
class GenerateService |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var DocumentGenerator |
25
|
|
|
*/ |
26
|
|
|
private $generator; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var Filesystem |
30
|
|
|
*/ |
31
|
|
|
private $filesystem; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Constructor |
35
|
|
|
* |
36
|
|
|
* @param DocumentGenerator $generator |
37
|
|
|
* @param Filesystem $filesystem |
38
|
|
|
*/ |
39
|
|
|
public function __construct(DocumentGenerator $generator, Filesystem $filesystem) |
40
|
|
|
{ |
41
|
|
|
$this->generator = $generator; |
42
|
|
|
$this->filesystem = $filesystem; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Generates document class |
47
|
|
|
* |
48
|
|
|
* @param BundleInterface $bundle |
49
|
|
|
* @param string $document |
50
|
|
|
* @param string $annotation |
51
|
|
|
* @param string $type |
52
|
|
|
* @param array $properties |
53
|
|
|
*/ |
54
|
|
|
public function generate( |
55
|
|
|
BundleInterface $bundle, |
56
|
|
|
$document, |
57
|
|
|
$annotation, |
58
|
|
|
$type, |
59
|
|
|
array $properties |
60
|
|
|
) { |
61
|
|
|
$documentPath = $bundle->getPath() . '/Document/' . str_replace('\\', '/', $document) . '.php'; |
62
|
|
|
$class = [ |
63
|
|
|
'name' => $bundle->getNamespace() . '\\Document\\' . $document, |
64
|
|
|
'annotation' => $annotation, |
65
|
|
|
'type' => $type, |
66
|
|
|
'properties' => $properties, |
67
|
|
|
]; |
68
|
|
|
|
69
|
|
|
$documentCode = $this->generator->generateDocumentClass($class); |
70
|
|
|
|
71
|
|
|
$this->filesystem->mkdir(dirname($documentPath)); |
72
|
|
|
file_put_contents($documentPath, $documentCode); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|