This file is indexed.

/usr/share/php/pkgtools/base/dependency.php is in pkg-php-tools 1.28.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
<?php
/*
 * Copyright (c) 2014 Mathieu Parent <sathieu@debian.org>
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 */

namespace Pkgtools\Base;

/**
* This class represents a dependency
*
* @copyright Copyright (c) 2014 Mathieu Parent <sathieu@debian.org>
* @author Mathieu Parent <sathieu@debian.org>
* @license Expat http://www.jclark.com/xml/copying.txt
*/
class Dependency {

    /**
     * Dependency level
     * One of:
     * - require
     * - require-dev
     * - recommend
     * - suggest
     * - conflict
     * - provide
     * - replace
     *
     * @var string
     */
    private $_level = NULL;

    /**
     * Package project
     * (Composer terminology)
     * Use an empty string for platform packages
     *
     * @var string
     */
    private $_project = NULL;

    /**
     * Package name
     *
     * @var string
     */
    private $_package = NULL;

    /**
     * Minimum version
     *
     * @var string
     */
    private $_minVersion = NULL;

    /**
     * Exclude minimum version
     * If true : $vers > $minVersion
     * If false: $vers >= $minVersion
     *
     * @var bool
     */
    private $_excludeMinVersion = false;

    /**
     * Maximum version
     *
     * @var string
     */
    private $_maxVersion = NULL;

    /**
     * Exclude maximum version
     * If true : $vers < $maxVersion
     * If false: $vers <= $maxVersion
     *
     * @var bool
     */
    private $_excludeMaxVersion = true;

    /**
     * Original (before override) dependency
     *
     * @var Dependency|NULL
     */
    private $_original = true;

    /**
     * Constructor
     *
     * @param string $level
     * @param string $project
     * @param string $package
     * @param string $minVersion
     * @param string $maxVersion
     * @param Dependency $original Original (before override) dependency
     */
    final public function __construct($level, $project, $package, $minVersion = NULL, $maxVersion = NULL, $original = NULL) {
        $this->level = $level;
        $this->project = $project;
        $this->package = $package;
        $this->minVersion = $minVersion;
        $this->maxVersion = $maxVersion;
        $this->original = $original;
    }

    /**
     * As string
     */
    final public function __toString() {
        $min = false;
        if ($this->minVersion) {
            if ($this->excludeMinVersion) {
                $min = '> '.$this->minVersion;
            } else {
                $min = '>= '.$this->minVersion;
            }
        }
        $max = false;
        if ($this->maxVersion) {
            if ($this->excludeMaxVersion) {
                $max = '< '.$this->maxVersion;
            } else {
                $max = '<= '.$this->maxVersion;
            }
        }
        if ($min && $max) {
            $version = " ($min, $max)";
        } elseif ($min) {
            $version = " ($min)";
        } elseif ($max) {
            $version = " ($max)";
        } else {
            $version = '';
        }
        return sprintf("%s:%s/%s%s", $this->level, $this->project, $this->package, $version);
    }

    /**
     * Raw properties getter
     *
     * @param string $property
     */
    function __get($property) {
        switch($property) {
            case 'level':
            case 'project':
            case 'package':
            case 'minVersion':
            case 'excludeMinVersion':
            case 'maxVersion':
            case 'excludeMaxVersion':
            case 'original':
                return $this->{"_$property"};
            default:
                throw new \InvalidArgumentException("Unknown property: '$property'");
        }
    }

    /**
     * Raw properties setter
     *
     * @param string $property
     * @param mixed $value
     */
    function __set($property, $value) {
        switch($property) {
            case 'level':
                if (!in_array($value, Array('require', 'require-dev', 'recommend', 'suggest', 'conflict', 'provide', 'replace'))) {
                    throw new \InvalidArgumentException("Unknown dependency level: '$value'");
                }
                break;
            case 'project':
                if (!preg_match('/^[a-zA-Z0-9_.-]*$/', $value)) {
                    throw new \InvalidArgumentException("Malformed dependency $property: '$value'");
                }
                // Prevent misuse
                if ($value == 'pear-extension') {
                    throw new \InvalidArgumentException("Invalid dependency project: $value");
                }
                break;
            case 'package':
                if (!preg_match('/^[a-zA-Z0-9_.-]+$/', $value)) {
                    throw new \InvalidArgumentException("Malformed dependency $property: '$value'");
                }
                // Canonalize PECL extension
                if (substr($value, 0, 4) == 'ext-') {
                    $this->_project = 'pear-pecl.php.net';
                    $this->_package = substr($value, 4);
                    return;
                }
                break;
            case 'minVersion':
            case 'maxVersion':
                if (!is_null($value) && ($value !== 'self.version') && !preg_match('/^[0-9][a-zA-Z0-9_.~-]*$/', $value)) {
                    throw new \InvalidArgumentException("Malformed dependency $property: '$value'");
                }
                break;
            case 'excludeMinVersion':
            case 'excludeMaxVersion':
                if (!is_bool($value)) {
                    throw new \InvalidArgumentException("Malformed dependency $property: '$value'");
                }
                break;
            case 'original':
                if (!is_null($value) && !($value instanceof Dependency)) {
                    throw new \InvalidArgumentException("Malformed dependency $property: '$value'");
                }
                break;
            default:
                throw new \InvalidArgumentException("Unknown property: '$property'");
        }
        $this->{"_$property"} = $value;
    }

