|
|
@@ -54,6 +54,25 @@ class Core_AclSimpleSchemaBase extends Core_AclBase {
|
|
|
if (count($ns) < 2) throw new Exception("Wrong @namespace syntax in simpleSchema");
|
|
|
$this->_rootTableName = $ns[1];
|
|
|
|
|
|
+ {// validate and fix _simpleSchema:
|
|
|
+ // - convert field scalar to [ '@type' => ... ]
|
|
|
+ // - check required @namespace attribute
|
|
|
+ foreach ($this->_simpleSchema as $keySchema => $schema) {
|
|
|
+ foreach ($schema as $fieldName => $params) {
|
|
|
+ if ('@' == substr($fieldName, 0, 1)) continue;// skip params
|
|
|
+ if (is_scalar($params)) {
|
|
|
+ $this->_simpleSchema[ $keySchema ][ $fieldName ] = [ '@type' => $params ];
|
|
|
+ } else if (!is_array($params)) {
|
|
|
+ throw new Exception("Parse error - simpleSchema field type");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (empty($schema['@namespace'])) throw new Exception("Missing @namespace in schema for '{$keySchema}'");
|
|
|
+ $ns = explode('/', $schema['@namespace']);
|
|
|
+ $name = end($ns);
|
|
|
+ if (count($ns) < 2) throw new Exception("Wrong @namespace syntax in schema for '{$keySchema}'");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// $this->parseXsdTypes();// parse xsdTypes
|
|
|
$this->_xsdTypes = array();
|
|
|
{
|
|
|
@@ -65,7 +84,11 @@ class Core_AclSimpleSchemaBase extends Core_AclBase {
|
|
|
$field = [ 'name' => $fieldName, 'perms' => '', 'idZasob' => $generatedIdZasob ];
|
|
|
|
|
|
if (!empty($value['@type'])) $field['xsdType'] = "{$value['@type']}";
|
|
|
- else if (!empty($value['@ref'])) $field['xsdType'] = "ref:{$value['@ref']}";
|
|
|
+ else if (!empty($value['@ref'])) {
|
|
|
+ $field['xsdType'] = (false !== strpos($value['@ref'], '/'))
|
|
|
+ ? "ref_uri:{$value['@ref']}"
|
|
|
+ : "ref:{$value['@ref']}";
|
|
|
+ }
|
|
|
else throw new Exception("StorageAcl - field type not defined '{$key}'");
|
|
|
|
|
|
if (!empty($value['@maxOccurs'])) $field['maxOccurs'] = $value['@maxOccurs'];
|
|
|
@@ -86,6 +109,38 @@ class Core_AclSimpleSchemaBase extends Core_AclBase {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ public function __toString() {
|
|
|
+ $out = "xsd @prefix(default_db__x3A__{$this->_rootTableName})" . "\n";
|
|
|
+ $aliasRefUri = array();
|
|
|
+ foreach ($this->_simpleSchema as $objectName => $schema) {
|
|
|
+ if ('root' == $objectName) $objectName = $this->_name;
|
|
|
+ $out .= "\t" . "{$objectName}";
|
|
|
+ $out .= " @namespace({$schema['@namespace']})";
|
|
|
+ $out .= "\n";
|
|
|
+ foreach ($schema as $fieldName => $field) {
|
|
|
+ if ('@' == substr($fieldName, 0, 1)) continue;// skip tags
|
|
|
+ $out .= "\t\t" . "{$fieldName}";
|
|
|
+ if (!empty($field['@type'])) {
|
|
|
+ $out .= " @type({$field['@type']})";
|
|
|
+ if (!empty($field['@alias'])) $out .= " @alias({$field['@alias']})";
|
|
|
+ } else if (!empty($field['@ref'])) {
|
|
|
+ $out .= " @ref({$field['@ref']})";
|
|
|
+ if (false !== strpos($field['@ref'], '/')) $aliasRefUri[ $fieldName ] = $field['@ref'];
|
|
|
+ } else {
|
|
|
+ $out .= " @BUG('missing @type or @ref')";
|
|
|
+ }
|
|
|
+ // TODO: maxOccurs, nillable, etc.
|
|
|
+ $out .= "\n";
|
|
|
+ }
|
|
|
+ foreach ($aliasRefUri as $fieldName => $nsUri) {
|
|
|
+ $out .= "\t" . "{$objectName} @ref({$nsUri})" . "\n";
|
|
|
+ // TODO: maxOccurs, nillable, etc.
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $out;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function hasSimpleSchema() { return true; }
|
|
|
public function getSimpleSchema() { return $this->_simpleSchema; }
|
|
|
public function getName() { return $this->_name; }
|
|
|
public function getRootTableName() { $this->_rootTableName; }
|