/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php require_once "phing/Task.php"; /** * Saves currently defined properties into a specified file * * @author Andrei Serdeliuc * @extends Task */ class ExportProperties extends Task { /** * Array of project properties * * (default value: null) * * @var array * @access private */ private $_properties = null; /** * Target file for saved properties * * (default value: null) * * @var string * @access private */ private $_targetFile = null; /** * Exclude properties starting with these prefixes * * @var array * @access private */ 'host.', 'phing.', 'os.', 'php.', 'line.', 'env.', 'user.' ); /** * setter for _targetFile * * @access public * @param string $file * @return bool */ public function setTargetFile($file) { throw new BuildException("Parent directory of target file doesn't exist"); } throw new BuildException("Target file isn't writable"); } $this->_targetFile = $file; return true; } /** * Sets the currently declared properties * * @access public * @return void */ public function init() { $this->_properties = $this->getProject()->getProperties(); } public function main() { $propertiesString = ''; foreach($this->_properties as $propertyName => $propertyValue) { if(!$this->isDisallowedPropery($propertyName)) { $propertiesString .= $propertyName . "=" . $propertyValue . PHP_EOL; } } throw new BuildException('Failed writing to ' . $this->_targetFile); } } } /** * Checks if a property name is disallowed * * @access protected * @param string $propertyName * @return bool */ protected function isDisallowedPropery($propertyName) { foreach($this->_disallowedPropertyPrefixes as $property) { return true; } } return false; } } ?>
URL: http://extraordinaire.me/post/249721396/phing-how-to-export-defined-properties-to-file