1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sylius package. |
5
|
|
|
* |
6
|
|
|
* (c) Paweł Jędrzejewski |
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 Sylius\Bundle\ThemeBundle\Asset\Installer; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\HttpKernel\Bundle\BundleInterface; |
15
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @author Kamil Kokot <[email protected]> |
19
|
|
|
*/ |
20
|
|
|
class OutputAwareAssetsInstaller extends AssetsInstaller implements OutputAwareInterface |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var OutputInterface |
24
|
|
|
*/ |
25
|
|
|
protected $output; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* {@inheritdoc} |
29
|
|
|
*/ |
30
|
|
|
public function setOutput(OutputInterface $output) |
31
|
|
|
{ |
32
|
|
|
$this->output = $output; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* {@inheritdoc} |
37
|
|
|
*/ |
38
|
|
|
public function installAssets($targetDir, $symlinkMask) |
39
|
|
|
{ |
40
|
|
|
if ($this->hasOutput()) { |
41
|
|
|
$this->output->writeln($this->provideExpectationComment($symlinkMask)); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
return parent::installAssets($targetDir, $symlinkMask); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* {@inheritdoc} |
49
|
|
|
*/ |
50
|
|
|
public function installBundleAssets(BundleInterface $bundle, $targetDir, $symlinkMask) |
51
|
|
|
{ |
52
|
|
|
$sources = $this->findAssetsPaths($bundle); |
53
|
|
|
|
54
|
|
|
if (empty($sources)) { |
55
|
|
|
return $symlinkMask; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
if ($this->hasOutput()) { |
59
|
|
|
$this->output->writeln(sprintf('Installing assets for <comment>%s</comment>', $bundle->getNamespace(), $targetDir)); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$effectiveSymlinkMask = parent::installBundleAssets($bundle, $targetDir, $symlinkMask); |
63
|
|
|
|
64
|
|
|
if ($this->hasOutput()) { |
65
|
|
|
$this->output->writeln($this->provideResultComment($symlinkMask, $effectiveSymlinkMask)); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
return $effectiveSymlinkMask; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return bool |
73
|
|
|
*/ |
74
|
|
|
private function hasOutput() |
75
|
|
|
{ |
76
|
|
|
return null !== $this->output; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param int $symlinkMask |
81
|
|
|
* @param int $effectiveSymlinkMask |
82
|
|
|
* |
83
|
|
|
* @return string |
84
|
|
|
*/ |
85
|
|
|
private function provideResultComment($symlinkMask, $effectiveSymlinkMask) |
86
|
|
|
{ |
87
|
|
|
if ($effectiveSymlinkMask === $symlinkMask) { |
88
|
|
|
switch ($symlinkMask) { |
89
|
|
|
case AssetsInstallerInterface::HARD_COPY: |
90
|
|
|
return 'The assets were copied.'; |
91
|
|
|
case AssetsInstallerInterface::SYMLINK: |
92
|
|
|
return 'The assets were installed using symbolic links.'; |
93
|
|
|
case AssetsInstallerInterface::RELATIVE_SYMLINK: |
94
|
|
|
return 'The assets were installed using relative symbolic links.'; |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
switch ($symlinkMask + $effectiveSymlinkMask) { |
99
|
|
|
case AssetsInstallerInterface::SYMLINK: |
100
|
|
|
case AssetsInstallerInterface::RELATIVE_SYMLINK: |
101
|
|
|
return 'It looks like your system doesn\'t support symbolic links, so the assets were copied.'; |
102
|
|
|
case AssetsInstallerInterface::RELATIVE_SYMLINK + AssetsInstallerInterface::SYMLINK: |
103
|
|
|
return 'It looks like your system doesn\'t support relative symbolic links, so the assets were installed by using absolute symbolic links.'; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
return 'Something gone bad, can\'t provide the result of assets installing!'; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @param int $symlinkMask |
111
|
|
|
* |
112
|
|
|
* @return string |
113
|
|
|
*/ |
114
|
|
|
private function provideExpectationComment($symlinkMask) |
115
|
|
|
{ |
116
|
|
|
if (AssetsInstallerInterface::HARD_COPY === $symlinkMask) { |
117
|
|
|
return 'Installing assets as <comment>hard copies</comment>.'; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
return 'Trying to install assets as <comment>symbolic links</comment>.'; |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|