function loadFromArray($array, $ignore = array()) { $sql = "--outputting sql\n"; $sql .= "BEGIN;\n"; foreach ($array as $data) { if (!in_array($data['type'], $ignore)) { $component_name = ComponentFactory::Factory($data['type']); $component = call_user_func(array($component_name, 'Factory'), $data); $sql .= $component->toSQL(); } else { } } $sql .= 'COMMIT;'; return $sql; }
/** * Internal function to lookup the saved data for a given component based on its name. * * Will return null if it doesn't exist or an array. * * @param string $componentname The name of the component to lookup * * @return array | null */ public static function _LookupComponentData($componentname) { if (self::$_DBCache === null) { self::$_DBCache = array(); // Try to load the components try { $res = Core\Datamodel\Dataset::Init()->table('component')->select('*')->execute(); } // But since this function is called during the installer, it might fail... that's acceptable. catch (DMI_Exception $e) { return false; } foreach ($res as $r) { $n = strtolower($r['name']); self::$_DBCache[$n] = $r; } } $componentname = strtolower($componentname); return (isset(self::$_DBCache[$componentname])) ? self::$_DBCache[$componentname] : null; }
public function load() { if ($this->_loaded) { return; } $this->_name = $this->_xmlloader->getRootDOM()->getAttribute('name'); $this->_version = $this->_xmlloader->getRootDOM()->getAttribute("version"); // Load the database information, if there is any. $dat = \ComponentFactory::_LookupComponentData('theme/' . $this->_name); if (!$dat) { return; } $this->_versionDB = $dat['version']; $this->_enabled = $dat['enabled'] ? true : false; if (DEVELOPMENT_MODE && defined('AUTO_INSTALL_ASSETS') && AUTO_INSTALL_ASSETS && EXEC_MODE == 'WEB' && CDN_TYPE == 'local' && $this->getKeyName() == \ConfigHandler::Get('/theme/selected')) { \Core\Utilities\Logger\write_debug('Auto-installing assets for theme [' . $this->getName() . ']'); $this->_parseAssets(); } $this->_loaded = true; }
function __construct(ComponentFactory $c) { $this->componentFactory = $c; $c->accept($this); }
/** * Load all the components in the system, replacement for the Core. * @throws CoreException */ private function _loadComponents() { // cannot reload components. if ($this->_components) return null; $this->_components = array(); $this->_libraries = array(); $tempcomponents = false; Core\Utilities\Logger\write_debug('Starting loading of component metadata'); // If the site is in DEVELOPMENT mode, component caching would probably be a bad idea; ie: the developer probably wants // those component files loaded everytime. if(DEVELOPMENT_MODE){ $enablecache = false; } else{ $enablecache = true; } // Is there a cache of elements available? This is a primary system cache that greatly increases performance, // since it will no longer have to run through each component.xml file to register each one. if($enablecache){ Core\Utilities\Logger\write_debug('Checking core-components cache'); // Try to load up the cached components and check them first. $tempcomponents = \Core\Cache::Get('core-components', (3600 * 24)); if($tempcomponents !== false){ // Cached components only need to be loaded. foreach ($tempcomponents as $c) { try { $c->load(); } catch (Exception $e) { // Don't completely bail out here, just invalidate the cache and continue on. \Core\Cache::Delete('core-components'); $tempcomponents = false; } } } } if(!$enablecache || $tempcomponents == false){ \Core\Utilities\Profiler\Profiler::GetDefaultProfiler()->record('Scanning for component.xml files manually'); Core\Utilities\Logger\write_debug('Scanning for component.xml files manually'); // Core is first, (obviously) $tempcomponents['core'] = ComponentFactory::Load(ROOT_PDIR . 'core/component.xml'); Core\Utilities\Logger\write_debug('Core component loaded'); // First, build my cache of components, regardless if the component is installed or not. $dh = opendir(ROOT_PDIR . 'components'); if (!$dh) throw new CoreException('Unable to open directory [' . ROOT_PDIR . 'components/] for reading.'); // This will read through every directory in 'components', which is // where all components in the system are installed to. while (($file = readdir($dh)) !== false) { // skip hidden directories. if ($file{0} == '.') continue; // skip non-directories if (!is_dir(ROOT_PDIR . 'components/' . $file)) continue; // Skip directories that do not have a readable component.xml file. if (!is_readable(ROOT_PDIR . 'components/' . $file . '/component.xml')) continue; //Core\Utilities\Logger\write_debug(' * Loading component ' . $file); $c = ComponentFactory::Load(ROOT_PDIR . 'components/' . $file . '/component.xml'); Core\Utilities\Logger\write_debug('Opened component ' . $file); // All further operations are case insensitive. // The original call to Component needs to be case sensitive because it sets the filename to pull. $file = strtolower($file); // If the component was flagged as invalid.. just skip to the next one. if (!$c->isValid()) { if (DEVELOPMENT_MODE) { \Core\set_message('Component ' . $c->getName() . ' appears to be invalid.'); } continue; } $tempcomponents[$file] = $c; unset($c); } closedir($dh); \Core\Utilities\Profiler\Profiler::GetDefaultProfiler()->record('Component XML files scanned'); // Now I probably could actually load the components! foreach ($tempcomponents as $c) { /** @var Component_2_1 $c */ try { // Load some of the data in the class so that it's available in the cached version. // This is because the component 2.1 has built-in caching for many of the XML requests. // by calling them once, that lookup data is cached in that component, which in turn gets // copied to the cache version here! $c->load(); $c->getClassList(); $c->getViewSearchDir(); $c->getSmartyPluginDirectory(); $c->getWidgetList(); } catch (Exception $e) { var_dump($e); die(); } } // Cache this list! if($enablecache){ Core\Utilities\Logger\write_debug(' * Caching core-components for next pass'); \Core\Cache::Set('core-components', $tempcomponents, (3600 * 24)); } } $list = $tempcomponents; \Core\Utilities\Profiler\Profiler::GetDefaultProfiler()->record('Component metadata loaded, starting registration'); Core\Utilities\Logger\write_debug(' * Component metadata loaded, starting registration'); // The core component at a minimum needs to be loaded and registered. // $this->_registerComponent($list['core']); // $this->_components['core']->loadFiles(); // unset($list['core']); // Now that I have a list of components available, copy them into a list of // components that are installed. do { $size = sizeof($list); foreach ($list as $n => $c) { /** @var $c Component_2_1 */ // Disabled components don't get recognized. if($c->isInstalled() && !$c->isEnabled()){ // But they do get sent to the disabled list! $this->_componentsDisabled[$n] = $c; unset($list[$n]); continue; } // Clear out the temporary class list $this->_tmpclasses = []; // If it's loaded, register it and remove it from the list! if ($c->isInstalled() && $c->isLoadable() && $c->loadFiles()) { try{ // Allow for on-the-fly package upgrading regardless of DEV mode or not. if ($c->needsUpdated()) { // Load this component's classes in case an upgrade operation requires one. // This allows a component to be loaded partially without completely being loaded. $this->_tmpclasses = $c->getClassList(); // Lock the site first! // This is because some upgrade procedures take a long time to upgrade. file_put_contents(TMP_DIR . 'lock.message', 'Core Plus is being upgraded, please try again in a minute. '); $c->upgrade(); unlink(TMP_DIR . 'lock.message'); } } catch(Exception $e){ SystemLogModel::LogErrorEvent('/core/component/failedupgrade', 'Ignoring component [' . $n . '] due to an error during upgrading!', $e->getMessage()); unlink(TMP_DIR . 'lock.message'); //$c->disable(); $this->_componentsDisabled[$n] = $c; unset($list[$n]); continue; } try{ $this->_components[$n] = $c; $this->_registerComponent($c); $c->loadSupplementalModels(); } catch(Exception $e){ SystemLogModel::LogErrorEvent('/core/component/failedregister', 'Ignoring component [' . $n . '] due to an error during registration!', $e->getMessage()); //$c->disable(); $this->_componentsDisabled[$n] = $c; unset($list[$n]); continue; } unset($list[$n]); continue; } // Allow for on-the-fly package upgrading regardless of DEV mode or not. // Guess this is needed for the loadFiles part... if ($c->isInstalled() && $c->needsUpdated() && $c->isLoadable()) { // Lock the site first! // This is because some upgrade procedures take a long time to upgrade. file_put_contents(TMP_DIR . 'lock.message', 'Core Plus is being upgraded, please try again in a minute. '); $c->upgrade(); $c->loadFiles(); $this->_components[$n] = $c; $this->_registerComponent($c); unlink(TMP_DIR . 'lock.message'); unset($list[$n]); continue; } // Allow packages to be auto-installed if in DEV mode. // If DEV mode is not enabled, just install the new component, do not enable it. if (!$c->isInstalled() && $c->isLoadable()) { // Load this component's classes in case an install operation requires one. // This allows a component to be loaded partially without completely being loaded. $this->_tmpclasses = $c->getClassList(); // w00t $c->install(); // BLAH, until I fix the disabled-packages-not-viewable bug... $c->enable(); $c->loadFiles(); $this->_components[$n] = $c; $this->_registerComponent($c); /* if(!DEVELOPMENT_MODE){ $c->disable(); } else{ $c->enable(); $c->loadFiles(); $this->_components[$n] = $c; $this->_registerComponent($c); } */ unset($list[$n]); continue; } } } while ($size > 0 && ($size != sizeof($list))); // If dev mode is enabled, display a list of components installed but not loadable. foreach ($list as $n => $c) { //$this->_components[$n] = $c; $this->_componentsDisabled[$n] = $c; // Ignore anything with the execmode different, those should be minor notices for debugging if anything. if ($c->error & Component_2_1::ERROR_WRONGEXECMODE) continue; if (DEVELOPMENT_MODE) { SystemLogModel::LogErrorEvent('/core/component/missingrequirement', 'Could not load installed component ' . $n . ' due to requirement failed.', $c->getErrors()); } } // Don't forget to load the themes too! if(class_exists('ThemeHandler')){ foreach(ThemeHandler::GetAllThemes() as $theme){ /** @var $theme Theme */ $theme->load(); } } // Lastly, make sure that the template path cache is updated! if(class_exists('\\Core\\Templates\\Template')){ \Core\Templates\Template::RequeryPaths(); } }
$content = $factory->createComponent('content_container'); $layout->setContentContainer($content); $layout->setTopMenu($topMenu); $layout->display(); /** На выходе получим: [layout] [top_menu]It's a top menu[/top_menu] [content]Content[/content] [/layout] */ /** * Пример 2. Используем дополнительные настройки фабрики. */ $factory = new ComponentFactory($g_defaultComponentSettings, $g_componentSettings); $layout = $factory->createComponent('layout'); $topMenu = $factory->createComponent('top_menu'); $content = $factory->createComponent('content_container'); $layout->setContentContainer($content); $layout->setTopMenu($topMenu); $layout->display(); /** На выходе получим: [layout] [decorated_top_menu] [top_menu]It's a top menu[/top_menu] [/decorated_top_menu] [content]Content[/content] [/layout]
public function set($componentID, $component, $external = false) { parent::set($componentID, $component, true); }
private function _setupCore(){ $this->_xmlFile = \ComponentFactory::ResolveNameToFile($this->_keyname); if(!$this->_xmlFile){ throw new \Exception('XML file for Core not found??? [' . $this->_keyname . ']'); } $this->_base = new DirectoryLocal(ROOT_PDIR); $this->_iterator = new DirectoryIterator($this->_base); // Get the XMLLoader object for this file. This will allow me to have more fine-tune control over the file. $this->_xmlLoader = new \XMLLoader(); $this->_xmlLoader->setRootName('component'); if(!$this->_xmlLoader->loadFromFile($this->_xmlFile)){ throw new \Exception('Unable to load XML file ' . $this->_xmlFile); } $this->_iterator->findDirectories = false; $this->_iterator->recursive = true; $this->_iterator->ignores = [ 'core/component.xml', 'components/', 'config/configuration.xml', 'dropins/', 'exports/', 'nbproject/', '.idea/', 'themes/', '.htaccess', 'gnupg', 'core/bootstrap.compiled.php', 'logs/', 'core/dev/', 'core/tests/', ]; if(CDN_LOCAL_ASSETDIR) $this->_iterator->ignores[] = CDN_LOCAL_ASSETDIR; if(CDN_LOCAL_PUBLICDIR) $this->_iterator->ignores[] = CDN_LOCAL_PUBLICDIR; if(CDN_LOCAL_PRIVATEDIR) $this->_iterator->ignores[] = CDN_LOCAL_PRIVATEDIR; if(strpos(TMP_DIR_WEB, ROOT_PDIR) === 0) $this->_iterator->ignores[] = TMP_DIR_WEB; if(strpos(TMP_DIR_CLI, ROOT_PDIR) === 0) $this->_iterator->ignores[] = TMP_DIR_CLI; $this->_name = 'Core'; $this->_licenses = []; foreach($this->_xmlLoader->getElements('//component/licenses/license') as $el){ /** @var \DOMElement $el */ $url = @$el->getAttribute('url'); $this->_licenses[] = [ 'title' => $el->nodeValue, 'url' => $url ]; } $this->_authors = []; foreach($this->_xmlLoader->getElements('//component/authors/author') as $el){ $this->_authors[] = [ 'name' => $el->getAttribute('name'), 'email' => @$el->getAttribute('email'), ]; } $this->_changelog = new Changelog\Parser('Core Plus', ROOT_PDIR . 'core/CHANGELOG'); $this->_gitPaths = [ ROOT_PDIR . 'config/', ROOT_PDIR . 'core/', ROOT_PDIR . 'install/', ROOT_PDIR . 'utilities/', ROOT_PDIR . 'index.php' ]; }
/** * Load this component's metadata from the XML file. * * Will setup the name, version, installed version (if available), and enabled flag (if available). * * @return void */ public function load() { if ($this->_loaded) return; if (($mode = $this->_xmlloader->getRootDOM()->getAttribute('execmode'))) { $this->_execMode = strtoupper($mode); } $this->_name = $this->_xmlloader->getRootDOM()->getAttribute('name'); $this->_version = $this->_xmlloader->getRootDOM()->getAttribute("version"); Core\Utilities\Logger\write_debug('Loading metadata for component [' . $this->_name . ']'); // Load the database information, if there is any. $dat = ComponentFactory::_LookupComponentData($this->_name); if (!$dat) return; $this->_versionDB = $dat['version']; $this->_enabled = ($dat['enabled']) ? true : false; $this->_loaded = true; // Set the permissions $this->_permissions = array(); foreach($this->_xmlloader->getElements('/permissions/permission') as $el){ /** @var $el DOMElement */ $this->_permissions[$el->getAttribute('key')] = [ 'description' => $el->getAttribute('description'), 'context' => ($el->getAttribute('context')) ? $el->getAttribute('context') : '', ]; } }