https://github.com/PHPOffice/PhpSpreadsheet
столкнулся с проблемой - как ее подключить, она использует неймспейсы.
Пытался их отпарсить
Код: Выделить всё
public static function autoload($class)
{
if( 0 === strpos($class, 'PhpOffice\PhpSpreadsheet') ){
$class = str_replace('PhpOffice\PhpSpreadsheet', '', $class);
$class = ltrim($class, '\\');
$path = __DIR__.'/src/PhpSpreadsheet/'.str_replace('\\', '/', $class).'.php';
if (!file_exists($path)) {
return;
}
require_once $path;
}
elseif( 0 === strpos($class, 'PhpOffice\PhpSpreadsheet\Calculation\Calculation') ){
$class = str_replace('PhpOffice\PhpSpreadsheet\Calculation\Calculation', '', $class);
$class = ltrim($class, '\\');
$path = __DIR__.'/src/PhpSpreadsheet/Calculation/Calculation/'.str_replace('\\', '/', $class).'.php';
if (!file_exists($path)) {
return;
}
require_once $path;
}elseif( 0 === strpos($class, 'PhpOffice\PhpSpreadsheet\Style') ){
$class = str_replace('PhpOffice\PhpSpreadsheet\Style', '', $class);
$class = ltrim($class, '\\');
$path = __DIR__.'src/PhpSpreadsheet/Style/'.str_replace('\\', '/', $class).'.php';
if (!file_exists($path)) {
return;
}
require_once $path;
}
elseif( 0 === strpos($class, 'PhpOffice\PhpSpreadsheet\Worksheet') ) {
$class = str_replace('PhpOffice\PhpSpreadsheet\Worksheet', '', $class);
$class = ltrim($class, '\\');
$path = __DIR__ . 'src/PhpSpreadsheet/Worksheet/' . str_replace('\\', '/', $class) . '.php';
if (!file_exists($path)) {
return;
}
require_once $path;
}
else{
parent::autoload($class);
}
}
/**
* Configure autoloading using Swift Mailer.
*
* This is designed to play nicely with other autoloaders.
*
* @param mixed $callable A valid PHP callable that will be called when autoloading the first Swift class
*/
public static function registerAutoload($callable = null)
{
if (null !== $callable) {
self::$inits[] = $callable;
}
Yii::registerAutoloader(['Spreadsheet','autoload']);
}