/** * Метод получает экземпляр класса и, если нужно, кеширует его. */ public static function getClassInstance($__DIR__, $subDir, $className, $parent, $caching = true) { if (!is_valid_file_name($className)) { return null; //--- } $className = get_file_name($className); if ($className == $parent) { //Абстрактный класс/интерфейс лежит рядом с классами реализации - пропустим его return null; } //Абсолютный путь к классу $classPath = file_path(array($__DIR__, $subDir), $className, PsConst::EXT_PHP); //Ключ кеширования $cacheKey = md5($classPath); $CACHE = $caching ? SimpleDataCache::inst(__CLASS__, __FUNCTION__) : null; if ($CACHE && $CACHE->has($cacheKey)) { return $CACHE->get($cacheKey); } $INST = null; if (is_file($classPath)) { //Подключим данный класс require_once $classPath; //Проверим, существует ли класс $rc = PsUtil::newReflectionClass($className, false); $INST = $rc && $rc->isSubclassOf($parent) ? $rc->newInstance() : null; } if ($CACHE && $INST) { $CACHE->set($cacheKey, $INST); } return $INST; }
protected function __construct() { $this->LOGGER = PsLogger::inst(get_called_class()); $this->CACHE = SimpleDataCache::inst(); }
protected function __construct() { $this->LOGGER = PsLogger::inst(__CLASS__); $this->PROFILER = PsProfiler::inst(__CLASS__); $this->CACHE = SimpleDataCache::inst(); $this->DM = DirManager::autoNoDel(DirManager::DIR_FORMULES); }
public static function getContentProvider($item) { $ident = IdHelper::ident($item); $CACHE = SimpleDataCache::inst(__CLASS__); return $CACHE->has($ident) ? $CACHE->get($ident) : $CACHE->set($ident, self::makeProvider($item)); }
/** * Создание экземпляра класса для сущности фолдинга. * Если по каким-либо причинам экземпляр не может быть создан - выбрасываем ошибку. * * @return FoldedClass */ public final function getEntityClassInst($ident, $cache = true) { /* @var $CACHE SimpleDataCache */ $CACHE = $cache ? SimpleDataCache::inst($this->unique('CLASSES-CACHE')) : null; //--- if ($CACHE && $CACHE->has($ident)) { return $CACHE->get($ident); } $classPath = $this->getClassPath($ident); //Подключим класс, не будем заставлять трудиться класслоадер require_once $classPath; //Построим название класса на основе идентификатора сущности $className = $this->ident2className($ident); if (!PsUtil::isInstanceOf($className, FoldedClass::getCalledClass())) { return PsUtil::raise('Класс для сущности {} не является наследником {}', $this->getTextDescr($ident), FoldedClass::getCalledClass()); } //Получим FoldedEntity, так как её потом нужно будет передать в конструктор $foldedEntity = $this->getFoldedEntity($ident); //Создаём экземпляр $inst = new $className($foldedEntity); //Отлогируем $this->LOGGER->info('Instance of {} created.', $className); FoldedResourcesManager::onEntityAction(FoldedResourcesManager::ACTION_ENTITY_INST_CREATED, $this, $ident); return $CACHE ? $CACHE->set($ident, $inst) : $CACHE; }
protected function __construct() { $this->LOGGER = PsLogger::inst(__CLASS__); $this->PROFILER = PsProfiler::inst(__CLASS__); $this->CACHE = SimpleDataCache::inst(); $this->DM = DirManager::formules(); }