Subversion Repositories Applications.gtt

Rev

Rev 94 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
94 jpm 1
<?php
2
/**
3
 * <tasks:windowseol>
4
 *
5
 * PHP versions 4 and 5
6
 *
187 mathias 7
 * @category  pear
8
 * @package   PEAR
9
 * @author    Greg Beaver <cellog@php.net>
10
 * @copyright 1997-2009 The Authors
11
 * @license   http://opensource.org/licenses/bsd-license.php New BSD License
12
 * @link      http://pear.php.net/package/PEAR
13
 * @since     File available since Release 1.4.0a1
94 jpm 14
 */
15
/**
16
 * Base class
17
 */
18
require_once 'PEAR/Task/Common.php';
19
/**
20
 * Implements the windows line endsings file task.
187 mathias 21
 *
22
 * @category  pear
23
 * @package   PEAR
24
 * @author    Greg Beaver <cellog@php.net>
25
 * @copyright 1997-2009 The Authors
26
 * @license   http://opensource.org/licenses/bsd-license.php New BSD License
27
 * @version   Release: 1.10.1
28
 * @link      http://pear.php.net/package/PEAR
29
 * @since     Class available since Release 1.4.0a1
94 jpm 30
 */
31
class PEAR_Task_Windowseol extends PEAR_Task_Common
32
{
187 mathias 33
    public $type = 'simple';
34
    public $phase = PEAR_TASK_PACKAGE;
35
    public $_replacements;
94 jpm 36
 
37
    /**
38
     * Validate the raw xml at parsing-time.
187 mathias 39
     *
40
     * @param  PEAR_PackageFile_v2
41
     * @param  array raw, parsed xml
42
     * @param  PEAR_Config
94 jpm 43
     */
187 mathias 44
    public static function validateXml($pkg, $xml, $config, $fileXml)
94 jpm 45
    {
46
        if ($xml != '') {
47
            return array(PEAR_TASK_ERROR_INVALID, 'no attributes allowed');
48
        }
187 mathias 49
 
94 jpm 50
        return true;
51
    }
52
 
53
    /**
54
     * Initialize a task instance with the parameters
55
     * @param array raw, parsed xml
56
     * @param unused
187 mathias 57
     * @param unused
94 jpm 58
     */
187 mathias 59
    public function init($xml, $attribs, $lastVersion = null)
94 jpm 60
    {
61
    }
62
 
63
    /**
64
     * Replace all line endings with windows line endings
65
     *
66
     * See validateXml() source for the complete list of allowed fields
187 mathias 67
     *
68
     * @param  PEAR_PackageFile_v1|PEAR_PackageFile_v2
69
     * @param  string file contents
70
     * @param  string the eventual final file location (informational only)
94 jpm 71
     * @return string|false|PEAR_Error false to skip this file, PEAR_Error to fail
187 mathias 72
     *                                 (use $this->throwError), otherwise return the new contents
94 jpm 73
     */
187 mathias 74
    public function startSession($pkg, $contents, $dest)
94 jpm 75
    {
76
        $this->logger->log(3, "replacing all line endings with \\r\\n in $dest");
187 mathias 77
 
94 jpm 78
        return preg_replace("/\r\n|\n\r|\r|\n/", "\r\n", $contents);
79
    }
80
}