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

  • Property
  • Read
  • Write
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  • Download
  1: <?php
  2: /**
  3:  * LICENSE (BSD)
  4:  *
  5:  * Copyright (c) 2012, 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:  * Read
 36:  * 31.07.2012 16:48
 37:  */
 38: namespace MOC\Core\Drive\Directory;
 39: use MOC\Api;
 40: use MOC\Core\Drive;
 41: 
 42: /**
 43:  * Directory-Read
 44:  */
 45: class Read extends Write {
 46: 
 47:     /**
 48:      * Get Dependencies
 49:      *
 50:      * @static
 51:      * @return \MOC\Core\Depending
 52:      */
 53:     public static function InterfaceDepending() {
 54:         return Api::Core()->Depending();
 55:     }
 56: 
 57:     /**
 58:      * Get Singleton/Instance
 59:      *
 60:      * @static
 61:      * @return object
 62:      */
 63:     public static function InterfaceInstance() {
 64:         return new Read();
 65:     }
 66: 
 67:     /**
 68:      * Get Changelog
 69:      *
 70:      * @static
 71:      * @return \MOC\Core\Changelog
 72:      */
 73:     public static function InterfaceChangelog() {
 74:         return Api::Core()->Changelog()->Create( __CLASS__ );
 75:     }
 76: 
 77:     /**
 78:      * @param $Name
 79:      *
 80:      * @return \MOC\Core\Drive\File
 81:      */
 82:     public function File( $Name ) {
 83:         return Drive::InterfaceInstance()->File()->Handle( $this->Location().DIRECTORY_SEPARATOR.$Name );
 84:     }
 85: 
 86:     /**
 87:      * @return \MOC\Core\Drive\File[]
 88:      */
 89:     public function FileList() {
 90:         if( is_dir( $this->Location() ) ) {
 91:             $List = array();
 92:             if( ($Directory = $this->DirectoryHandler()) ) {
 93:                 while ( false !== ( $Item = $Directory->read() ) ) {
 94:                     if( $Item != '.' && $Item != '..' ) {
 95:                         $Item = $this->UpdateSyntax( $this->Location() . DIRECTORY_SEPARATOR . $Item );
 96:                         if( !is_dir( $Item ) ) {
 97:                             array_push( $List, Drive::InterfaceInstance()->File()->Handle( $Item ) );
 98:                         }
 99:                     }
100:                 }
101:             }
102:             $Directory->close();
103:             return $List;
104:         } else {
105:             return array();
106:         }
107:     }
108: 
109:     /**
110:      * @return \MOC\Core\Drive\File[]
111:      */
112:     public function FileListRecursive() {
113:         if( is_dir( $this->Location() ) ) {
114:             $List = array();
115:             if( ($Directory = $this->DirectoryHandler()) ) {
116:                 while ( false !== ( $Item = $Directory->read() ) ) {
117:                     if( $Item != '.' && $Item != '..' ) {
118:                         $Item = $this->UpdateSyntax($this->Location() . DIRECTORY_SEPARATOR . $Item );
119:                         if( is_dir( $Item ) ) {
120:                             $Recursive = Drive::InterfaceInstance()->Directory()->Handle( $Item );
121:                             $List = array_merge( $List, $Recursive->FileListRecursive() );
122:                         } else {
123:                             array_push( $List, Drive::InterfaceInstance()->File()->Handle( $Item ) );
124:                         }
125:                     }
126:                 }
127:             }
128:             $Directory->close();
129:             return $List;
130:         } else {
131:             return array();
132:         }
133:     }
134: 
135:     /**
136:      * @return \MOC\Core\Drive\Directory[]
137:      */
138:     public function DirectoryList() {
139:         if( is_dir( $this->Location() ) ) {
140:             $List = array();
141:             if( ($Directory = $this->DirectoryHandler()) ) {
142:                 while ( false !== ( $Item = $Directory->read() ) ) {
143:                     if( $Item != '.' && $Item != '..' ) {
144:                         $Item = $this->UpdateSyntax( $this->Location() . DIRECTORY_SEPARATOR . $Item );
145:                         if( is_dir( $Item ) ) {
146:                             array_push( $List, Drive::InterfaceInstance()->Directory()->Handle( $Item ) );
147:                         }
148:                     }
149:                 }
150:             }
151:             $Directory->close();
152:             return $List;
153:         } else {
154:             return array();
155:         }
156:     }
157: 
158:     /**
159:      * @return \MOC\Core\Drive\Directory[]
160:      */
161:     public function DirectoryListRecursive() {
162:         if( is_dir( $this->Location() ) ) {
163:             $List = array();
164:             if( ($Directory = $this->DirectoryHandler()) ) {
165:                 while ( false !== ( $Item = $Directory->read() ) ) {
166:                     if( $Item != '.' && $Item != '..' ) {
167:                         $Item = $this->UpdateSyntax( $this->Location() . DIRECTORY_SEPARATOR . $Item );
168:                         if( is_dir( $Item ) ) {
169:                             $Recursive = Drive::InterfaceInstance()->Directory()->Handle( $Item );
170:                             array_push( $List, Drive::InterfaceInstance()->Directory()->Handle( $Item ) );
171:                             $List = array_merge( $List, $Recursive->DirectoryListRecursive() );
172:                         }
173:                     }
174:                 }
175:             }
176:             $Directory->close();
177:             return $List;
178:         } else {
179:             return array();
180:         }
181:     }
182: 
183:     /**
184:      * @return string
185:      */
186:     public function DirectoryRoot() {
187:         $this->UpdateDocumentRootOnIIS();
188:         return $this->UpdateSyntax( $_SERVER['DOCUMENT_ROOT'] );
189:     }
190: 
191:     /**
192:      * @return string
193:      */
194:     public function DirectoryCurrent() {
195:         return $this->UpdateSyntax( $this->DirectoryRoot().dirname($_SERVER['SCRIPT_NAME']) );
196:     }
197: 
198:     /**
199:      * @param \MOC\Core\Drive\Directory $Target
200:      *
201:      * @return \MOC\Core\Drive\Directory
202:      */
203: /*  public function DirectoryRelative( \MOC\Core\Drive\Directory $Target ) {
204:         $Result = \MOC\Core\Drive\Directory::InterfaceInstance();
205: 
206:         $WorkBase = explode( DIRECTORY_SEPARATOR, $this->Location() );
207:         $WorkTarget = explode( DIRECTORY_SEPARATOR, $Target->Location() );
208:         $WorkRelative = '';
209: 
210:         $WorkCommon = array_intersect_assoc( $WorkBase, $WorkTarget );
211:         $WorkGetOut = array_diff_assoc( $WorkBase, $WorkCommon );
212:         $WorkGetIn = array_diff_assoc( $WorkTarget, $WorkCommon );
213: 
214:         $RelativeBase = implode( DIRECTORY_SEPARATOR, $WorkCommon ).DIRECTORY_SEPARATOR;
215:         $RelativeTarget = implode( DIRECTORY_SEPARATOR, $WorkGetIn ).DIRECTORY_SEPARATOR;
216:         $RelativePath = $RelativeBase;
217:         foreach( (array)$WorkGetOut as $Index => $Directory ) {
218:             $RelativePath .= $Directory.'/../';
219:         }
220:         $RelativePath .= $RelativeTarget;
221: 
222:         $Result->Handle( $RelativePath );
223:         return $Result;
224:     }
225: */
226:     /**
227:      * @return bool|\Directory
228:      */
229:     private function DirectoryHandler() {
230:         if( !is_object( $DirectoryHandler = dir( $this->Location() ) ) ) {
231:             return false;
232:         }
233:         return  $DirectoryHandler;
234:     }
235: 
236: }
237: 
API documentation generated by ApiGen 2.8.0