FOF30\Configuration\Domain\Models::parseDomain PHP Метод

parseDomain() публичный Метод

Parse the XML data, adding them to the $ret array
public parseDomain ( SimpleXMLElement $xml, array &$ret ) : void
$xml SimpleXMLElement The XML data of the component's configuration area
$ret array
Результат void
    public function parseDomain(SimpleXMLElement $xml, array &$ret)
    {
        // Initialise
        $ret['models'] = array();
        // Parse model configuration
        $modelsData = $xml->xpath('model');
        // Sanity check
        if (empty($modelsData)) {
            return;
        }
        foreach ($modelsData as $aModel) {
            $key = (string) $aModel['name'];
            $ret['models'][$key]['behaviors'] = array();
            $ret['models'][$key]['behaviorsMerge'] = false;
            $ret['models'][$key]['tablealias'] = $aModel->xpath('tablealias');
            $ret['models'][$key]['fields'] = array();
            $ret['models'][$key]['relations'] = array();
            $ret['models'][$key]['config'] = array();
            // Parse configuration
            $optionData = $aModel->xpath('config/option');
            if (!empty($optionData)) {
                foreach ($optionData as $option) {
                    $k = (string) $option['name'];
                    $ret['models'][$key]['config'][$k] = (string) $option;
                }
            }
            // Parse field aliases
            $fieldData = $aModel->xpath('field');
            if (!empty($fieldData)) {
                foreach ($fieldData as $field) {
                    $k = (string) $field['name'];
                    $ret['models'][$key]['fields'][$k] = (string) $field;
                }
            }
            // Parse behaviours
            $behaviorsData = (string) $aModel->behaviors;
            $behaviorsMerge = (string) $aModel->behaviors['merge'];
            if (!empty($behaviorsMerge)) {
                $behaviorsMerge = trim($behaviorsMerge);
                $behaviorsMerge = strtoupper($behaviorsMerge);
                if (in_array($behaviorsMerge, array('1', 'YES', 'ON', 'TRUE'))) {
                    $ret['models'][$key]['behaviorsMerge'] = true;
                }
            }
            if (!empty($behaviorsData)) {
                $behaviorsData = explode(',', $behaviorsData);
                foreach ($behaviorsData as $behavior) {
                    $behavior = trim($behavior);
                    if (empty($behavior)) {
                        continue;
                    }
                    $ret['models'][$key]['behaviors'][] = $behavior;
                }
            }
            // Parse relations
            $relationsData = $aModel->xpath('relation');
            if (!empty($relationsData)) {
                foreach ($relationsData as $relationData) {
                    $type = (string) $relationData['type'];
                    $itemName = (string) $relationData['name'];
                    if (empty($type) || empty($itemName)) {
                        continue;
                    }
                    $modelClass = (string) $relationData['foreignModelClass'];
                    $localKey = (string) $relationData['localKey'];
                    $foreignKey = (string) $relationData['foreignKey'];
                    $pivotTable = (string) $relationData['pivotTable'];
                    $ourPivotKey = (string) $relationData['pivotLocalKey'];
                    $theirPivotKey = (string) $relationData['pivotForeignKey'];
                    $relation = array('type' => $type, 'itemName' => $itemName, 'foreignModelClass' => empty($modelClass) ? null : $modelClass, 'localKey' => empty($localKey) ? null : $localKey, 'foreignKey' => empty($foreignKey) ? null : $foreignKey);
                    if (!empty($ourPivotKey) || !empty($theirPivotKey) || !empty($pivotTable)) {
                        $relation['pivotLocalKey'] = empty($ourPivotKey) ? null : $ourPivotKey;
                        $relation['pivotForeignKey'] = empty($theirPivotKey) ? null : $theirPivotKey;
                        $relation['pivotTable'] = empty($pivotTable) ? null : $pivotTable;
                    }
                    $ret['models'][$key]['relations'][] = $relation;
                }
            }
        }
    }