|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* a compilerpass that computes a single hash of the current generated bundles |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace Graviton\GeneratorBundle\DependencyInjection\Compiler; |
|
7
|
|
|
|
|
8
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
|
9
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
10
|
|
|
use Symfony\Component\Finder\Finder; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @author List of contributors <https://github.com/libgraviton/graviton/graphs/contributors> |
|
14
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
|
15
|
|
|
* @link http://swisscom.ch |
|
16
|
|
|
*/ |
|
17
|
|
|
class GeneratorHashCompilerPass implements CompilerPassInterface |
|
18
|
|
|
{ |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* generate the hashes |
|
22
|
|
|
* |
|
23
|
|
|
* @param ContainerBuilder $container container builder |
|
24
|
|
|
* |
|
25
|
|
|
* @return void |
|
26
|
|
|
*/ |
|
27
|
2 |
|
public function process(ContainerBuilder $container) |
|
28
|
|
|
{ |
|
29
|
|
|
// first type of hash: the genhash'es of all GravitonDyn bundles |
|
30
|
2 |
|
$dir = $container->getParameter('graviton.generator.dynamicbundle.dir'); |
|
31
|
|
|
|
|
32
|
2 |
|
$dynHash = ''; |
|
33
|
2 |
|
if (is_dir($dir)) { |
|
34
|
2 |
|
$finder = (new Finder()) |
|
35
|
2 |
|
->in($dir) |
|
36
|
2 |
|
->files() |
|
37
|
2 |
|
->sortByName() |
|
38
|
2 |
|
->name('genhash'); |
|
39
|
|
|
|
|
40
|
2 |
|
foreach ($finder as $file) { |
|
41
|
2 |
|
$dynHash .= DIRECTORY_SEPARATOR . $file->getContents(); |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
// 2nd hash: configuration of our own graviton things (static stuff) |
|
46
|
2 |
|
$staticHash = ''; |
|
47
|
2 |
|
if (is_dir(__DIR__.'/../../../')) { |
|
48
|
2 |
|
$finder = (new Finder()) |
|
49
|
2 |
|
->in(__DIR__ . '/../../../') |
|
50
|
2 |
|
->path('/serializer/') |
|
51
|
2 |
|
->path('/doctrine/') |
|
52
|
2 |
|
->path('/schema/') |
|
53
|
2 |
|
->notPath('/Tests/') |
|
54
|
2 |
|
->files() |
|
55
|
2 |
|
->sortByName() |
|
56
|
2 |
|
->name('*.xml') |
|
57
|
2 |
|
->name('*.json'); |
|
58
|
|
|
|
|
59
|
2 |
|
foreach ($finder as $file) { |
|
60
|
2 |
|
$staticHash .= DIRECTORY_SEPARATOR . sha1_file($file->getPathname()); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
2 |
|
$dynHash = sha1($dynHash); |
|
65
|
2 |
|
$staticHash = sha1($staticHash); |
|
66
|
2 |
|
$allHash = sha1($dynHash . DIRECTORY_SEPARATOR . $staticHash); |
|
67
|
|
|
|
|
68
|
2 |
|
$container->setParameter('graviton.generator.hash.dyn', $dynHash); |
|
69
|
2 |
|
$container->setParameter('graviton.generator.hash.static', $staticHash); |
|
70
|
2 |
|
$container->setParameter('graviton.generator.hash.all', $allHash); |
|
71
|
2 |
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|