1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37:
38: namespace MOC\Module\Installer;
39: use MOC\Api;
40: use MOC\Core\Changelog\Entry;
41: use MOC\Generic\Device\Module;
42:
43: 44: 45:
46: class Client implements Module {
47: 48: 49: 50: 51: 52: 53:
54: public static function InterfaceChangelog() {
55: return Api::Core()->Changelog()->Create( __CLASS__ )
56: ->Build()->Clearance( '18.02.2013 14:26', 'Dev' )
57: ->Fix()->HotFix( '19.02.2013 16:15', 'Call to a member function on a non-object in GetVersionList()' )
58: ;
59: }
60:
61: 62: 63: 64: 65: 66: 67:
68: public static function InterfaceDepending() {
69: return Api::Core()->Depending();
70: }
71:
72: 73: 74: 75: 76: 77: 78:
79: public static function InterfaceInstance() {
80: return new Client();
81: }
82:
83: public function LoadUpdateProtocol() {
84: return unserialize( $this->LoadTransport( 'AUTO', $this->GetVersionList() ) );
85: }
86: public function LoadBuildProtocol() {
87: var_dump( $this->LoadTransport( 'UPGRADE', $this->GetVersionList() ) );
88: }
89: public function LoadReleaseProtocol() {
90: var_dump( $this->LoadTransport( 'INSTALL', $this->GetVersionList() ) );
91: }
92:
93: private function LoadTransport( $Type, $VersionList ) {
94: return Api::Module()->Network()->Http()->Post()->Request(
95: self::$ServerChannel, array( 'T' => $Type, 'V' => serialize( $VersionList ) )
96: );
97: }
98:
99:
100: private static $ServerTimeout = 15;
101:
102: private static $ServerChannel = 'http://sub.domain.top/server/path';
103: 104: 105: 106: 107:
108: public function SetServerChannel( $Server = 'http://sub.domain.top/server/path' ) {
109: self::$ServerChannel = $Server;
110: return $this;
111: }
112:
113: 114: 115:
116: public function GetVersionList() {
117: $ClassList = $this->GetClassList();
118:
119: $Version = array();
120:
121: foreach( (array)$ClassList as $Class ) {
122: $rClass = new \ReflectionClass( $Class );
123: if( $rClass->hasMethod( 'InterfaceChangelog' ) ) {
124: $Version[(string)$Class] = $Class::InterfaceChangelog();
125: $rClass = new \ReflectionClass( get_class( $Version[(string)$Class] ) );
126: if( $rClass->hasMethod( 'Version' ) ) {
127: $Version[(string)$Class] = $Version[(string)$Class]->Version();
128: } else {
129: trigger_error( 'Missing Version() in '.$Class );
130: }
131: } else {
132: trigger_error( 'Missing InterfaceChangelog() in '.$Class );
133: }
134: }
135: return $Version;
136: }
137:
138: 139: 140:
141: public function GetChangeLog() {
142: $ClassList = $this->GetClassList();
143:
144: $Log = array();
145:
146: foreach( (array)$ClassList as $Class ) {
147: $rClass = new \ReflectionClass( $Class );
148: if( $rClass->hasMethod( 'InterfaceChangelog' ) ) {
149: $Log = array_merge( $Log, $Class::InterfaceChangelog()->Log() );
150: }
151: }
152: return $Log;
153: }
154:
155: 156: 157:
158: public function GetChangeLogByTimeLine() {
159: $Log = $this->GetChangeLog();
160:
161: usort( $Log, function( Entry $A, Entry $B ) {
162: if( $A->Timestamp() > $B->Timestamp() ) {
163: return -1;
164: } else if( $A->Timestamp() < $B->Timestamp() ) {
165: return 1;
166: } else {
167: return 0;
168: }
169: });
170:
171: return $Log;
172: }
173:
174:
175: private static $ClassList = array();
176:
177: private $ClassDirectory = array(
178: 'Adapter',
179: 'Core', 'Extension', 'Module',
180: 'Plugin', 'Widget'
181: );
182: 183: 184:
185: public function GetClassList() {
186: if( empty( self::$ClassList ) ) {
187: $BaseDirectory = realpath( __DIR__.'/../../' );
188: foreach( (array)$this->ClassDirectory as $ClassDirectory ) {
189:
190: $FileList = Api::Module()
191: ->Drive()->Directory()->Open(
192: realpath( $BaseDirectory.DIRECTORY_SEPARATOR.$ClassDirectory )
193: )->FileList( true );
194:
195: array_walk( $FileList, function( &$File, $Index, $BaseDirectory ) {
196:
197: if(
198: false !== strpos( $File->GetPath(), '#Trash' )
199: || false !== strpos( $File->GetPath(), '3rdParty' )
200: || $File->GetExtension() !== 'php'
201: ) {
202: $File = false;
203: } else {
204: $File = '\\MOC'.str_replace( $BaseDirectory, '', $File->GetPath() ).'\\'.$File->GetName();
205: }
206: }, $BaseDirectory );
207:
208: $FileList = array_filter( $FileList );
209: self::$ClassList = array_merge( self::$ClassList, $FileList );
210: }
211:
212: sort( self::$ClassList );
213: }
214: return self::$ClassList;
215: }
216: }
217: