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

  • Directory
  • File
  • 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:  * File
 36:  * 30.08.2012 13:37
 37:  */
 38: namespace MOC\Core\Drive;
 39: use MOC\Api;
 40: use MOC\Generic\Common\Instance;
 41: 
 42: /**
 43:  *
 44:  */
 45: class File extends File\Read implements Instance {
 46: 
 47:     /**
 48:      * Get Singleton/Instance
 49:      *
 50:      * @static
 51:      * @return File
 52:      */
 53:     public static function InterfaceInstance() {
 54:         return new File();
 55:     }
 56: 
 57:     /**
 58:      * Get Dependencies
 59:      *
 60:      * @static
 61:      * @return \MOC\Core\Depending
 62:      */
 63:     public static function InterfaceDepending() {
 64:         return Api::Core()->Depending();
 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:             ->Fix()->DocFix( '19.02.2013 11:05', 'Correct Parameter-Types' )
 76:             ->Build()->Clearance( '19.02.2013 11:05', 'Alpha' )
 77:         ;
 78:     }
 79: 
 80:     /**
 81:      * File-to-Handle
 82:      *
 83:      * @param string $Location
 84:      *
 85:      * @return \MOC\Core\Drive\File
 86:      */
 87:     public function Handle( $Location ) {
 88:         $this->Location( $Location );
 89:         $this->UpdateProperties();
 90:         return $this;
 91:     }
 92: 
 93:     /**
 94:      * File-Exists
 95:      *
 96:      * @return bool
 97:      */
 98:     public function Exists() {
 99:         if( file_exists( $this->Location() ) ) {
100:             return true;
101:         } else {
102:             return false;
103:         }
104:     }
105: 
106:     /**
107:      * File-Content
108:      *
109:      * @param array|null|string $Content
110:      * @param int  $Type
111:      *
112:      * @return array|null|string|File
113:      */
114:     public function Content( $Content = null, $Type = self::AS_STRING ) {
115:         if( $Content !== null ) {
116:             if( $this->Content !== null ) { $this->Changed( true ); }
117:             $this->Content = $Content;
118:             $this->Changed( true );
119:             return $this;
120:         } elseif( $this->Content === null ) {
121:             switch( $Type ) {
122:                 case self::AS_STRING: { $this->ReadAsString(); break; }
123:                 case self::AS_ARRAY: { $this->ReadAsArray(); break; }
124:                 case self::AS_PHP: { $this->ReadAsPhpCode(); break; }
125:             }
126:             $this->Changed( false );
127:             return $this->Content;
128:         } else {
129:             return $this->Content;
130:         }
131:     }
132: 
133:     /**
134:      * File-Hash
135:      *
136:      * @return null|string
137:      */
138:     public function Hash() {
139:         return ( file_exists( $this->Location() ) ? sha1_file( $this->Location() ) : sha1( $this->Location() ) );
140:     }
141: 
142: 
143:     /**
144:      * @return File
145:      */
146:     public function SetFileNameEncoding() {
147:         $FileName = self::MixedToUtf8( $this->Name() );
148: 
149:         $FileName = str_replace(
150:             array('ä', 'ö', 'ü', 'ß', 'ó', 'è', 'é'),
151:             array('ae', 'oe', 'ue', 'ss', 'o', 'e', 'e'),
152:         $FileName );
153: 
154:         $FileName = preg_replace( '/\s/s', '-', $FileName );
155: 
156:         $FileName = preg_replace('/[^a-z0-9_-]/isU', '', $FileName);
157: 
158:         $FileName = trim($FileName);
159: 
160:         $this->Name( $FileName );
161: 
162:         $this->Location( dirname( $this->Location() ).DIRECTORY_SEPARATOR.$FileName.(strlen($this->Extension())?'.'.$this->Extension():'') );
163: 
164:         return $this;
165:     }
166: 
167:     private static $DictionaryLatin1ToUtf8 = null;
168:     private static $DictionaryUtf8ToLatin1 = null;
169: 
170:     private static function BuildDictionary() {
171:         if( self::$DictionaryUtf8ToLatin1 === null || self::$DictionaryLatin1ToUtf8 === null ) {
172:             for ($Run = 32; $Run <= 255; $Run++) {
173:                 self::$DictionaryLatin1ToUtf8[chr($Run)] = utf8_encode(chr($Run));
174:                 self::$DictionaryUtf8ToLatin1[utf8_encode(chr($Run))] = chr($Run);
175:             }
176:         }
177:     }
178: 
179:     /**
180:      * @param string $Text
181:      *
182:      * @return string
183:      */
184:     public static function MixedToLatin1( $Text ) {
185:         self::BuildDictionary();
186:         foreach ( self::$DictionaryUtf8ToLatin1 as $Key => $Val) {
187:             $Text = str_replace( $Key, $Val, $Text );
188:         }
189:         return $Text;
190:     }
191: 
192:     /**
193:      * @param string $Text
194:      *
195:      * @return string
196:      */
197:     public static function MixedToUtf8( $Text ) {
198:         self::BuildDictionary();
199:         return utf8_encode( self::MixedToLatin1( $Text ) );
200:     }
201: }
202: 
API documentation generated by ApiGen 2.8.0