1
+ <?php
2
+ /**
3
+ * Composer plugin for config assembling
4
+ *
5
+ * @link https://github.com/hiqdev/composer-config-plugin
6
+ * @package composer-config-plugin
7
+ * @license BSD-3-Clause
8
+ * @copyright Copyright (c) 2016-2017, HiQDev (http://hiqdev.com/)
9
+ */
10
+
11
+ namespace skeeks \cms \marketplace \composer ;
12
+
13
+ use Composer \Composer ;
14
+ use Composer \EventDispatcher \EventSubscriberInterface ;
15
+ use Composer \IO \IOInterface ;
16
+ use Composer \Package \CompletePackageInterface ;
17
+ use Composer \Package \PackageInterface ;
18
+ use Composer \Package \RootPackageInterface ;
19
+ use Composer \Plugin \PluginInterface ;
20
+ use Composer \Script \Event ;
21
+ use Composer \Script \ScriptEvents ;
22
+ use Composer \Util \Filesystem ;
23
+
24
+ /**
25
+ * Class UpdatePlugin
26
+ * @package skeeks\cms\marketplace\composer
27
+ */
28
+ class UpdatePlugin implements PluginInterface, EventSubscriberInterface
29
+ {
30
+ /**
31
+ * @var string absolute path to the package base directory
32
+ */
33
+ protected $ baseDir ;
34
+ /**
35
+ * @var string absolute path to vendor directory
36
+ */
37
+ protected $ vendorDir ;
38
+ /**
39
+ * @var Filesystem utility
40
+ */
41
+ protected $ filesystem ;
42
+
43
+ /**
44
+ * @var Composer instance
45
+ */
46
+ protected $ composer ;
47
+ /**
48
+ * @var IOInterface
49
+ */
50
+ public $ io ;
51
+
52
+ /**
53
+ * Initializes the plugin object with the passed $composer and $io.
54
+ * @param Composer $composer
55
+ * @param IOInterface $io
56
+ */
57
+ public function activate (Composer $ composer , IOInterface $ io )
58
+ {
59
+ $ this ->composer = $ composer ;
60
+ $ this ->io = $ io ;
61
+ }
62
+
63
+ /**
64
+ * Returns list of events the plugin is subscribed to.
65
+ * @return array list of events
66
+ */
67
+ public static function getSubscribedEvents ()
68
+ {
69
+ return [
70
+ ScriptEvents::POST_AUTOLOAD_DUMP => [
71
+ ['onPostAutoloadDump ' , 0 ],
72
+ ],
73
+ ];
74
+ }
75
+
76
+ /**
77
+ * This is the main function.
78
+ * @param Event $event
79
+ */
80
+ public function onPostAutoloadDump (Event $ event )
81
+ {
82
+ $ this ->io ->writeError ('<info>After all update</info> ' );
83
+ $ this ->initAutoload ();
84
+ }
85
+
86
+ protected function initAutoload ()
87
+ {
88
+ $ dir = dirname (dirname (dirname (__DIR__ )));
89
+ require_once "$ dir/autoload.php " ;
90
+ }
91
+
92
+
93
+ /**
94
+ * Get absolute path to package base dir.
95
+ * @return string
96
+ */
97
+ public function getBaseDir ()
98
+ {
99
+ if (null === $ this ->baseDir ) {
100
+ $ this ->baseDir = dirname ($ this ->getVendorDir ());
101
+ }
102
+ return $ this ->baseDir ;
103
+ }
104
+
105
+ /**
106
+ * Get absolute path to composer vendor dir.
107
+ * @return string
108
+ */
109
+ public function getVendorDir ()
110
+ {
111
+ if (null === $ this ->vendorDir ) {
112
+ $ dir = $ this ->composer ->getConfig ()->get ('vendor-dir ' );
113
+ $ this ->vendorDir = $ this ->getFilesystem ()->normalizePath ($ dir );
114
+ }
115
+ return $ this ->vendorDir ;
116
+ }
117
+
118
+ /**
119
+ * Getter for filesystem utility.
120
+ * @return Filesystem
121
+ */
122
+ public function getFilesystem ()
123
+ {
124
+ if (null === $ this ->filesystem ) {
125
+ $ this ->filesystem = new Filesystem ();
126
+ }
127
+ return $ this ->filesystem ;
128
+ }
129
+ }
0 commit comments