Created
November 3, 2011 12:23
-
-
Save pinscript/1336371 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class Smash { | |
| /** | |
| * Combine all files with a certain extension in a directory into a single file | |
| */ | |
| public function smash_directory($directory, $extension, $output) { | |
| $files = glob($directory . '*.' . $extension); | |
| $smashed = ''; | |
| foreach($files as $file) { | |
| $content = sprintf($this->get_comment($extension), $file); | |
| $content .= $this->read_file($file); | |
| $smashed .= $content; // Add file to combined output | |
| } | |
| $this->write_file($output, $smashed); | |
| } | |
| private function read_file($path) { | |
| return file_get_contents($path); | |
| } | |
| private function write_file($path, $content) { | |
| file_put_contents($path, $content); | |
| } | |
| private function get_comment($filetype) { | |
| switch($filetype) { | |
| case 'css': | |
| case 'js': | |
| return '/* %s */'; | |
| case 'php': | |
| return '<?php /* */ ?>'; | |
| } | |
| trigger_error('Unknown filetype: ' . $filetype); | |
| } | |
| } | |
| $smash = new Smash; | |
| $smash->smash_directory('functions', 'css', 'smashed.css'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment