Skip to content
Browse files

Added support for compactAll(); Added basis for exclude().

Testing definitely needs to be updated.
  • Loading branch information...
1 parent 2c352a9 commit 9eb55c70f38b9ddf155e44090b989630ca628fdf @technosophos committed
Showing with 52 additions and 1 deletion.
  1. +44 −0 src/lib/compactor.php
  2. +8 −1 src/phpcompactor.php
View
44 src/lib/compactor.php
@@ -26,6 +26,9 @@ class Compactor {
private $compacted = array();
private $handle;
+ /** The files excluded during a {@link compactAll()}. */
+ protected $excludes = array();
+
public function __construct($outfile) {
$this->handle = fopen($outfile, 'w');
fwrite($this->handle, '<?php' . PHP_EOL);
@@ -37,6 +40,47 @@ public function compact($file) {
$this->compacted[] = $compact;
}
+ /**
+ * Exclude these files from compacting.
+ *
+ * @param array $files
+ * An array of files to exclude.
+ */
+ public function exclude($files) {
+ $expanded = array();
+ // Expand wildcards:
+ foreach ($files as $pattern) {
+ $expanded += glob($pattern);
+ }
+
+ // Probably should do something to remove duplicates.
+
+ $this->excludes = $expanded;
+ }
+
+ /**
+ * Returns the expanded exclusion list.
+ */
+ public function getExcludedFiles() {
+ return $this->excludes;
+ }
+
+ /**
+ * Compact the given file and all included files.
+ *
+ * Files specified in the 'excludes' list will not be compacted here.
+ *
+ * @param string $baseFile
+ * The base file to exclude.
+ */
+ public function compactAll($baseFile) {
+ $before = get_included_files();
+ include $baseFile;
+ $files = array_diff(get_included_files(),$before);
+
+ foreach($files as $file) $this->compact($file);
+ }
+
public function report() {
$lenbefore = 0;
$lenafter = 0;
View
9 src/phpcompactor.php 100644 → 100755
@@ -20,11 +20,18 @@
print "Compacting $source into $target.\n";
$compactor = new Compactor($target);
+/*
$before = get_included_files();
include $source;
$files = array_diff(get_included_files(),$before);
foreach($files as $file) $compactor->compact($file);
+*/
+//$compactor->exclude(array('test.php'));
+//print_r($compactor->getExcludedFiles());
+
+$compactor->compactAll($source);
+
$compactor->report();
-$compactor->close();
+$compactor->close();

0 comments on commit 9eb55c7

Please sign in to comment.
Something went wrong with that request. Please try again.