1
|
|
|
<?php |
2
|
|
|
/** @formatter:off |
3
|
|
|
* ****************************************************************** |
4
|
|
|
* Created by Marko Kungla on Jun 26, 2016 - 3:59:35 PM |
5
|
|
|
* Contact [email protected] |
6
|
|
|
* @copyright 2016 Marko Kungla - https://github.com/mkungla |
7
|
|
|
* @license The MIT License (MIT) |
8
|
|
|
* |
9
|
|
|
* @category AframeVR |
10
|
|
|
* @package aframe-php |
11
|
|
|
* |
12
|
|
|
* Lang PHP (php version >= 7) |
13
|
|
|
* Encoding UTF-8 |
14
|
|
|
* File AframeInstaller.php |
15
|
|
|
* Code format PSR-2 and 12 |
16
|
|
|
* @link https://github.com/mkungla/aframe-php |
17
|
|
|
^ @issues https://github.com/mkungla/aframe-php/issues |
18
|
|
|
* ******************************************************************** |
19
|
|
|
* Contributors: |
20
|
|
|
* @author Marko Kungla <[email protected]> |
21
|
|
|
* ******************************************************************** |
22
|
|
|
* Comments: |
23
|
|
|
* @formatter:on */ |
24
|
|
|
namespace AframeVR\Composer\Installer; |
25
|
|
|
|
26
|
|
|
use Composer\Composer; |
27
|
|
|
use Composer\IO\IOInterface; |
28
|
|
|
use Composer\Plugin\PluginInterface; |
29
|
|
|
class AframeInstallerPlugin implements PluginInterface |
30
|
|
|
{ |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Apply plugin modifications to Composer |
34
|
|
|
* |
35
|
|
|
* @param Composer $composer |
36
|
|
|
* @param IOInterface $io |
37
|
|
|
*/ |
38
|
|
|
public function activate(Composer $composer, IOInterface $io) |
39
|
|
|
{ |
40
|
|
|
$aframe_installer = new AframeComponentInstaller($io, $composer); |
41
|
|
|
$composer->getInstallationManager()->addInstaller($aframe_installer); |
42
|
|
|
$info_msg = sprintf('A-Frame installer plugin is added as custom installer! composer-plugin-api v: %s', self::PLUGIN_API_VERSION); |
43
|
|
|
$io->write($info_msg, "comment"); |
44
|
|
|
|
45
|
|
|
/* Update A-Frame core */ |
46
|
|
|
if ($this->requiresAframeCoreUpdate($aframe_installer, $io)) |
47
|
|
|
$this->updateAframeCore($aframe_installer,$io); |
48
|
|
|
|
49
|
|
|
$aframe_installer->updateConfig(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Update A-Frame core |
54
|
|
|
* |
55
|
|
|
* Aframe core is always installed as dependency |
56
|
|
|
* so therefore it is installed/updated before |
57
|
|
|
* this pulgin is loaded or updated. |
58
|
|
|
* |
59
|
|
|
* @param AframeComponentInstaller $aframe_installer |
60
|
|
|
* @return void |
61
|
|
|
*/ |
62
|
|
|
private function updateAframeCore(AframeComponentInstaller $aframe_installer,$io) |
63
|
|
|
{ |
64
|
|
|
$source = $aframe_installer->getAframeCoreSrcDir(); |
65
|
|
|
$dest = $aframe_installer->getPublicAframeCoreDir(); |
66
|
|
|
|
67
|
|
|
$aframe_installer->copy($source, $dest); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Is update of Aframe is required |
72
|
|
|
* |
73
|
|
|
* @param AframeComponentInstaller $aframe_installer |
74
|
|
|
* @return bool |
75
|
|
|
*/ |
76
|
|
|
protected function requiresAframeCoreUpdate(AframeComponentInstaller $aframe_installer, IOInterface $io) |
77
|
|
|
{ |
78
|
|
|
$public_path = $aframe_installer->getPublicRoot(); |
|
|
|
|
79
|
|
|
$aframe_core_dir = $aframe_installer->getPublicAframeCoreDir(); |
80
|
|
|
|
81
|
|
|
$aframe_core_file = $aframe_core_dir . DIRECTORY_SEPARATOR . 'aframe.js'; |
82
|
|
|
|
83
|
|
|
$aframe_src_dir = $aframe_installer->getAframeCoreSrcDir(); |
84
|
|
|
|
85
|
|
|
return (! is_dir($aframe_core_dir) || ! file_exists($aframe_core_file) || ! is_dir($aframe_src_dir)) ? true : filemtime($aframe_src_dir) > filemtime($aframe_core_dir); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
} |
89
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.