cvs: pear-core /PEAR/PackageFile/v2 rw.php /PEAR/Task/Postinstallscript rw.php /PEAR/Task/Replace rw.php

From: Date: Wed, 06 Apr 2005 01:38:18 +0000
Subject: cvs: pear-core /PEAR/PackageFile/v2 rw.php /PEAR/Task/Postinstallscript rw.php /PEAR/Task/Replace rw.php
Groups: php.pear.cvs php.pear.core 
Request: Send a blank email to pear-cvs+get-30950@lists.php.net to get a copy of this message
cellog Tue Apr 5 21:38:18 2005 EDT Added files: /pear-core/PEAR/Task/Postinstallscript rw.php /pear-core/PEAR/Task/Replace rw.php Modified files: /pear-core/PEAR/PackageFile/v2 rw.php Log: add support for abstracted writeable file tasks (necessary for automated package.xml generation tools)

http://cvs.php.net/diff.php/pear-core/PEAR/PackageFile/v2/rw.php?r1=1.1&r2=1.2&ty=u Index: pear-core/PEAR/PackageFile/v2/rw.php diff -u pear-core/PEAR/PackageFile/v2/rw.php:1.1 pear-core/PEAR/PackageFile/v2/rw.php:1.2 --- pear-core/PEAR/PackageFile/v2/rw.php:1.1 Thu Mar 24 22:50:34 2005 +++ pear-core/PEAR/PackageFile/v2/rw.php Tue Apr 5 21:38:18 2005 @@ -15,7 +15,7 @@ * @author Greg Beaver <cellog@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: rw.php,v 1.1 2005/03/25 03:50:34 cellog Exp $ + * @version CVS: $Id: rw.php,v 1.2 2005/04/06 01:38:18 cellog Exp $ * @link http://pear.php.net/package/PEAR * @since File available since Release 1.4.0a8 */ @@ -457,6 +457,70 @@ } /** + * @param string file name + * @param PEAR_Task_Common a read/write task + */ + function addTaskToFile($file, $task) + { + if (!method_exists($task, 'getXml')) { + return false; + } + if (!method_exists($task, 'getName')) { + return false; + } + if (!method_exists($task, 'validate')) { + return false; + } + if (!$task->validate()) { + return false; + } + if (!isset($this->_packageInfo['contents']['dir']['file'])) { + return false; + } + $files = $this->_packageInfo['contents']['dir']['file']; + if (!isset($files[0])) { + $files = array($files); + $ind = false; + } else { + $ind = true; + } + foreach ($files as $i => $file) { + if (isset($file['attribs'])) { + if ($file['attribs']['name'] == $filename) { + if ($ind) { + $t = isset($this->_packageInfo['contents']['dir']['file'][$i] + ['attribs'][$this->_tasksNs . + ':' . $task->getName()]) ? + $this->_packageInfo['contents']['dir']['file'][$i] + ['attribs'][$this->_tasksNs . + ':' . $task->getName()] : false; + if ($t && !isset($t[0])) { + $this->_packageInfo['contents']['dir']['file'][$i] + [$this->_tasksNs . ':' . $task->getName()] = array($t); + } + $this->_packageInfo['contents']['dir']['file'][$i][$this->_tasksNs . + ':' . $task->getName()][] = $task->getXml(); + } else { + $t = isset($this->_packageInfo['contents']['dir']['file'] + ['attribs'][$this->_tasksNs . + ':' . $task->getName()]) ? $this->_packageInfo['contents']['dir']['file'] + ['attribs'][$this->_tasksNs . + ':' . $task->getName()] : false; + if ($t && !isset($t[0])) { + $this->_packageInfo['contents']['dir']['file'] + [$this->_tasksNs . ':' . $task->getName()] = array($t); + } + $this->_packageInfo['contents']['dir']['file'][$this->_tasksNs . + ':' . $task->getName()][] = $task->getXml(); + } + return true; + } + } + } + return false; + } + + /** * @param string path to the file * @param string filename * @param array extra attributes http://cvs.php.net/co.php/pear-core/PEAR/Task/Postinstallscript/rw.php?r=1.1&p=1 Index: pear-core/PEAR/Task/Postinstallscript/rw.php +++ pear-core/PEAR/Task/Postinstallscript/rw.php <?php /** * <tasks:postinstallscript> - read/write version * * PHP versions 4 and 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category pear * @package PEAR * @author Greg Beaver <cellog@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version CVS: $Id: rw.php,v 1.1 2005/04/06 01:38:18 cellog Exp $ * @link http://pear.php.net/package/PEAR * @since File available since Release 1.4.0a10 */ /** * Base class */ require_once 'PEAR/Task/Postinstallscript.php'; /** * Abstracts the postinstallscript file task xml. * @category pear * @package PEAR * @author Greg Beaver <cellog@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/PEAR * @since Class available since Release 1.4.0a10 */ class PEAR_Task_Postinstallscript_rw extends PEAR_Task_Postinstallscript { function PEAR_Task_Postinstallscript_rw(&$pkg, &$config, &$logger, $fileXml) { parent::PEAR_Task_Common($config, $logger, PEAR_TASK_PACKAGE); $this->_contents = $fileXml; $this->_pkg = &$pkg; $this->_params = array(); } function validate() { return $this->validateXml($this->_pkg, $this->_params, $this->config, $this->_contents); } function addParamGroup($id, $params) { if (isset($params[0]) && !isset($params[1])) { $params = $params[0]; } $this->_params[] = array( 'id' => $id, 'param' => $params, ); } function addConditionTypeGroup($id, $oldgroup, $param, $value, $conditiontype = '=') { if (isset($params[0]) && !isset($params[1])) { $params = $params[0]; } $this->_params[] = array( 'id' => $id, 'name' => $oldgroup . '::' . $param, 'conditiontype' => $conditiontype, 'value' => $value, 'param' => $params, ); } function getXml() { return $this->_params; } /** * Use to set up a param tag for use in creating a paramgroup * @static */ function getParam($name, $prompt, $type = 'string', $default = null) { if ($default !== null) { return array( 'name' => $name, 'prompt' => $prompt, 'type' => $type, 'default' => $default ); } return array( 'name' => $name, 'prompt' => $prompt, 'type' => $type, ); } } ?> http://cvs.php.net/co.php/pear-core/PEAR/Task/Replace/rw.php?r=1.1&p=1 Index: pear-core/PEAR/Task/Replace/rw.php +++ pear-core/PEAR/Task/Replace/rw.php <?php /** * <tasks:replace> - read/write version * * PHP versions 4 and 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category pear * @package PEAR * @author Greg Beaver <cellog@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version CVS: $Id: rw.php,v 1.1 2005/04/06 01:38:18 cellog Exp $ * @link http://pear.php.net/package/PEAR * @since File available since Release 1.4.0a10 */ /** * Base class */ require_once 'PEAR/Task/Replace.php'; /** * Abstracts the replace task xml. * @category pear * @package PEAR * @author Greg Beaver <cellog@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/PEAR * @since Class available since Release 1.4.0a10 */ class PEAR_Task_Replace_rw extends PEAR_Task_Replace { function PEAR_Task_Replace_rw(&$pkg, &$config, &$logger, $fileXml) { parent::PEAR_Task_Common($config, $logger, PEAR_TASK_PACKAGE); $this->_contents = $fileXml; $this->_pkg = &$pkg; $this->_params = array(); } function validate() { return $this->validateXml($this->_pkg, $this->_params, $this->config, $this->_contents); } function setInfo($from, $to, $type) { $this->_params = array('attribs' => array('from' => $from, 'to' => $to, 'type' => $type)); } function getXml() { return $this->_params; } } ?>
« previous php.pear.cvs (#30950) next »