Repository: ProcessMaker/nayra (php)

Issue:
Add BpmnElement reference
As a developer I would like to get the reference to the BPMN element of a loaded BPMN document, so I can work with that element reference.

```
interface EntityInterface
{

    /**
     * @return \ProcessMaker\Nayra\Contracts\Storage\BpmnElementInterface
     */
    public function getBpmnElement();

    /**
     * Set DOM element of this object.
     *
     * @param BpmnElementInterface $domElement
     *
     * @return $this
     */
    public function setBpmnElement(BpmnElementInterface $ownerDocument);
}
```


Pull request:
Resolves #177 Add BpmnElement reference
This PR implements a reference getter/setter to the Bpmn Element  of any EntityInterface.


Patch:
diff --git a/src/ProcessMaker/Nayra/Bpmn/BaseTrait.php b/src/ProcessMaker/Nayra/Bpmn/BaseTrait.php
index 3915269..2735315 100755
--- a/src/ProcessMaker/Nayra/Bpmn/BaseTrait.php
+++ b/src/ProcessMaker/Nayra/Bpmn/BaseTrait.php
@@ -2,9 +2,9 @@
 
 namespace ProcessMaker\Nayra\Bpmn;
 
-use ProcessMaker\Nayra\Bpmn\Collection;
 use ProcessMaker\Nayra\Contracts\Repositories\StorageInterface;
 use ProcessMaker\Nayra\Contracts\RepositoryInterface;
+use ProcessMaker\Nayra\Contracts\Storage\BpmnElementInterface;
 use ReflectionClass;
 
 /**
@@ -30,6 +30,13 @@ trait BaseTrait
      */
     private $ownerDocument;
 
+    /**
+     * Bpmn Element of this object.
+     *
+     * @var BpmnElementInterface $bpmnElement
+     */
+    private $bpmnElement;
+
     /**
      * BaseTrait constructor.
      *
@@ -102,6 +109,29 @@ trait BaseTrait
         return $this;
     }
 
+    /**
+     * Get DOM element of this object.
+     *
+     * @return \ProcessMaker\Nayra\Contracts\Storage\BpmnElementInterface
+     */
+    public function getBpmnElement()
+    {
+        return $this->bpmnElement;
+    }
+
+    /**
+     * Set DOM element of this object.
+     *
+     * @param \ProcessMaker\Nayra\Contracts\Repositories\StorageInterface $ownerDocument
+     *
+     * @return $this
+     */
+    public function setBpmnElement(BpmnElementInterface $bpmnElement)
+    {
+        $this->bpmnElement = $bpmnElement;
+        return $this;
+    }
+
     /**
      * Get properties.
      *
@@ -120,7 +150,7 @@ trait BaseTrait
      */
     public function setProperties(array $properties)
     {
-        foreach($properties as $name => $value) {
+        foreach ($properties as $name => $value) {
             $setter = 'set' . $name;
             if (method_exists($this, $setter)) {
                 $this->$setter($value);
diff --git a/src/ProcessMaker/Nayra/Contracts/Bpmn/EntityInterface.php b/src/ProcessMaker/Nayra/Contracts/Bpmn/EntityInterface.php
index 2bcc875..15602ec 100755
--- a/src/ProcessMaker/Nayra/Contracts/Bpmn/EntityInterface.php
+++ b/src/ProcessMaker/Nayra/Contracts/Bpmn/EntityInterface.php
@@ -4,6 +4,7 @@ namespace ProcessMaker\Nayra\Contracts\Bpmn;
 
 use ProcessMaker\Nayra\Contracts\Repositories\StorageInterface;
 use ProcessMaker\Nayra\Contracts\RepositoryInterface;
+use ProcessMaker\Nayra\Contracts\Storage\BpmnElementInterface;
 
 /**
  * Entity could get and set properties for an bpmn element.
@@ -12,7 +13,6 @@ use ProcessMaker\Nayra\Contracts\RepositoryInterface;
  */
 interface EntityInterface
 {
-
     const BPMN_PROPERTY_ID = 'id';
     const BPMN_PROPERTY_NAME = 'name';
 
@@ -106,9 +106,25 @@ interface EntityInterface
     public function getOwnerDocument();
 
     /**
+     * Get DOM element of this object.
+     *
      * @param StorageInterface $ownerDocument
      *
      * @return $this
      */
     public function setOwnerDocument(StorageInterface $ownerDocument);
+
+    /**
+     * @return \ProcessMaker\Nayra\Contracts\Storage\BpmnElementInterface
+     */
+    public function getBpmnElement();
+
+    /**
+     * Set DOM element of this object.
+     *
+     * @param BpmnElementInterface $domElement
+     *
+     * @return $this
+     */
+    public function setBpmnElement(BpmnElementInterface $ownerDocument);
 }
diff --git a/src/ProcessMaker/Nayra/Storage/BpmnElement.php b/src/ProcessMaker/Nayra/Storage/BpmnElement.php
index 63aff08..0847ca0 100644
--- a/src/ProcessMaker/Nayra/Storage/BpmnElement.php
+++ b/src/ProcessMaker/Nayra/Storage/BpmnElement.php
@@ -60,6 +60,7 @@ class BpmnElement extends DOMElement implements BpmnElementInterface
         } else {
             $bpmnElement = $this->ownerDocument->getFactory()->create($classInterface);
             $bpmnElement->setOwnerDocument($this->ownerDocument);
+            $bpmnElement->setBpmnElement($this);
             $id ? $this->ownerDocument->indexBpmnElement($id, $bpmnElement) : null;
             $bpmnElement->setRepository($this->ownerDocument->getFactory());
             if ($bpmnElement instanceof CallableElementInterface) {


Test patch:
diff --git a/tests/Feature/Engine/LoadFromBPMNFileTest.php b/tests/Feature/Engine/LoadFromBPMNFileTest.php
index ac99d41..ad8a6bc 100644
--- a/tests/Feature/Engine/LoadFromBPMNFileTest.php
+++ b/tests/Feature/Engine/LoadFromBPMNFileTest.php
@@ -84,6 +84,10 @@ class LoadFromBPMNFileTest extends EngineTestCase
         $this->assertEquals($bpmnRepository, $activityB->getOwnerDocument());
         $this->assertEquals($bpmnRepository, $endActivity->getOwnerDocument());
 
+        //Assertion: Check reference to BPMN element
+        $this->assertEquals($bpmnRepository->findElementById('StartEvent'), $start->getBpmnElement());
+        $this->assertEquals($bpmnRepository->findElementById('start'), $startActivity->getBpmnElement());
+
         //Start the process
         $start->start($instance);
         $this->engine->runToNextState();