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:  * Server
 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 Server 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();
 56:     }
 57: 
 58:     /**
 59:      * Get Dependencies
 60:      *
 61:      * @static
 62:      * @return \MOC\Core\Depending
 63:      * @noinspection PhpAbstractStaticMethodInspection
 64:      */
 65:     public static function InterfaceDepending() {
 66:         return Api::Core()->Depending();
 67:     }
 68: 
 69:     /**
 70:      * Get Singleton/Instance
 71:      *
 72:      * @static
 73:      * @return Server
 74:      * @noinspection PhpAbstractStaticMethodInspection
 75:      */
 76:     public static function InterfaceInstance() {
 77:         $Server = new Server();
 78:         $Server->SetServerLibrary( __DIR__.'/../../Library' );
 79:         return $Server;
 80:     }
 81: 
 82: 
 83:     public function CreateLibrary() {
 84:         $BaseDirectory = realpath( __DIR__.'/../../' );
 85: 
 86:         $VersionList = $this->GetVersionList();
 87:         /** @var \MOC\Core\Version $Version */
 88:         foreach( (array)$VersionList as $Class => $Version ) {
 89: 
 90:             set_time_limit( 120 );
 91: 
 92:             $File = basename( $Class ).'-'.$Version->Number().'.zip';
 93:             $Source = str_replace( '\MOC', '', $Class );
 94:             $Path = dirname( $Source );
 95:             $Location = self::$ServerLibrary.$Path.DIRECTORY_SEPARATOR.$File;
 96:             $Handler = Api::Module()->Drive()->File()->Open( $Location );
 97: 
 98:             $RootBase = dirname( $BaseDirectory.$Source );
 99:             $RootDir = $RootBase.DIRECTORY_SEPARATOR.basename( $BaseDirectory.$Source );
100:             $RootFile = $RootDir.'.php';
101: 
102:             if(
103:                 ( false !== strpos( $Class, 'MOC\Adapter' ) )
104:             ) {
105:                 if( !$Handler->Exists() ) {
106:                     $PackageDir = Api::Module()->Drive()->Directory()->Open( $Handler->GetPath() );
107:                     $PackageFile = Api::Module()->Packer()->Zip()->Encoder()->Open( $Handler );
108:                     $PackageFile->Content( Api::Module()->Drive()->File()->Open( $RootFile ), $RootBase );
109:                 }
110:             }
111:             else if(
112:                 ( false !== strpos( $Class, 'MOC\Core' ) )
113:                 || ( false !== strpos( $Class, 'MOC\Module' ) )
114:             ) {
115:                 if( !$Handler->Exists() ) {
116:                     $PackageDir = Api::Module()->Drive()->Directory()->Open( $Handler->GetPath() );
117:                     $PackageFile = Api::Module()->Packer()->Zip()->Encoder()->Open( $Handler );
118:                     $PackageFile->Content( Api::Module()->Drive()->File()->Open( $RootFile ), $RootBase );
119:                 }
120:             }
121:             else if(
122:                 ( false !== strpos( $Class, 'MOC\Extension' ) )
123:             ) {
124:                 if( !$Handler->Exists() ) {
125:                     $PackageDir = Api::Module()->Drive()->Directory()->Open( $Handler->GetPath() );
126:                     $PackageFile = Api::Module()->Packer()->Zip()->Encoder()->Open( $Handler );
127:                     $PackageFile->Content( Api::Module()->Drive()->File()->Open( $RootFile ), $RootBase );
128:                     if( is_dir( $RootBase.DIRECTORY_SEPARATOR.'3rdParty' ) ) {
129:                         $FileList = Api::Module()->Drive()->Directory()->Open(
130:                             $RootBase.DIRECTORY_SEPARATOR.'3rdParty'
131:                         )->FileList( true );
132:                         /** @var \MOC\Module\Drive\File $File */
133:                         foreach( (array)$FileList as $File ) {
134:                             $PackageFile->Content( $File, $RootBase );
135:                         }
136:                     }
137: 
138:                 }
139:             }
140:         }
141:     }
142: 
143:     /** @var string $ServerLibrary */
144:     private static $ServerLibrary = '';
145:     /**
146:      * @param string $Server
147:      *
148:      * @return \MOC\Module\Installer\Client
149:      */
150:     public function SetServerLibrary( $Server ) {
151:         self::$ServerLibrary = Api::Module()->Drive()->Directory()->Open( $Server )->GetLocation();
152:         return $this;
153:     }
154: 
155:     /**
156:      * Get a Protocol for a single Class
157:      *
158:      * @param $Class
159:      *
160:      * @return mixed
161:      */
162:     public function GetProtocol( $Class ) {
163:         /** @var \MOC\Generic\Common $Class */
164:         return $Class::InterfaceChangelog()->Protocol();
165:     }
166: 
167:     /**
168:      * Get a List of Protocols for all Classes
169:      *
170:      * @return array
171:      */
172:     public function GetProtocolList() {
173:         $ClassList = $this->GetClassList();
174:         $List = array();
175:         /** @var \MOC\Generic\Common $Class */
176:         foreach( (array)$ClassList as $Class ) {
177:             $List = array_merge( $List, $Class::InterfaceChangelog()->Protocol() );
178:         }
179:         return $List;
180:     }
181: 
182:     /**
183:      * @return \MOC\Core\Version[]
184:      */
185:     public function GetVersionList() {
186:         $ClassList = $this->GetClassList();
187:         /** @var \MOC\Core\Version[] $Version */
188:         $Version = array();
189:         /** @var \MOC\Generic\Common $Class */
190:         foreach( (array)$ClassList as $Class ) {
191:             $rClass = new \ReflectionClass( $Class );
192:             if( $rClass->hasMethod( 'InterfaceChangelog' ) ) {
193:                 $Version[(string)$Class] = $Class::InterfaceChangelog();
194:                 $rClass = new \ReflectionClass( get_class( $Version[(string)$Class] ) );
195:                 if( $rClass->hasMethod( 'Version' ) ) {
196:                     $Version[(string)$Class] = $Version[(string)$Class]->Version();
197:                 } else {
198:                     trigger_error( 'Missing Version() in '.$Class );
199:                 }
200:             } else {
201:                 trigger_error( 'Missing InterfaceChangelog() in '.$Class );
202:             }
203:         }
204:         return $Version;
205:     }
206: 
207:     /**
208:      * @return Entry[]
209:      */
210:     public function GetChangeLog() {
211:         $ClassList = $this->GetClassList();
212:         /** @var Entry[] $Log */
213:         $Log = array();
214:         /** @var \MOC\Generic\Common $Class */
215:         foreach( (array)$ClassList as $Class ) {
216:             $rClass = new \ReflectionClass( $Class );
217:             if( $rClass->hasMethod( 'InterfaceChangelog' ) ) {
218:                 $Log = array_merge( $Log, $Class::InterfaceChangelog()->Log() );
219:             }
220:         }
221:         return $Log;
222:     }
223: 
224:     /**
225:      * @return Entry[]
226:      */
227:     public function GetChangeLogByTimeLine() {
228:         $Log = $this->GetChangeLog();
229: 
230:         usort( $Log, function( Entry $A, Entry $B ) {
231:             if( $A->Timestamp() > $B->Timestamp() ) {
232:                 return -1;
233:             } else if( $A->Timestamp() < $B->Timestamp() ) {
234:                 return 1;
235:             } else {
236:                 return 0;
237:             }
238:         });
239: 
240:         return $Log;
241:     }
242: 
243:     /** @var array $ClassList */
244:     private static $ClassList = array();
245:     /** @var array $ClassDirectory */
246:     private $ClassDirectory = array(
247:         'Adapter',
248:         'Core', 'Extension', 'Module',
249:         'Plugin', 'Widget'
250:     );
251:     /**
252:      * @return array
253:      */
254:     public function GetClassList() {
255:         if( empty( self::$ClassList ) ) {
256:             $BaseDirectory = realpath( __DIR__.'/../../' );
257:             foreach( (array)$this->ClassDirectory as $ClassDirectory ) {
258:                 // Read Directory (recursive)
259:                 $FileList = Api::Module()
260:                     ->Drive()->Directory()->Open(
261:                     realpath( $BaseDirectory.DIRECTORY_SEPARATOR.$ClassDirectory )
262:                 )->FileList( true );
263:                 // Read Class-Definition of relevant File
264:                 array_walk( $FileList, function( &$File, $Index, $BaseDirectory ) {
265:                     /** @var \MOC\Module\Drive\File $File */
266:                     if(
267:                         false !== strpos( $File->GetPath(), '#Trash' )
268:                         || false !== strpos( $File->GetPath(), '3rdParty' )
269:                         || $File->GetExtension() !== 'php'
270:                     ) {
271:                         $File = false;
272:                     } else {
273:                         $File = '\\MOC'.str_replace( $BaseDirectory, '', $File->GetPath() ).'\\'.$File->GetName();
274:                     }
275:                 }, $BaseDirectory );
276:                 // Save to Class-List
277:                 $FileList = array_filter( $FileList );
278:                 self::$ClassList = array_merge( self::$ClassList, $FileList );
279:             }
280:             // Sort Class-List
281:             sort( self::$ClassList );
282:         }
283:         return self::$ClassList;
284:     }
285: }
286: 
API documentation generated by ApiGen 2.8.0