2012-04-13 23:45:28 +02:00
|
|
|
<?php
|
2021-10-11 16:10:47 +02:00
|
|
|
|
|
|
|
class Application_Common_OsPath
|
|
|
|
{
|
2012-04-13 23:45:28 +02:00
|
|
|
// this function is from http://stackoverflow.com/questions/2670299/is-there-a-php-equivalent-function-to-the-python-os-path-normpath
|
|
|
|
public static function normpath($path)
|
|
|
|
{
|
2021-10-11 16:10:47 +02:00
|
|
|
if (empty($path)) {
|
2012-04-13 23:45:28 +02:00
|
|
|
return '.';
|
2021-10-11 16:10:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (strpos($path, '/') === 0) {
|
2012-04-13 23:45:28 +02:00
|
|
|
$initial_slashes = true;
|
2021-10-11 16:10:47 +02:00
|
|
|
} else {
|
2012-04-13 23:45:28 +02:00
|
|
|
$initial_slashes = false;
|
2021-10-11 16:10:47 +02:00
|
|
|
}
|
2012-04-13 23:45:28 +02:00
|
|
|
if (
|
2021-10-11 16:10:47 +02:00
|
|
|
($initial_slashes)
|
|
|
|
&& (strpos($path, '//') === 0)
|
|
|
|
&& (strpos($path, '///') === false)
|
|
|
|
) {
|
2012-04-13 23:45:28 +02:00
|
|
|
$initial_slashes = 2;
|
2021-10-11 16:10:47 +02:00
|
|
|
}
|
2012-04-13 23:45:28 +02:00
|
|
|
$initial_slashes = (int) $initial_slashes;
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2012-04-13 23:45:28 +02:00
|
|
|
$comps = explode('/', $path);
|
2021-10-11 16:10:47 +02:00
|
|
|
$new_comps = [];
|
|
|
|
foreach ($comps as $comp) {
|
|
|
|
if (in_array($comp, ['', '.'])) {
|
2012-04-13 23:45:28 +02:00
|
|
|
continue;
|
2021-10-11 16:10:47 +02:00
|
|
|
}
|
2012-04-13 23:45:28 +02:00
|
|
|
if (
|
2021-10-11 16:10:47 +02:00
|
|
|
($comp != '..')
|
|
|
|
|| (!$initial_slashes && !$new_comps)
|
|
|
|
|| ($new_comps && (end($new_comps) == '..'))
|
|
|
|
) {
|
2012-04-13 23:45:28 +02:00
|
|
|
array_push($new_comps, $comp);
|
2021-10-11 16:10:47 +02:00
|
|
|
} elseif ($new_comps) {
|
2012-04-13 23:45:28 +02:00
|
|
|
array_pop($new_comps);
|
2021-10-11 16:10:47 +02:00
|
|
|
}
|
2012-04-13 23:45:28 +02:00
|
|
|
}
|
|
|
|
$comps = $new_comps;
|
|
|
|
$path = implode('/', $comps);
|
2021-10-11 16:10:47 +02:00
|
|
|
if ($initial_slashes) {
|
2012-04-13 23:45:28 +02:00
|
|
|
$path = str_repeat('/', $initial_slashes) . $path;
|
2021-10-11 16:10:47 +02:00
|
|
|
}
|
|
|
|
if ($path) {
|
2012-04-13 23:45:28 +02:00
|
|
|
return $path;
|
2021-10-11 16:10:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return '.';
|
2012-04-13 23:45:28 +02:00
|
|
|
}
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2012-04-24 22:15:22 +02:00
|
|
|
/* Similar to the os.path.join python method
|
|
|
|
* http://stackoverflow.com/a/1782990/276949 */
|
2021-10-11 16:10:47 +02:00
|
|
|
public static function join()
|
|
|
|
{
|
2012-04-24 22:15:22 +02:00
|
|
|
$args = func_get_args();
|
2021-10-11 16:10:47 +02:00
|
|
|
$paths = [];
|
2012-04-24 22:15:22 +02:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
foreach ($args as $arg) {
|
|
|
|
$paths = array_merge($paths, (array) $arg);
|
2012-04-24 22:15:22 +02:00
|
|
|
}
|
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
foreach ($paths as &$path) {
|
2012-04-24 22:15:22 +02:00
|
|
|
$path = trim($path, DIRECTORY_SEPARATOR);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (substr($args[0], 0, 1) == DIRECTORY_SEPARATOR) {
|
|
|
|
$paths[0] = DIRECTORY_SEPARATOR . $paths[0];
|
|
|
|
}
|
|
|
|
|
Feature: Support php7.4 (#1354)
* Run CI tests against php 7.4
* Sort composer dependencies
* Remove unused Aws S3 php library
* Pin simplepie dependency to ^1.5
* Pin getid3 dependency to ^1.9
* Pin composer semver to ^3.2
* Pin php-amqplib to ^2.12
* Drop sentry logging support
* Update composer dependencies
* Move propel regenerate to Makefile
* Regenerate propel files with v1.7.0
* Pin propel orm to ^1.7
* Regenerate propel files with v1.7.2
* fix: generator_version in airtime-conf-production.php
* Replace propel/propel1 with jooola/propel1
* Regenerate propel files with v1.7.3-dev
* Fix php7.4 compatibility
Using php-cs-fixer:
'@PhpCsFixer' => true,
'concat_space' => ['spacing' => 'one'],
'ordered_class_elements' => false,
'yoda_style' => false,
'@PHP74Migration' => true,
'assign_null_coalescing_to_coalesce_equal' => false,
'ternary_to_null_coalescing' => false,
'heredoc_indentation' => false,
'@PHP74Migration:risky' => true,
'declare_strict_types' => false,
'void_return' => false,
'use_arrow_functions' => false,
* Fix pre-commit
2021-10-17 17:19:53 +02:00
|
|
|
return implode(DIRECTORY_SEPARATOR, $paths);
|
2012-04-24 22:15:22 +02:00
|
|
|
}
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2014-10-24 21:11:27 +02:00
|
|
|
public static function formatDirectoryWithDirectorySeparators($dir)
|
|
|
|
{
|
2021-10-11 16:10:47 +02:00
|
|
|
if ($dir[0] != '/') {
|
|
|
|
$dir = '/' . $dir;
|
2014-10-24 21:11:27 +02:00
|
|
|
}
|
2021-10-11 16:10:47 +02:00
|
|
|
|
|
|
|
if ($dir[strlen($dir) - 1] != '/') {
|
|
|
|
$dir = $dir . '/';
|
2014-10-24 21:11:27 +02:00
|
|
|
}
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2014-10-24 21:11:27 +02:00
|
|
|
return $dir;
|
|
|
|
}
|
2012-04-13 23:45:28 +02:00
|
|
|
}
|