/usr/share/php/pkgtools/base/overrides.php is in pkg-php-tools 1.32ubuntu2.
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 | <?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;
use \Pkgtools\Base\Logger;
/**
* This class provide package name overrides
*
* @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 Overrides {
/**
* Overrides map
* An array of \Pkgtools\Base\Override, or NULL if uninitialized
*
* @var Array|NULL
*/
private static $_overrides = NULL;
/**
* Constructor
*
* As this class should not be instanciated, this fails
*/
final public function __construct() {
throw new \LogicException(__class__.' could not be instanciated');
}
/**
* Load overrides from files
*
* @param bool $force If true, reload even if already loaded
*/
static public function load($force = FALSE) {
// Already loaded
if (!is_null(self::$_overrides) && !$force) {
return;
}
self::$_overrides = Array();
self::loadFiles();
// Builtin extensions
$builtin_extensions = Array(
// Statically compiled extensions
'calendar', 'core', 'ctype', 'date', 'dba',
'ereg', 'exif', 'fileinfo', 'filter', 'ftp', 'gettext', 'hash',
'iconv', 'libxml', 'openssl', 'pcntl', 'pcre', 'phar', 'posix',
'reflection', 'session', 'shmop', 'sockets',
'spl', 'standard', 'sysvmsg', 'sysvsem', 'sysvshm', 'tokenizer',
'xmlreader', 'xmlwriter', 'zlib',
// Dynamically compiled extensions
'pdo',
// Extensions provided or no longer builtin
//'mhash', 'json',
);
foreach ($builtin_extensions as $builtin_extension) {
self::$_overrides[] = new Override('pear-pecl.php.net', $builtin_extension, 'builtin');
}
}
/**
* Load overrides from one file
*
* @param string $overrides_file File path
*/
static private function loadFile($overrides_file) {
if (file_exists($overrides_file)) {
$fh = fopen($overrides_file, 'r');
if ($fh === false) {
throw new \LogicException("Unable to open '$overrides_file'");
}
while (($line = fgets($fh)) !== false) {
$fields = preg_split("/[\s]+/", $line);
if (count($fields) < 3) {
Logger::warning('Ignoring line, too short: "%s" in file "%s".', $line, $overrides_file);
continue;
}
self::$_overrides[] = new Override('pear-'.$fields[0], $fields[1], $fields[2]);
}
if (!feof($fh)) {
throw new \LogicException("Unable to read '$overrides_file'");
}
fclose($fh);
}
}
/**
* Load overrides from one file
*
* @param string $overrides_file File path
*/
static private function loadFiles() {
self::loadFile('debian/pkg-php-tools-overrides');
// /usr/share/pkg-php-tools/overrides
$overrides_dir = dirname(dirname(dirname(dirname(__FILE__)))) . '/pkg-php-tools/overrides';
if (is_dir($overrides_dir)) {
if ($dh = opendir($overrides_dir)) {
while (($file = readdir($dh)) !== false) {
if (($file == '.') || ($file == '..')) {
continue;
}
self::loadFile($overrides_dir.'/'.$file);
}
closedir($dh);
} else {
throw new \LogicException("Unable to open '$overrides_dir'");
}
}
}
/**
* Apply an override
* Return:
* - NULL if no override found
* - a Dependency object
*
* @param Dependency $dependency
* @return Dependency|NULL
*/
function override($dependency) {
self::load();
foreach(self::$_overrides as $override) {
$overriden = $override->override($dependency);
if (!is_null($overriden)) {
//printLog("Overriding: $dependency -> $overriden");
return $overriden;
}
}
return NULL;
}
}
|