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

  • Gateway
  • Repository
  • Shared
  • 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:  * Repository
 36:  * 10.06.2013 11:56
 37:  */
 38: namespace MOC\Plugin;
 39: use MOC\Api;
 40: use MOC\Generic\Common;
 41: 
 42: /**
 43:  *
 44:  */
 45: class Repository implements Common {
 46:     /**
 47:      * Get Changelog
 48:      *
 49:      * @static
 50:      * @return \MOC\Core\Changelog
 51:      * @noinspection PhpAbstractStaticMethodInspection
 52:      */
 53:     public static function InterfaceChangelog() {
 54:         Api::Core()->Changelog();
 55:     }
 56: 
 57:     /**
 58:      * Get Dependencies
 59:      *
 60:      * @static
 61:      * @return \MOC\Core\Depending
 62:      * @noinspection PhpAbstractStaticMethodInspection
 63:      */
 64:     public static function InterfaceDepending() {
 65:         Api::Core()->Depending();
 66:     }
 67: 
 68:     /** @var Repository $Singleton */
 69:     private static $Singleton = null;
 70: 
 71:     /**
 72:      * Get Singleton/Instance
 73:      *
 74:      * @static
 75:      * @return Repository
 76:      * @noinspection PhpAbstractStaticMethodInspection
 77:      */
 78:     public static function InterfaceInstance() {
 79:         if( self::$Singleton === null ) {
 80:             self::$Singleton = new Repository();
 81:             self::$Singleton->LoadRepository();
 82:         } return self::$Singleton;
 83:     }
 84: 
 85:     /** @var Shared[] $Repository */
 86:     private $Repository = array();
 87:     /** @var Shared[] $Helper */
 88:     private $Helper = array(
 89:         'mocStyleSheetHelper',
 90:         'mocJavaScriptHelper'
 91:     );
 92: 
 93:     private function LoadRepository() {
 94:         $Repository = Api::Module()->Drive()->Directory()->Open( __DIR__.DIRECTORY_SEPARATOR.'Repository' )->FileList();
 95: 
 96:         // HelperPlugins
 97:         foreach( $this->Helper as $Plugin ) {
 98:             $Reflection = new \ReflectionClass( 'MOC\\Plugin\\Repository\\'.$Plugin );
 99:             $Plugin = $Reflection->newInstance();
100:             $this->Repository[$Reflection->getParentClass()->getName()][$Reflection->getShortName()] = $Plugin;
101:         }
102: 
103:         foreach( $Repository as $Plugin ) {
104:             try {
105:                 $Reflection = new \ReflectionClass( 'MOC\\Plugin\\Repository\\'.$Plugin->GetName() );
106:                 if( is_object( $Reflection->getParentClass() )
107:                     && is_object( $Reflection->getParentClass()->getParentClass() )
108:                     && is_object( $Reflection->getParentClass()->getParentClass()->getParentClass() )
109:                     && $Reflection->getParentClass()->getParentClass()->getParentClass()->getName() == 'MOC\\Plugin\\Shared'
110:                 ) {
111: 
112:                     /** @var Shared $Plugin */
113:                     $Plugin = $Reflection->newInstance();
114:                     if( !isset( $this->Repository[$Reflection->getParentClass()->getName()] )
115:                         || !isset( $this->Repository[$Reflection->getParentClass()->getName()][$Reflection->getShortName()] )
116:                     ) {
117:                         $this->Repository[$Reflection->getParentClass()->getName()][$Reflection->getShortName()] = $Plugin;
118:                         $Plugin->PluginLoader();
119:                     }
120:                 } else {
121:                     Api::Core()->Error()->Type()->Exception()->Trigger( 'Plugin-Repository: '.$Reflection->getName().' is not a plugin!', $Plugin->GetLocation(), $Reflection->getStartLine() );
122:                 }
123:             } catch( \Exception $Exception  ) {
124:                 Api::Core()->Error()->Type()->Exception()->Trigger( $Exception->getMessage(), $Exception->getFile(), $Exception->getLine(), $Exception->getTraceAsString() );
125:             }
126:         }
127:     }
128: 
129:     /**
130:      * @param Shared $Shared
131:      * @param null|string $PluginName - Name of specific plugin to use
132:      *
133:      * @return Shared|null
134:      */
135:     public function Execute( Shared $Shared, $PluginName = null ) {
136:         $SharedReflection = new \ReflectionObject( $Shared );
137:         if( $SharedReflection->getNamespaceName() != 'MOC\\Plugin\\Shared' ) {
138:             Api::Core()->Error()->Type()->Exception()->Trigger( 'Plugin-Repository: '.$SharedReflection->getName().' is not a valid plugin configuration!', __FILE__, __LINE__ );
139:         }
140:         $SharedPropertyList = $SharedReflection->getProperties();
141:         $PluginGateway = 'MOC\\Plugin\\Gateway\\'.$SharedReflection->getShortName();
142:         foreach( $this->Repository[$PluginGateway] as $Plugin ) {
143:             /** @var Shared $Plugin  */
144:             if( $PluginName !== null && $PluginName != $Plugin->PluginName() ) {
145:                 continue;
146:             }
147:             /** @var Shared $Prospect */
148:             $Prospect = clone $Plugin;
149:             foreach( $SharedPropertyList as $Property ) {
150:                 $Prospect->{$Property->getName()}( $Shared->{$Property->getName()}() );
151:             }
152:             if( $Prospect->PluginCapable() ) {
153:                 return $Prospect;
154:             }
155:         }
156:         if( $PluginName !== null ) {
157:             Api::Core()->Error()->Type()->Exception()->Trigger( 'Plugin-Repository: '.$PluginName.' is either not available or not a capable plugin!', __FILE__, __LINE__ );
158:         } else {
159:             Api::Core()->Error()->Type()->Exception()->Trigger( 'Plugin-Repository: Missing capable '.$PluginGateway.' plugin!', __FILE__, __LINE__ );
160:         }
161:         return null;
162:     }
163: }
164: 
API documentation generated by ApiGen 2.8.0