<?php
//
// +--------------------------------------------------------------------+
// | Sourdough PHP Application Framework |
// +--------------------------------------------------------------------+
// | Copyright (c) 2001-2007 Philip Iezzi, phpee.com |
// | Web http://sourdough.phpee.com/ |
// | License GNU Lesser General Public License (LGPL) |
// +--------------------------------------------------------------------+
// | This library is free software; you can redistribute it and/or |
// | modify it under the terms of the GNU Lesser General Public |
// | License as published by the Free Software Foundation; either |
// | version 2.1 of the License, or (at your option) any later version. |
// +--------------------------------------------------------------------+
//
/**
* Sourdough PHP Application Framework
* @package sourdough
* @subpackage fileconvert
*/
/**
* SOURDOUGH Shared Library
*
* This class handles basic syntax conversion on text files.
* The main conversion is done in convert() which much get implemented
* in each subclass.
*
* @package sourdough
* @subpackage fileconvert
* @author Philip Iezzi <hide@address.com>
* @copyright Copyright (c) 2001-2007 PHPEE.COM
* @license http://opensource.org/licenses/lgpl-license.php GNU Lesser General Public License
* @version $Id: Sd_FileConvert.class.php 3003 2007-12-08 11:05:17Z piezzi $
*/
abstract class Sd_FileConvert {
//[start] Local Variables
/**
* source filename
*
* @var string $filename
*/
protected $filename = '';
/**
* Target file extension
*
* @var string $fileExtension
*/
protected $fileExtension = '';
/**
* source content
*
* @var string $contSource
*/
protected $contSource = '';
/**
* target content
*
* @var string $contTarget
*/
protected $contTarget = '';
//[end]
//[start] Public Methods
/**
* Get the content of a file.
*
* @param string $filename
*/
public function load($filename)
{
if(is_file($filename)) {
$this->filename = $filename;
$this->contSource = Sd_File::getContent($this->filename);
} else {
return false;
}
}
/**
* Run PHP2JAVA syntax conversion.
*
* @return void
*/
public abstract function convert();
/**
* Get original source content
*
* @return string
*/
public function getSourceContent()
{
return $this->contSource;
}
/**
* Get converted target content
*
* @return string
*/
public function getTargetContent()
{
return $this->contTarget;
}
/**
* Write converted output to the new file
*
* @param boolean force file write even if file has not been changed
* @return boolean true on successful file write
*/
public function writeFile($force = false)
{
if($force || $this->contTarget != $this->contSource) {
return Sd_File::writeFile($this->convertFilename(), $this->contTarget);
}
return false;
}
/**
* Set the new file extension
*
* @param string $sExt extension
* @return void
*/
public function changeExtension($sExt)
{
$this->fileExtension = $sExt;
}
//[end]
//[start] Protected/Private Methods
/**
* Get the target filename.
*
* @return string original filename converted to the new filename
*/
protected function convertFilename()
{
if($this->fileExtension !== '') {
return eregi_replace("(.*)\.[a-z0-9]*$",
"\\1.".$this->fileExtension, $this->filename);
} else {
return $this->filename;
}
}
//[end]
}
?>