Overview

Namespaces

  • MOC
    • Adapter
    • Core
      • Changelog
      • Depending
      • Drive
        • Directory
        • File
      • Error
        • Register
        • Type
      • Journal
      • Proxy
      • Template
      • Xml
    • Extension
      • Excel
      • Flot
      • Mail
      • Pdf
      • Word
      • Xml
      • YUICompressor
      • Zip
    • Generic
      • Common
      • Device
        • Extension
        • Widget
    • Module
      • Database
        • Driver
      • Drive
      • Image
        • Font
      • Installer
      • Network
        • Ftp
          • Directory
          • File
          • Transport
        • Http
        • ParcelTracker
          • Carrier
      • Office
        • Chart
          • Axis
        • Document
          • Excel
            • Cell
              • Format
              • Style
                • Border
                  • Bottom
                  • Left
                  • Right
                  • Top
                • Font
            • Close
            • Page
            • Worksheet
          • Pdf
            • Close
            • Font
            • Page
              • Margin
              • Position
            • Text
          • Xml
            • Close
        • Image
        • Mail
          • Address
          • Content
      • Packer
        • Yui
        • Zip
      • Template
    • Plugin
      • Gateway
      • Repository
      • Shared
  • PHP

Classes

  • Client
  • Server
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  • Download
  1: <?php
  2: /**
  3:  * LICENSE (BSD)
  4:  *
  5:  * Copyright (c) 2013, Gerd Christian Kunze
  6:  * All rights reserved.
  7:  *
  8:  * Redistribution and use in source and binary forms, with or without
  9:  * modification, are permitted provided that the following conditions are
 10:  * met:
 11:  *
 12:  *  * Redistributions of source code must retain the above copyright
 13:  *    notice, this list of conditions and the following disclaimer.
 14:  *
 15:  *  * Redistributions in binary form must reproduce the above copyright
 16:  *    notice, this list of conditions and the following disclaimer in the
 17:  *    documentation and/or other materials provided with the distribution.
 18:  *
 19:  *  * Neither the name of Gerd Christian Kunze nor the names of the
 20:  *    contributors may be used to endorse or promote products derived from
 21:  *    this software without specific prior written permission.
 22:  *
 23:  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
 24:  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 25:  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 26:  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 27:  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 28:  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 29:  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 30:  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 31:  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 32:  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 33:  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 34:  *
 35:  * Client
 36:  * 18.02.2013 14:23
 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:      * Get Changelog
 49:      *
 50:      * @static
 51:      * @return \MOC\Core\Changelog
 52:      * @noinspection PhpAbstractStaticMethodInspection
 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:      * Get Dependencies
 63:      *
 64:      * @static
 65:      * @return \MOC\Core\Depending
 66:      * @noinspection PhpAbstractStaticMethodInspection
 67:      */
 68:     public static function InterfaceDepending() {
 69:         return Api::Core()->Depending();
 70:     }
 71: 
 72:     /**
 73:      * Get Singleton/Instance
 74:      *
 75:      * @static
 76:      * @return Client
 77:      * @noinspection PhpAbstractStaticMethodInspection
 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:     /** @var int $ServerTimeout */
100:     private static $ServerTimeout = 15;
101:     /** @var string $ServerChannel */
102:     private static $ServerChannel = 'http://sub.domain.top/server/path';
103:     /**
104:      * @param string $Server
105:      *
106:      * @return \MOC\Module\Installer\Client
107:      */
108:     public function SetServerChannel( $Server = 'http://sub.domain.top/server/path' ) {
109:         self::$ServerChannel = $Server;
110:         return $this;
111:     }
112: 
113:     /**
114:      * @return \MOC\Core\Version[]
115:      */
116:     public function GetVersionList() {
117:         $ClassList = $this->GetClassList();
118:         /** @var \MOC\Core\Version[] $Version */
119:         $Version = array();
120:         /** @var \MOC\Generic\Common $Class */
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:      * @return Entry[]
140:      */
141:     public function GetChangeLog() {
142:         $ClassList = $this->GetClassList();
143:         /** @var Entry[] $Log */
144:         $Log = array();
145:         /** @var \MOC\Generic\Common $Class */
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:      * @return Entry[]
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:     /** @var array $ClassList */
175:     private static $ClassList = array();
176:     /** @var array $ClassDirectory */
177:     private $ClassDirectory = array(
178:         'Adapter',
179:         'Core', 'Extension', 'Module',
180:         'Plugin', 'Widget'
181:     );
182:     /**
183:      * @return array
184:      */
185:     public function GetClassList() {
186:         if( empty( self::$ClassList ) ) {
187:             $BaseDirectory = realpath( __DIR__.'/../../' );
188:             foreach( (array)$this->ClassDirectory as $ClassDirectory ) {
189:                 // Read Directory (recursive)
190:                 $FileList = Api::Module()
191:                     ->Drive()->Directory()->Open(
192:                     realpath( $BaseDirectory.DIRECTORY_SEPARATOR.$ClassDirectory )
193:                 )->FileList( true );
194:                 // Read Class-Definition of relevant File
195:                 array_walk( $FileList, function( &$File, $Index, $BaseDirectory ) {
196:                     /** @var \MOC\Module\Drive\File $File */
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:                 // Save to Class-List
208:                 $FileList = array_filter( $FileList );
209:                 self::$ClassList = array_merge( self::$ClassList, $FileList );
210:             }
211:             // Sort Class-List
212:             sort( self::$ClassList );
213:         }
214:         return self::$ClassList;
215:     }
216: }
217: 
API documentation generated by ApiGen 2.8.0