Skip to content

Commit

Permalink
Add Packager_Builder::reduce to select fewer modules (without using P…
Browse files Browse the repository at this point in the history
…ackager for the whole analyzation again
  • Loading branch information
Arian committed Aug 14, 2011
1 parent 78d52cb commit d04820e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
24 changes: 23 additions & 1 deletion lib/Builder.php
Expand Up @@ -67,7 +67,7 @@ public function output($glue = "\n\n"){

/**
* Concatenates the files by Package
*
*
* @param string $glue optional The glue which joins the code of the different modules together
*/
public function outputByPackage($glue = "\n\n"){
Expand Down Expand Up @@ -118,4 +118,26 @@ static public function fromJSON($json){
return new self(json_decode($json, true));
}

/**
* Reduces the number of modules to the given ids and their dependencies
*
* @param array $ids
* @return Packager_Builder
*/
public function reduce(array $ids, $_oldmodules = null){
if (!$_oldmodules){
$_oldmodules = $this->_modules;
$this->_modules = array();
}
$this->_reduce($ids, $_oldmodules);
return $this;
}

protected function _reduce($ids, $old){
foreach ($ids as $id) if (isset($old[$id]) && !isset($this->_modules[$id])){
$this->_modules[$id] = $old[$id];
$this->reduce($this->_modules[$id]['dependencies'], $old);
}
}

}
12 changes: 12 additions & 0 deletions test/php/BuilderTest.php
Expand Up @@ -173,4 +173,16 @@ public function testSerialization(){

}

public function testReduce(){

$packager = new Packager;
$packager->setBaseUrl($this->fixtures);
$builder = $packager->req(array('basic/three'));

$builder->reduce(array('basic/two'));

$this->assertEquals(array('basic/two', 'basic/one'), $builder->modules());

}

}

0 comments on commit d04820e

Please sign in to comment.