Skip to content

Commit

Permalink
Automaticall register calling element in context
Browse files Browse the repository at this point in the history
  • Loading branch information
tolecar committed Oct 5, 2024
1 parent ec9a546 commit da6141b
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/Convo/Core/Workflow/AbstractWorkflowComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
*/
abstract class AbstractWorkflowComponent extends AbstractBasicComponent implements \Convo\Core\Workflow\IServiceWorkflowComponent
{

/**
* @var \Convo\Core\Workflow\IWorkflowContainerComponent
*/
private $_parent;


public function __construct( $properties)
{
parent::__construct( $properties);
Expand All @@ -30,7 +30,7 @@ public function isRoot()
}
return false;
}

/**
* {@inheritDoc}
* @see \Convo\Core\Workflow\IServiceWorkflowComponent::getParent()
Expand All @@ -41,46 +41,49 @@ public function getParent() {
}
return $this->_parent;
}

/**
* {@inheritDoc}
* @see \Convo\Core\Workflow\IServiceWorkflowComponent::setParent()
*/
public function setParent( \Convo\Core\Workflow\IWorkflowContainerComponent $parent) {
$this->_parent = $parent;
}

/**
* {@inheritDoc}
* @see \Convo\Core\Workflow\IServiceWorkflowComponent::evaluateString()
*/
public function evaluateString( $string, $context=[])
{
return $this->getParent()->evaluateString( $string, $context);
return $this->getParent()->evaluateString( $string, array_merge( [
'_workflowComponent' => $this
],
$context));
}

/**
* {@inheritDoc}
* @see \Convo\Core\Workflow\IServiceWorkflowComponent::getBlockParams()
*/
public function getBlockParams( $scopeType) {
return $this->getParent()->getBlockParams( $scopeType);
}

public function findAncestor( $class)
{
$parent = $this;
while ( $parent = $parent->getParent()) {
if ( is_a( $parent, $class)) {
return $parent;
}

if ( $parent === $this->getService()) {
break;
}
}

throw new DataItemNotFoundException( 'Ancestro with class ['.$class.'] not found');
}
}

}

0 comments on commit da6141b

Please sign in to comment.