public function configElem($config, $el = NULL)
	{
		if (is_scalar($config)) {
			$config = $this->fetchConfig($config);
		}

		// first define which element we want to work with
		if (isset($config[ Cnf::elementName ])) {
			$name = $config[ Cnf::elementName ];
			if (!$el) {
				// element does not exist, so create it
				$el = Html::el($name);
			} else {
				// element exists, but we want to change its name
				$el->setName($name);
			}
		}

		if ($el instanceof Html && $el != NULL) {
			// if el is defined, we can configure it accordingly

			// go through all config and configure element accordingly
			foreach ($config as $key => $value) {
				if (in_array($key, [Cnf::classSet, Cnf::classAdd, Cnf::classAdd, Cnf::classRemove])) {
					// we'll be working with classes, we must standardize everything to arrays, not strings for the sake of sanity
					if (!is_array($value)) {
						// configuration may contain classes as strings, but we always work with arrays
						$value = [$value];
					}

					$origClass = $el->getAttribute('class');
					$newClass = $origClass;
					if ($origClass === NULL) {
						// class is not set
						$newClass = [];
					} elseif (!is_array($origClass)) {
						// class is set, but not a array
						$newClass = explode(' ', $el->getAttribute('class'));
					}
					$el->setAttribute('class', $newClass);
					$origClass = $newClass;
				}

				if ($key == Cnf::classSet) {
					$el->setAttribute('class', $value);
				} elseif ($key == Cnf::classAdd) {
					$el->setAttribute(
						'class',
						array_merge($origClass, $value)
					);
				} elseif ($key == Cnf::classRemove) {
					$el->setAttribute(
						'class',
						array_diff($origClass, $value)
					);
				} elseif ($key == Cnf::attributes) {
					foreach ($value as $attr => $attrVal) {
						$el->setAttribute($attr, $attrVal);
					}
				}
			}
		}

		// el may be null, but maybe it has a container defined
		if (isset($config[ Cnf::container ])) {
			$container = $this->configElem($config[ Cnf::container ], NULL);
			if ($container !== NULL && $el !== NULL) {
				$elClone = clone $el;
				$container->setHtml($elClone);
			}
			$el = $container;
		}

		return $el;
	}
public function configElem($config, $el = NULL)
	{
		if (is_scalar($config)) {
			$config = $this->fetchConfig($config);
		}

		// first define which element we want to work with
		if (isset($config[ Cnf::elementName ])) {
			$name = $config[ Cnf::elementName ];
			if (!$el) {
				// element does not exist, so create it
				$el = Html::el($name);
			} else {
				// element exists, but we want to change its name
				$el->setName($name);
			}
		}

		if ($el instanceof Html && $el != NULL) {
			// if el is defined, we can configure it accordingly

			// go through all config and configure element accordingly
			foreach ($config as $key => $value) {
				if (in_array($key, [Cnf::classSet, Cnf::classAdd, Cnf::classAdd, Cnf::classRemove])) {
					// we'll be working with classes, we must standardize everything to arrays, not strings for the sake of sanity
					if (!is_array($value)) {
						// configuration may contain classes as strings, but we always work with arrays
						$value = [$value];
					}

					$origClass = $el->getAttribute('class');
					$newClass = $origClass;
					if ($origClass === NULL) {
						// class is not set
						$newClass = [];
					} elseif (!is_array($origClass)) {
						// class is set, but not a array
						$newClass = explode(' ', $el->getAttribute('class'));
					}
					$el->setAttribute('class', $newClass);
					$origClass = $newClass;
				}

				if ($key == Cnf::classSet) {
					$el->setAttribute('class', $value);
				} elseif ($key == Cnf::classAdd) {
					$el->setAttribute(
						'class',
						array_merge($origClass, $value)
					);
				} elseif ($key == Cnf::classRemove) {
					$el->setAttribute(
						'class',
						array_diff($origClass, $value)
					);
				} elseif ($key == Cnf::attributes) {
					foreach ($value as $attr => $attrVal) {
						$el->setAttribute($attr, $attrVal);
					}
				}
			}
		}

		// el may be null, but maybe it has a container defined
		if (isset($config[ Cnf::container ])) {
			$container = $this->configElem($config[ Cnf::container ], NULL);
			if ($container !== NULL && $el !== NULL) {
				$elClone = clone $el;
				$container->setHtml($elClone);
			}
			$el = $container;
		}

		return $el;
	}
public function configElem ( $ config , $ el = NULL ) { if ( is_scalar ( $ config ) ) { $ config = $ this -> fetchConfig ( $ config ) ; } // first define which element we want to work with if ( isset ( $ config [ Cnf :: elementName ] ) ) { $ name = $ config [ Cnf :: elementName ] ; if ( ! $ el ) { // element does not exist, so create it $ el = Html :: el ( $ name ) ; } else { // element exists, but we want to change its name $ el -> setName ( $ name ) ; } } if ( $ el instanceof Html && $ el != NULL ) { // if el is defined, we can configure it accordingly // go through all config and configure element accordingly foreach ( $ config as $ key => $ value ) { if ( in_array ( $ key , [ Cnf :: classSet , Cnf :: classAdd , Cnf :: classAdd , Cnf :: classRemove ] ) ) { // we'll be working with classes, we must standardize everything to arrays, not strings for the sake of sanity if ( ! is_array ( $ value ) ) { // configuration may contain classes as strings, but we always work with arrays $ value = [ $ value ] ; } $ origClass = $ el -> getAttribute ( 'class' ) ; $ newClass = $ origClass ; if ( $ origClass === NULL ) { // class is not set $ newClass = [ ] ; } elseif ( ! is_array ( $ origClass ) ) { // class is set, but not a array $ newClass = explode ( ' ' , $ el -> getAttribute ( 'class' ) ) ; } $ el -> setAttribute ( 'class' , $ newClass ) ; $ origClass = $ newClass ; } if ( $ key == Cnf :: classSet ) { $ el -> setAttribute ( 'class' , $ value ) ; } elseif ( $ key == Cnf :: classAdd ) { $ el -> setAttribute ( 'class' , array_merge ( $ origClass , $ value ) ) ; } elseif ( $ key == Cnf :: classRemove ) { $ el -> setAttribute ( 'class' , array_diff ( $ origClass , $ value ) ) ; } elseif ( $ key == Cnf :: attributes ) { foreach ( $ value as $ attr => $ attrVal ) { $ el -> setAttribute ( $ attr , $ attrVal ) ; } } } } // el may be null, but maybe it has a container defined if ( isset ( $ config [ Cnf :: container ] ) ) { $ container = $ this -> configElem ( $ config [ Cnf :: container ] , NULL ) ; if ( $ container !== NULL && $ el !== NULL ) { $ elClone = clone $ el ; $ container -> setHtml ( $ elClone ) ; } $ el = $ container ; } return $ el ; }
Turns configuration or and existing element and configures it appropriately
@param $config array|string top-level config key
@param $el     Html|null elem to config.
@return Html|null
Turns configuration or and existing element and configures it appropriately