    /**
     * Debian package name
     */
    function debName() {
        $prefix = 'php';
        $project =  $this->project;
        $package = strtolower($this->package);
        // Builtin or none overrides
        if (($project == '__override__') && (in_array($package, Array('builtin', 'none')))) {
            return NULL;
        }
        // Generic overrides
        if ($project == '__override__') {
            return $package;
        }
        // PHP
        if (($project == '') && ($package == 'php')) {
            return 'php5-common';
        }
        if (($project == '') && ($package == 'php-cli')) {
            return 'php5-cli';
        }
        // lib-*
        if (($project == '') && substr($package, 0, 4) == 'lib-') {
            $lib = substr($package, 4);
            switch($lib) {
                case 'curl':
                    return 'libcurl3';
                case 'iconv':
                    // static lib
                    return NULL;
                case 'icu':
                    return 'libicu52';
                case 'libxml':
                    return 'libxml2';
                case 'openssl':
                    return 'libssl1.0.0';
                case 'pcre':
                    return 'libpcre3'; // FIXME: epoch=1
                case 'uuid':
                    // static lib
                    return NULL;
                case 'xsl':
                    return 'libxslt1.1';
                default:
                    Logger::info('Unknown dependency: "%s".', $package);
                    return NULL;
            }
        }
        // PEAR package
        if (substr($project, 0, 5) == 'pear-') {
            $channel_url = substr($project, 5);
            if ($channel_url === 'pecl.php.net') {
                $prefix = 'php5';
            }
            // Split channel url by dots
            $channel_components = explode(".", $channel_url);
            // Split package name by underscores
            $package_components = explode('_', $package);
            // Drop last part of url (TLD):
            array_pop($channel_components);
            // Drop first part of url if equal to pear, pecl or www
            if (isset($channel_components[0]) && in_array($channel_components[0], Array('pear', 'pecl', 'www'))) {
                array_shift($channel_components);
            }
            // Drop first part of url if equal to php
            if (isset($channel_components[0]) && ($channel_components[0] == 'php')) {
                array_shift($channel_components);
            }
            // Drop first part of package if equal to last part of url
            if (end($channel_components) == $package_components[0]) {
                array_shift($package_components);
            }
            // PEAR: Build the debian name from remaining components
            return implode('-', array_merge(Array($prefix), $channel_components, $package_components));
        }
        // Return package name if package name begins with project name
        if (strpos($package, $project) === 0) {
            return "$prefix-$package";
        }
        // Split project name by hyphen
        $project_components = explode('-', $project);
        // Split package name by hyphen
        $package_components = explode('-', $package);
        // Drop first part of package if equal to last part of url
        if (end($project_components) == $package_components[0]) {
            array_shift($package_components);
        }
        // Composer: Build the debian name from remaining components
        return implode('-', array_merge(Array($prefix), $project_components, $package_components));
    }

    /**
     * Debian version
     */
    static function toDebVersion($version) {
        if ($version == 'self.version') {
            return '${binary:Version}';
        }
        return $version;
    }

    /**
     * Dependency as deb format
     */
    function debDependency() {
        $name = $this->debName();
        if (is_null($name)) {
            return NULL;
        }
        if (!$this->minVersion && !$this->maxVersion) {
            return $name;
        }
        if ($this->minVersion == $this->maxVersion) {
            return $name.' (= '.$this::toDebVersion($this->minVersion).')';
        }
        $min = false;
        if ($this->minVersion) {
            if ($this->excludeMinVersion) {
                $min = $name.' (>> '.$this::toDebVersion($this->minVersion).')';
            } else {
                $min = $name.' (>= '.$this::toDebVersion($this->minVersion).')';
            }
        }
        $max = false;
        if ($this->maxVersion) {
            if ($this->excludeMaxVersion) {
                $max = $name.' (<< '.$this::toDebVersion($this->maxVersion).')';
            } else {
                $max = $name.' (<= '.$this::toDebVersion($this->maxVersion).')';
            }
        }
        if ($min && $max) {
            return "$min, $max";
        }
        if ($min) {
            return $min;
        }
        if ($max) {
            return $max;
        }

    }
}