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