diff --git a/library/CM/Config/Generator.php b/library/CM/Config/Generator.php index ff9441f44..f4180f51a 100644 --- a/library/CM/Config/Generator.php +++ b/library/CM/Config/Generator.php @@ -2,7 +2,7 @@ class CM_Config_Generator extends CM_Class_Abstract { - /** @var int */ + /** @var int */ private $_typesMaxValue = 0; /** @var string[] */ @@ -56,7 +56,9 @@ public function getConfigClassTypes() { $this->generateClassTypes(); $config = new CM_Config_Node(); foreach ($this->getNamespaceTypes() as $namespaceClass => $typeList) { - $config->$namespaceClass->types = $typeList; + $config->$namespaceClass->types = \Functional\map($typeList, function ($className) { + return "$className::class"; + }); } $classTypes = $this->getClassTypes(); foreach ($classTypes as $type => $class) { diff --git a/library/CM/Config/Node.php b/library/CM/Config/Node.php index 1ecf21f45..f9fee552f 100644 --- a/library/CM/Config/Node.php +++ b/library/CM/Config/Node.php @@ -20,7 +20,7 @@ public function export() { $object->$key = $value->export(); } else { if (is_array($value)) { - $value = $this->_evaluateConstantsInKeys($value); + $value = $this->_evaluateConstantsInArray($value); } $object->$key = $value; } @@ -59,7 +59,12 @@ public function exportAsString($baseKey, $property = null) { if (!is_scalar($value)) { $output .= $this->exportAsString($getFullKey($baseKey, $key), $value); } else { - $output .= $getFullKey($baseKey, $key) . " = " . var_export($value, true) . ";" . PHP_EOL; + if (preg_match('/^(\w+)::class$/', $value, $matches) && class_exists($matches[1])) { + $configValue = $value; + } else { + $configValue = var_export($value, true); + } + $output .= $getFullKey($baseKey, $key) . " = " . $configValue . ";" . PHP_EOL; } } return $output; @@ -112,15 +117,16 @@ public function extendWithFile(CM_File $configFile) { * @param array $list * @return array */ - private function _evaluateConstantsInKeys(array $list) { - $keys = array_keys($list); - $keys = \Functional\map($keys, function ($key) { - if (null !== ($value = $this->_evaluateClassConstant($key))) { + private function _evaluateConstantsInArray(array $list) { + $constantEvaluator = function ($key) { + if (is_scalar($key) && null !== ($value = $this->_evaluateClassConstant($key))) { return $value; } return $key; - }); - return array_combine($keys, array_values($list)); + }; + $keys = \Functional\map(array_keys($list), $constantEvaluator); + $values = \Functional\map(array_values($list), $constantEvaluator); + return array_combine($keys, $values); } /** @@ -128,7 +134,9 @@ private function _evaluateConstantsInKeys(array $list) { * @return mixed|null */ private function _evaluateClassConstant($reference) { - if (preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*::[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $reference)) { + if (preg_match('/^(\w+)::class$/', $reference, $matches) && class_exists($matches[1])) { + return $matches[1]; + } elseif (preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*::[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $reference)) { return @constant($reference); } return null;