Skip to content

Commit

Permalink
added ClassmapClearTask
Browse files Browse the repository at this point in the history
  • Loading branch information
heartsentwined committed Sep 17, 2012
1 parent db6983e commit 1680c23
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ Generate a classmap for the directory `foo/library` (and its subdirectories), sa
</project>
```

## ClassmapClearTask

Clear the classmap file `foo/autoload_classmap.php`, i.e. set it to `return array();`.

```xml
<project>
<target>
<includepath classpath="vendor/heartsentwined/phing-task/src/task" />
<taskdef name="classmap-clear" classname="ClassmapClearTask" />
<classmap-clear file="foo/autoload_classmap.php" />
</target>
</project>
```

## RchownTask

Recursively [chown](http://php.net/manual/en/function.chown.php) the directory `foo/src`, along with all its subdirectories and files, to the user `foouser` and group `foogroup`.
Expand Down
64 changes: 64 additions & 0 deletions src/task/ClassmapClearTask.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
require_once __DIR__ . '/../../../../autoload.php';

use Zend\File\ClassFileLocator;

class ClassmapClearTask extends Task
{
protected $file;
protected $failonerror = false;

/**
* classmap file
*
* @param string $file
* @return void
*/
public function setFile($file)
{
touch($file);
$this->file = realpath($file);
}

/**
* if error occured, whether build should fail
*
* @param bool $value
* @return void
*/
public function setFailonerror($value)
{
$this->failonerror = $value;
}

/**
* init
*
* @return void
*/
public function init()
{
}

/**
* main method
*
* @return void
*/
public function main()
{
$this->log(sprintf('Clearing classmap file %s', $this->file));

// Create a file with the class/file map.
// Stupid syntax highlighters make separating < from PHP declaration necessary
$content = '<' . "?php\n"
. "// Auto-generated by Phing, using ZF2's classmap generator\n"
. '// Generation time: ' . date(DATE_RFC2822) . "\n"
. 'return array();';

// Write the contents to disk
file_put_contents($this->file, $content);

$this->log(sprintf('Cleared classmap file at %s', $this->file));
}
}

0 comments on commit 1680c23

Please sign in to comment.