Skip to content

Commit

Permalink
Added a report callback for hooking progress and certain data while p…
Browse files Browse the repository at this point in the history
…arsing.
  • Loading branch information
Steven Bennett committed Oct 15, 2020
1 parent cc6b57e commit 38dea60
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/SchemaReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ private function loadAttributeGroup(
Schema $schema,
DOMElement $node
): Closure {
$this->reportProgress("loadAttributeGroup", [ $schema, $node ]);

$attGroup = new AttributeGroup($schema, $node->getAttribute('name'));
$attGroup->setDoc($this->getDocumentation($node));
$schema->addAttributeGroup($attGroup);
Expand Down Expand Up @@ -203,6 +205,8 @@ private function loadAttribute(
Schema $schema,
DOMElement $node
): Attribute {
$this->reportProgress("loadAttribute", [ $schema, $node ]);

$attribute = new Attribute($schema, $node->getAttribute('name'));
$attribute->setDoc($this->getDocumentation($node));
$this->fillItem($attribute, $node);
Expand Down Expand Up @@ -255,6 +259,8 @@ private function getDocumentation(DOMElement $node): string
*/
private function schemaNode(Schema $schema, DOMElement $node, Schema $parent = null): array
{
$this->reportProgress("schemaNode", [ $schema, $node, $parent ]);

$this->setSchemaThingsFromNode($schema, $node, $parent);
$functions = [];

Expand Down Expand Up @@ -465,6 +471,8 @@ private function addGroupAsElement(

private function loadGroup(Schema $schema, DOMElement $node): Closure
{
$this->reportProgress("loadGroup", [ $schema, $node ]);

$group = new Group($schema, $node->getAttribute('name'));
$group->setDoc($this->getDocumentation($node));
$groupOriginal = $group;
Expand Down Expand Up @@ -1091,6 +1099,8 @@ private function loadImport(
Schema $schema,
DOMElement $node
): Closure {
$this->reportProgress("loadImport", [ $schema, $node ]);

$namespace = $node->getAttribute('namespace');
$schemaLocation = $node->getAttribute('schemaLocation');
if (!$schemaLocation && isset($this->knownNamespaceSchemaLocations[$namespace])) {
Expand Down Expand Up @@ -1145,6 +1155,8 @@ private function loadImportFresh(
Schema $schema,
string $file
): Closure {
$this->reportProgress("loadImportFresh", [ $namespace, $schema, $file ]);

return function () use ($namespace, $schema, $file): void {
$dom = $this->getDOM(
isset($this->knownLocationSchemas[$file])
Expand Down Expand Up @@ -1310,6 +1322,8 @@ private function getDOM(string $file): DOMDocument
}
libxml_use_internal_errors(false);

$this->reportProgress("getDomLoaded", [ $file, $xml ]);

return $xml;
}

Expand Down Expand Up @@ -1338,6 +1352,8 @@ private function loadTypeWithCallback(
DOMElement $childNode,
Closure $callback
): void {
$this->reportProgress("loadTypeWithCallback", [ $schema, $childNode ]);

/**
* @var Closure|null $func
*/
Expand All @@ -1361,6 +1377,8 @@ private function loadElement(
Schema $schema,
DOMElement $node
): Element {
$this->reportProgress("loadElement", [ $schema, $node ]);

$element = new Element($schema, $node->getAttribute('name'));
$element->setDoc($this->getDocumentation($node));

Expand Down Expand Up @@ -1456,4 +1474,17 @@ private function setSchemaThingsFromNode(
$schema->setAttributesQualification($node->getAttribute('attributeFormDefault') == 'qualified');
$schema->setDoc($this->getDocumentation($node));
}

/** @var callable $reportCallback */
private $reportCallback;
public function setReportCallback(callable $rc)
{
$this->reportCallback = $rc;
}
private function reportProgress(string $report, array $data)
{
if (!empty($this->reportCallback)) {
call_user_func($this->reportCallback, $report, $data);
}
}
}

0 comments on commit 38dea60

Please sign in to comment.