Skip to content

Commit

Permalink
bug #30 Undefined variable: file in Bpmn2Reader (@iteman)
Browse files Browse the repository at this point in the history
Discussion
----------

Undefined variable: file in Bpmn2Reader

| Q             | A
| ------------- | ---
| Branch?       | 1.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #17
| License       | BSD-2-Clause

This will fix an error *Undefined variable: file* in `Bpmn2Reader`.

Commits
-------

cb765a4 fix "Undefined variable: file" in `Bpmn2Reader`
  • Loading branch information
iteman committed Apr 16, 2017
2 parents dbd0329 + cb765a4 commit 5c53cc1
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions src/Definition/Bpmn2Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function read($file)
});
$errorToExceptionContext->invoke();

return $this->readDocument($document);
return $this->readDocument($document, pathinfo($file, PATHINFO_FILENAME));
}

/**
Expand All @@ -58,40 +58,37 @@ public function readSource($source)

/**
* @param DOMDocument $document
* @param int|string $workflowId
*
* @return Workflow
*
* @throws IdAttributeNotFoundException
*
* @since Method available since Release 1.3.0
*/
private function readDocument(\DOMDocument $document)
private function readDocument(\DOMDocument $document, $workflowId = null)
{
$errorToExceptionContext = new ErrorToExceptionContext(E_WARNING, function () use ($document) {
$document->schemaValidate(dirname(__DIR__).'/Resources/config/workflower/schema/BPMN20.xsd');
});
$errorToExceptionContext->invoke();

$workflowBuilder = new WorkflowBuilder();
$workflowBuilder = new WorkflowBuilder($workflowId);

foreach ($document->getElementsByTagNameNs('http://www.omg.org/spec/BPMN/20100524/MODEL', 'process') as $element) {
if ($element->hasAttribute('id')) {
$workflowId = $element->getAttribute('id');
$workflowBuilder->setWorkflowId($element->getAttribute('id'));
}

if ($element->hasAttribute('name')) {
$workflowBuilder->setWorkflowName($element->getAttribute('name'));
}
}
if (!isset($workflowId)) {
$workflowId = pathinfo($file, PATHINFO_FILENAME);
}
$workflowBuilder->setWorkflowId($workflowId);

$flowObjectRoles = array();
foreach ($document->getElementsByTagNameNs('http://www.omg.org/spec/BPMN/20100524/MODEL', 'lane') as $element) {
if (!$element->hasAttribute('id')) {
throw $this->createIdAttributeNotFoundException($element, $file);
throw $this->createIdAttributeNotFoundException($element, $workflowId);
}

$workflowBuilder->addRole(
Expand All @@ -111,7 +108,7 @@ private function readDocument(\DOMDocument $document)
$messages = array();
foreach ($document->getElementsByTagNameNs('http://www.omg.org/spec/BPMN/20100524/MODEL', 'message') as $element) {
if (!$element->hasAttribute('id')) {
throw $this->createIdAttributeNotFoundException($element, $file);
throw $this->createIdAttributeNotFoundException($element, $workflowId);
}

$messages[$element->getAttribute('id')] = $element->getAttribute('name');
Expand All @@ -120,15 +117,15 @@ private function readDocument(\DOMDocument $document)
$operations = array();
foreach ($document->getElementsByTagNameNs('http://www.omg.org/spec/BPMN/20100524/MODEL', 'operation') as $element) {
if (!$element->hasAttribute('id')) {
throw $this->createIdAttributeNotFoundException($element, $file);
throw $this->createIdAttributeNotFoundException($element, $workflowId);
}

$operations[$element->getAttribute('id')] = $element->getAttribute('name');
}

foreach ($document->getElementsByTagNameNs('http://www.omg.org/spec/BPMN/20100524/MODEL', 'startEvent') as $element) {
if (!$element->hasAttribute('id')) {
throw $this->createIdAttributeNotFoundException($element, $file);
throw $this->createIdAttributeNotFoundException($element, $workflowId);
}

$workflowBuilder->addStartEvent(
Expand All @@ -141,7 +138,7 @@ private function readDocument(\DOMDocument $document)

foreach ($document->getElementsByTagNameNs('http://www.omg.org/spec/BPMN/20100524/MODEL', 'task') as $element) {
if (!$element->hasAttribute('id')) {
throw $this->createIdAttributeNotFoundException($element, $file);
throw $this->createIdAttributeNotFoundException($element, $workflowId);
}

$workflowBuilder->addTask(
Expand All @@ -154,7 +151,7 @@ private function readDocument(\DOMDocument $document)

foreach ($document->getElementsByTagNameNs('http://www.omg.org/spec/BPMN/20100524/MODEL', 'serviceTask') as $element) {
if (!$element->hasAttribute('id')) {
throw $this->createIdAttributeNotFoundException($element, $file);
throw $this->createIdAttributeNotFoundException($element, $workflowId);
}

$workflowBuilder->addServiceTask(
Expand All @@ -168,7 +165,7 @@ private function readDocument(\DOMDocument $document)

foreach ($document->getElementsByTagNameNs('http://www.omg.org/spec/BPMN/20100524/MODEL', 'sendTask') as $element) {
if (!$element->hasAttribute('id')) {
throw $this->createIdAttributeNotFoundException($element, $file);
throw $this->createIdAttributeNotFoundException($element, $workflowId);
}

$workflowBuilder->addSendTask(
Expand All @@ -183,7 +180,7 @@ private function readDocument(\DOMDocument $document)

foreach ($document->getElementsByTagNameNs('http://www.omg.org/spec/BPMN/20100524/MODEL', 'exclusiveGateway') as $element) {
if (!$element->hasAttribute('id')) {
throw $this->createIdAttributeNotFoundException($element, $file);
throw $this->createIdAttributeNotFoundException($element, $workflowId);
}

$workflowBuilder->addExclusiveGateway(
Expand All @@ -196,15 +193,15 @@ private function readDocument(\DOMDocument $document)

foreach ($document->getElementsByTagNameNs('http://www.omg.org/spec/BPMN/20100524/MODEL', 'endEvent') as $element) {
if (!$element->hasAttribute('id')) {
throw $this->createIdAttributeNotFoundException($element, $file);
throw $this->createIdAttributeNotFoundException($element, $workflowId);
}

$workflowBuilder->addEndEvent($element->getAttribute('id'), $this->provideRoleIdForFlowObject($flowObjectRoles, $element->getAttribute('id')), $element->hasAttribute('name') ? $element->getAttribute('name') : null);
}

foreach ($document->getElementsByTagNameNs('http://www.omg.org/spec/BPMN/20100524/MODEL', 'sequenceFlow') as $element) {
if (!$element->hasAttribute('id')) {
throw $this->createIdAttributeNotFoundException($element, $file);
throw $this->createIdAttributeNotFoundException($element, $workflowId);
}

$condition = null;
Expand All @@ -227,13 +224,13 @@ private function readDocument(\DOMDocument $document)

/**
* @param \DOMElement $element
* @param string $file
* @param int|string $workflowId
*
* @return IdAttributeNotFoundException
*/
private function createIdAttributeNotFoundException(\DOMElement $element, $file)
private function createIdAttributeNotFoundException(\DOMElement $element, $workflowId)
{
return new IdAttributeNotFoundException(sprintf('The id attribute of the "%s" element is not found in "%s" on line %d', $element->tagName, $file, $element->getLineNo()));
return new IdAttributeNotFoundException(sprintf('The id attribute of the "%s" element is not found in workflow "%s" on line %d', $element->tagName, $workflowId, $element->getLineNo()));
}

/**
Expand Down

0 comments on commit 5c53cc1

Please sign in to comment.