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

  • Script
  • Style
  • 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:  * Script
 36:  * 13.03.2013 10:54
 37:  */
 38: namespace MOC\Module\Packer\Yui;
 39: 
 40: use MOC\Api;
 41: use MOC\Generic\Device\Module;
 42: use MOC\Module\Drive\File;
 43: 
 44: /**
 45:  *
 46:  */
 47: class Script implements Module {
 48: 
 49:     /**
 50:      * Get Singleton/Instance
 51:      *
 52:      * @static
 53:      * @return Script
 54:      */
 55:     public static function InterfaceInstance() {
 56:         return new Script();
 57:     }
 58: 
 59:     /**
 60:      * Get Changelog
 61:      *
 62:      * @static
 63:      * @return \MOC\Core\Changelog
 64:      */
 65:     public static function InterfaceChangelog() {
 66:         return Api::Core()->Changelog()->Create( __CLASS__ );
 67:     }
 68: 
 69:     /**
 70:      * Get Dependencies
 71:      *
 72:      * @static
 73:      * @return \MOC\Core\Depending
 74:      */
 75:     public static function InterfaceDepending() {
 76:         return Api::Core()->Depending();
 77:     }
 78: 
 79:     /** @var string $Content */
 80:     private $Content = '';
 81: 
 82:     /**
 83:      * @param string $Content
 84:      * @param bool $asRaw
 85:      *
 86:      * @return $this
 87:      */
 88:     public function AddContent( $Content, $asRaw = false ) {
 89:         if( $asRaw ) {
 90:             $this->Content .= $Content;
 91:         } else {
 92:             $this->Content .= $this->Compress( $Content );
 93:         }
 94:         return $this;
 95:     }
 96: 
 97:     /**
 98:      * @param File $File
 99:      * @param bool $asRaw
100:      *
101:      * @return $this
102:      */
103:     public function AddFile( File $File, $asRaw = false ) {
104:         if( $asRaw ) {
105:             $this->Content .= $File->Read();
106:         } else {
107:             $this->Content .= $this->Compress( $File->Read() );
108:         }
109:         return $this;
110:     }
111: 
112:     /**
113:      * @param File $File
114:      */
115:     public function SaveAs( File $File ) {
116:         $File->Write( $this->Content );
117:     }
118: 
119:     /**
120:      * @param string $String
121:      *
122:      * @return string
123:      */
124:     private function Compress( $String ) {
125:         $Yui = Api::Extension()->YUICompressor()->Create()->Current();
126:         $Yui->setOption( 'type', 'js' );
127:         $Yui->setOption( 'linebreak', false );
128:         $Yui->setOption( 'verbose', false );
129:         $Yui->setOption( 'nomunge', false );
130:         $Yui->setOption( 'semi', false );
131:         $Yui->setOption( 'nooptimize', false );
132:         $Yui->addString( $String );
133:         return implode( "\n", $Yui->compress() );
134:     }
135: }
136: 
API documentation generated by ApiGen 2.8.0