/** * Initialize configuration. * * @param mixed $config Configuration or configuration filename. * @param string $className Class name. * @param string $moduleName Module name. * @return ComponentConfig * * @throws SystemException 'ERR_DEV_BAD_CONFIG_FILE' * @throws SystemException 'ERR_DEV_STRANGE' */ public function __construct($config, $className, $moduleName) { //Если это строка(с именем файла) или false if (!$config || is_string($config)) { $config = ($param = $this->getConfigPath($config, $moduleName)) ? $param : $this->getConfigPath(simplifyClassName($className) . '.component.xml', $moduleName); //search in parents classes configs if (!$config) { foreach (class_parents($className) as $tClass) { list(, $pModuleName, , $pClassName) = explode('\\', $tClass); if (in_array($pClassName, ['DBDataSet', 'DataSet', 'Component'])) { break; } if ($config = $this->getConfigPath(simplifyClassName($pClassName) . '.component.xml', $pModuleName)) { break; } } } if ($config) { try { $this->config = simplexml_load_file($config); } catch (\Exception $e) { throw new SystemException('ERR_DEV_BAD_CONFIG_FILE', SystemException::ERR_DEVELOPER, $config); } } } elseif (is_a($config, 'SimpleXMLElement')) { $this->config = $config; } else { //Этого не может быть throw new SystemException('ERR_DEV_STRANGE', SystemException::ERR_DEVELOPER, func_get_args()); //поскольку быть этого не может никогда } }
/** * @return \DOMDocument|\DOMElement */ public function build() { $result = $this->doc->createElement('component'); $result->setAttribute('name', $this->getName()); $result->setAttribute('componentAction', $this->getState()); $result->setAttribute('class', simplifyClassName(get_class($this))); foreach ($this->properties as $propName => $propValue) { $result->setAttribute($propName, $propValue); } /* * Существует ли построитель и правильно ли он отработал? * Построитель может не существовать, если мы создаем компонент в котором нет данных. */ if ($this->getBuilder() && $this->getBuilder()->build()) { $builderResult = $this->getBuilder()->getResult(); if ($builderResult instanceof \DOMNode) { $result->appendChild($this->doc->importNode($builderResult, true)); } elseif ($builderResult instanceof \DOMNodeList) { foreach ($builderResult as $node) { $result->appendChild($this->doc->importNode($node, true)); } } else { $el = $this->doc->createElement('result', $builderResult); $el->setAttribute('xml:id', 'result'); $result->appendChild($el); } } $this->doc->appendChild($result); $result = $this->doc; return $result; }
/** * @copydoc DBDataSet::defineParams */ protected function defineParams() { $params = []; if (!$this->params['config']) { $fileName = simplifyClassName(get_class($this)) . '.component.xml'; $fileConf = sprintf(SITE_DIR . ComponentConfig::SITE_CONFIG_DIR, E()->getSiteManager()->getCurrentSite()->folder) . $fileName; $coreConf = sprintf(CORE_DIR . ComponentConfig::CORE_CONFIG_DIR, $this->module) . $fileName; if (file_exists($fileConf)) { $params['config'] = $fileConf; } elseif (file_exists($coreConf)) { $params['config'] = $coreConf; } else { $params['config'] = sprintf(CORE_DIR . ComponentConfig::CORE_CONFIG_DIR, 'share') . 'Grid.component.xml'; } } $params['active'] = true; $params['thumbnail'] = [$this->getConfigValue('thumbnail.width'), $this->getConfigValue('thumbnail.height')]; $params['order'] = false; return array_merge(parent::defineParams(), $params); }