/**
  *
  * @param ApiType $parent
  * @param MethodDoc|PropertyDoc|ConstDoc|EventDoc $primitive
  * @param $version
  */
 public static function createRecord($parent, $primitive, $version)
 {
     /** @var SearchApiPrimitive $model */
     $model = new static();
     $model->version = $version;
     $model->name = $primitive->name;
     $model->parentId = $parent->getPrimaryKey();
     $model->shortDescription = $primitive->shortDescription;
     $model->description = $primitive->description;
     $model->since = $primitive->since;
     $model->deprecatedSince = $primitive->deprecatedSince;
     $model->deprecatedReason = $primitive->deprecatedReason;
     $model->definedBy = $primitive->definedBy;
     if ($primitive instanceof MethodDoc) {
         $model->type = 'method';
         $model->visibility = $primitive->visibility;
         $model->isStatic = $primitive->isStatic;
         $model->isAbstract = $primitive->isAbstract;
         $model->isFinal = $primitive->isFinal;
         $params = [];
         foreach ($primitive->params as $param) {
             $params[] = ['name' => $param->name, 'description' => $param->description, 'isOptional' => $param->isOptional, 'defaultValue' => $param->defaultValue, 'isPassedByReference' => $param->isPassedByReference, 'typeHint' => $param->typeHint, 'types' => $param->types];
         }
         $model->params = $params;
         $exceptions = [];
         foreach ($primitive->exceptions as $name => $description) {
             $exceptions[] = ['name' => $name, 'description' => $description];
         }
         $model->exceptions = $exceptions;
         $model->return = $primitive->return;
         $model->returnTypes = $primitive->returnTypes;
         $model->isReturnByReference = $primitive->isReturnByReference;
     } elseif ($primitive instanceof PropertyDoc) {
         $model->type = 'property';
         $model->writeOnly = $primitive->isWriteOnly;
         $model->readOnly = $primitive->isReadOnly;
         $model->types = $primitive->types;
         $model->defaultValue = $primitive->defaultValue;
         $model->setter = $primitive->setter ? $primitive->setter->name : null;
         $model->getter = $primitive->getter ? $primitive->getter->name : null;
     } elseif ($primitive instanceof ConstDoc) {
         $model->type = 'const';
         $model->value = $primitive->value;
     } elseif ($primitive instanceof EventDoc) {
         $model->type = 'event';
         $model->value = $primitive->value;
     }
     $model->insert(false, null, ['op_type' => 'create', 'parent' => $model->parentId]);
 }
Пример #2
0
 public static function fromXML(SimpleXMLElement $xml)
 {
     //        LoggerInterface::log("api xml: " . print_r($xml->saveXML(), true), LoggerInterface::DEBUG);
     $api = new Api();
     $api->setId((string) $xml->id);
     $api->setDisplayName((string) $xml->displayName);
     $api->setVersion((string) $xml->version);
     $api->setType(ApiType::fromXML($xml->type));
     $api->setEndpoint((string) $xml->endpoint);
     $api->setAuthentication(ProvisionAuthentication::fromXML($xml->authentication));
     $api->setTdrEnabled($xml->tdrEnabled->enabled == 'true' ? true : false);
     $api->setTdrOnLimitReached((string) $xml->tdrOnLimitReached['type']);
     $api->setTdrOnUse((string) $xml->tdrOnUse['type']);
     $api->setStatus((string) $xml->status);
     $v = Validation::fromXML($xml->validation);
     if ($v !== null) {
         $api->setValidation($v);
     }
     $api->setSubscriptionStep((string) $xml->subscriptionStep);
     $api->setNotificationFormat((string) $xml->notificationFormat);
     $https = self::get_bool_value((string) $xml->https);
     if ($https) {
         $api->setHttps(HTTPSType::fromXML($xml->https));
     } else {
         $httpsType = new HTTPSType();
         $httpsType->setEnabled(false);
         $api->setHttps($httpsType);
     }
     $contexts = array();
     foreach ($xml->contexts->context as $contextXML) {
         $context = ApiContext::fromXML($contextXML);
         $contexts[] = $context;
     }
     $api->setContexts($contexts);
     $api->setTdrData(TdrData::fromXML($xml->tdr));
     if ($xml->properties && $xml->properties->property) {
         foreach ($xml->properties->property as $prop) {
             $api->properties[(string) $prop['name']] = (string) $prop;
         }
     }
     $api->setHeaderTransformationEnabled(current($xml->headerTransEnabled) == "true");
     if ($xml->headerTransformations && $xml->headerTransformations->headerTransformation) {
         foreach ($xml->headerTransformations->headerTransformation as $transform) {
             $api->headerTransformations[] = HeaderTransformation::fromXML($transform);
         }
     }
     if ($xml->allowedHttpMethods && $xml->allowedHttpMethods->httpMethod) {
         foreach ($xml->allowedHttpMethods->httpMethod as $method) {
             $api->allowedHttpMethods[] = current($method);
         }
     }
     return $api;
 }