Cleanup spl_autoload and use native autoloader (lowercase)

Rename lessphp for default autoloader
This commit is contained in:
djmaze 2020-12-18 21:03:01 +01:00
parent 1cf7344ef5
commit 662eb59d40
4 changed files with 17 additions and 70 deletions

View file

@ -5,34 +5,24 @@ if (!\defined('RAINLOOP_APP_LIBRARIES_PATH'))
\define('RAINLOOP_APP_PATH', \rtrim(\realpath(__DIR__), '\\/').'/');
\define('RAINLOOP_APP_LIBRARIES_PATH', RAINLOOP_APP_PATH.'libraries/');
\define('RAINLOOP_INCLUDE_AS_API_DEF', isset($_ENV['RAINLOOP_INCLUDE_AS_API']) && $_ENV['RAINLOOP_INCLUDE_AS_API']);
function rainLoopSplAutoloadNamespaces() : array
{
return RAINLOOP_INCLUDE_AS_API_DEF ? array('RainLoop', 'Predis', 'MailSo') :
array('RainLoop', 'PHPThumb', 'Predis', 'SabreForRainLoop', 'Imagine', 'MailSo');
}
/**
* @param string $sClassName
*/
function rainLoopSplAutoloadRegisterFunction($sClassName) : void
{
if ($sClassName && '\\' === $sClassName[0])
{
$sClassName = \substr($sClassName, 1);
}
foreach (rainLoopSplAutoloadNamespaces() as $sNamespaceName)
{
if (0 === \strpos($sClassName, $sNamespaceName.'\\'))
{
include RAINLOOP_APP_LIBRARIES_PATH.\strtr($sClassName, '\\', '/').'.php';
break;
}
/** case-sensitive autoload */
$file = \strtr($sClassName, '\\', DIRECTORY_SEPARATOR) . '.php';
// if ($file = \stream_resolve_include_path($file)) {
if (\is_file(RAINLOOP_APP_LIBRARIES_PATH . $file)) {
include_once RAINLOOP_APP_LIBRARIES_PATH . $file;
}
}
if (false === \set_include_path(RAINLOOP_APP_LIBRARIES_PATH . PATH_SEPARATOR . \get_include_path())) {
exit('set_include_path() failed. Probably due to Apache config using php_admin_value instead of php_value');
}
\spl_autoload_extensions('.php');
\spl_autoload_register();
\spl_autoload_register('rainLoopSplAutoloadRegisterFunction');
}
@ -50,7 +40,7 @@ if (\class_exists('RainLoop\Api'))
}
}
if (RAINLOOP_INCLUDE_AS_API_DEF)
if (!empty($_ENV['RAINLOOP_INCLUDE_AS_API']))
{
if (!\defined('APP_API_STARTED'))
{

View file

@ -625,10 +625,7 @@ class ServiceActions
{
try
{
include_once APP_VERSION_ROOT_PATH.'app/libraries/lessphp/ctype.php';
include_once APP_VERSION_ROOT_PATH.'app/libraries/lessphp/lessc.inc.php';
$oLess = new \RainLoopVendor\lessc();
$oLess = new \LessPHP\lessc();
$oLess->setFormatter('compressed');
$aResult = array();

View file

@ -1,40 +0,0 @@
<?php
if (!function_exists('ctype_digit'))
{
function ctype_digit($text)
{
if (is_string($text))
{
if ('' === $text)
{
return false;
}
return !!preg_match('/^[\d]+$/', $text);
}
return false;
}
}
if (!function_exists('ctype_space'))
{
function ctype_space($text)
{
if ('' === $text)
{
return false;
}
return !!preg_match('/^[\s]+$/m', $text);
}
}
if (!function_exists('ctype_alnum'))
{
function ctype_alnum($sVar)
{
return !!preg_match('/^[a-zA-Z0-9]+$/', $sVar);
}
}

View file

@ -1,6 +1,6 @@
<?php
namespace RainLoopVendor;
namespace LessPHP;
class stdClass extends \stdClass {};
class Exception extends \Exception {};
@ -1819,7 +1819,7 @@ class lessc {
$className = "lessc_formatter_$this->formatterName";
}
$className = 'RainLoopVendor\\'.$className;
$className = 'LessPHP\\'.$className;
return new $className;
}
@ -2099,7 +2099,7 @@ class lessc_parser {
if (!self::$operatorString) {
self::$operatorString =
'('.implode('|', array_map(array('RainLoopVendor\\lessc', 'preg_quote'),
'('.implode('|', array_map(array('LessPHP\\lessc', 'preg_quote'),
array_keys(self::$precedence))).')';
$commentSingle = lessc::preg_quote(self::$commentSingle);
@ -2329,7 +2329,7 @@ class lessc_parser {
protected function isDirective($dirname, $directives) {
// TODO: cache pattern in parser
$pattern = implode('|',
array_map(array('RainLoopVendor\\lessc', 'preg_quote'), $directives));
array_map(array('LessPHP\\lessc', 'preg_quote'), $directives));
$pattern = '/^(-[a-z-]+-)?(' . $pattern . ')$/i';
return preg_match($pattern, $dirname);
@ -2617,7 +2617,7 @@ class lessc_parser {
$this->eatWhiteDefault = false;
$stop = array("'", '"', "@{", $end);
$stop = array_map(array('RainLoopVendor\\lessc', 'preg_quote'), $stop);
$stop = array_map(array('LessPHP\\lessc', 'preg_quote'), $stop);
// $stop[] = self::$commentMulti;
if (!is_null($rejectStrs)) {