49 lines
1.4 KiB
PHP
49 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace KupShop\AdminBundle\Util;
|
|
|
|
use KupShop\KupShopBundle\Config;
|
|
use KupShop\KupShopBundle\Util\System\PathFinder;
|
|
|
|
class AdminClassLocator
|
|
{
|
|
public function getClassPath($classPath)
|
|
{
|
|
$cfg = Config::get();
|
|
$pathFinder = PathFinder::getService();
|
|
|
|
// look to shop dir
|
|
$fullClassPath = $pathFinder->shopPath($cfg['Path']['admin'].$classPath);
|
|
if (!file_exists($fullClassPath)) {
|
|
// look to bundles admin
|
|
$fullClassPath = loadBundlesAdmin($classPath);
|
|
if (!file_exists($fullClassPath)) {
|
|
// look to engine
|
|
$fullClassPath = $cfg['Path']['shared_version'].'admin/'.$classPath;
|
|
}
|
|
}
|
|
|
|
return $fullClassPath;
|
|
}
|
|
|
|
public function createClass($classPath, $className = null)
|
|
{
|
|
// Nech to tady, je to treba v includnutejch souborech
|
|
global $cfg;
|
|
|
|
$fqcn = include $classPath;
|
|
|
|
if (is_string($fqcn)) {
|
|
$instance = new $fqcn();
|
|
} elseif (!empty($main_class)) {
|
|
$instance = new $main_class();
|
|
} elseif (!empty($className)) {
|
|
$instance = new $className();
|
|
} else {
|
|
throw new \InvalidArgumentException('Add missing return fqcn or define main_class in target file. Alternatively pass className parameter too: '.$classPath);
|
|
}
|
|
|
|
return $instance;
|
|
}
|
|
}
|