Skip to content

Instantly share code, notes, and snippets.

@M1ke
Created October 6, 2012 00:54
Show Gist options
  • Save M1ke/3843296 to your computer and use it in GitHub Desktop.
Save M1ke/3843296 to your computer and use it in GitHub Desktop.
Phing Last Build Time Saver
<?php
/*
* $Id: FileSizeTask.php 1084 2011-05-06 09:55:25Z mrook $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
require_once 'phing/Task.php';
/**
* lastBuilt
*
* @author Mike Lehan <mike@m1ke.me>
* @version $Id: PhingBuilttask.php 1084 2012-10-06 01:53:25Z
* @package phing.tasks.ext
*/
class PhingBuiltTask extends Task
{
/**
* Property for File
* @var PhingFile file
*/
private $file;
private $save=0;
/**
* Property where the file size will be stored
* @var string $property
*/
private $propertyName = "lastbuilt";
/**
* Which file to calculate the file size of
* @param PhingFile $file
*/
public function setFile($file)
{
$this->file = $file;
}
public function setSave($save)
{
$this->save = $save;
}
/**
* Set the name of the property to store the file size
* @param $property
* @return void
*/
public function setPropertyName($property)
{
$this->propertyName = $property;
}
/**
* Main-Method for the Task
*
* @return void
* @throws BuildException
*/
public function main()
{
date_default_timezone_set('GMT');
// $format='d/m/Y H:i A';
$format='';
if ($this->save==1)
{
//save new build time
$fh=fopen($this->file,'w+');
fwrite($fh,time());
fclose($fh);
}
else
{
if (file_exists($this->file))
{
$fh=fopen($this->file,'r');
$time=fread($fh,filesize($this->file));
fclose($fh);
}
else $time='0';
$this->project->setProperty($this->propertyName, $time);
}
}
/**
* checks file attribute
* @return void
* @throws BuildException
*/
private function checkFile()
{
// check File
if ($this->file === null ||
strlen($this->file) == 0) {
throw new BuildException('[FileSize] You must specify an input file.', $this->file);
}
if( ! is_readable($this->file) ) {
throw new BuildException(sprintf('[FileSize] Input file does not exist or is not readable: %s',$this->file));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment