protected function addPayloadToResource(ProjectionInterface $resource)
 {
     $resource_payload = [];
     foreach ($resource->getType()->getAttributes() as $attribute) {
         $attribute_payload = $this->getData($attribute->getName());
         //$this->logDebug('addPayloadToResource for', $attribute->getName(), 'with payload:', $attribute_payload);
         if ($attribute instanceof EmbeddedEntityListAttribute) {
             if (is_array($attribute_payload)) {
                 $attribute_payload = $this->filterEmptyPayloadComingFromEmbedTemplates($attribute, $attribute_payload);
             } else {
                 $attribute_payload = [];
             }
         }
         if (is_array($attribute_payload) && ($attribute instanceof HandlesFileListInterface || $attribute instanceof HandlesFileInterface)) {
             $attribute_payload = $this->filterEmptyPayloadComingFromFiles($attribute, $attribute_payload);
         }
         if (!empty($attribute_payload)) {
             //$this->logDebug('actually adding payload for', $attribute->getName(), '=>', $attribute_payload);
             $resource_payload[$attribute->getName()] = $attribute_payload;
         }
     }
     return $resource->getType()->createEntity(array_merge($resource->toNative(), $resource_payload));
 }
 protected function updateAffectedRelatives(ProjectionMap $affected_relatives, ProjectionInterface $source_projection)
 {
     $referenced_identifier = $source_projection->getIdentifier();
     $updated_relatives = [];
     foreach ($affected_relatives as $affected_relative) {
         // collate the paths and matching entity list attributes from the affected projection
         $updated_state = $affected_relative->toArray();
         $affected_relative_type = $affected_relative->getType();
         $affected_relative_prefix = $affected_relative_type->getPrefix();
         $affected_entities = $affected_relative->collateChildren(function (EntityInterface $embedded_entity) use($referenced_identifier) {
             return $embedded_entity instanceof EntityReferenceInterface && $embedded_entity->getReferencedIdentifier() === $referenced_identifier;
         });
         // reconstruct related projection state adding the updated mirrored values
         foreach ($affected_entities as $affected_entity_value_path => $affected_entity) {
             $affected_entity_type = $affected_entity->getType();
             $affected_entity_prefix = $affected_entity_type->getPrefix();
             $mirrored_values = $affected_entity_type->createMirroredEntity($source_projection, $affected_entity)->toArray();
             // @todo if the current affected entity type has no mirrored attributes we can cache the
             // mirrored values and improve performance by skipping additional unecessary recursion
             $mirrored_values['@type'] = $affected_entity_prefix;
             $mirrored_values['identifier'] = $affected_entity->getIdentifier();
             $mirrored_values['referenced_identifier'] = $affected_entity->getReferencedIdentifier();
             // insert the mirrored values in the correct position in our updated state
             preg_match_all('#(?<parent>[\\w-]+)\\.[\\w-]+\\[(?<position>\\d+)\\]\\.?#', $affected_entity_value_path, $value_path_parts, PREG_SET_ORDER);
             $nested_value =& $updated_state;
             foreach ($value_path_parts as $value_path_part) {
                 $nested_value =& $nested_value[$value_path_part['parent']][$value_path_part['position']];
             }
             $nested_value = $mirrored_values;
         }
         // create the new projection from the updated state
         $updated_relative = $affected_relative_type->createEntity($updated_state);
         $updated_relatives[] = $updated_relative;
     }
     return new ProjectionMap($updated_relatives);
 }
 /**
  * Tries to find a template for the given resource by inspecting the current view
  * and the domain object's workflow state.
  *
  * That is, an "InputView" with an resource of workflow step "inactive" results in
  * a template of ".../Inactive_Input" that can then be set via "setTemplate()".
  *
  * Returns the first found template that matches the view's name and has a file extension
  * of '.haml', '.twig' or '.php'.
  *
  * @param ProjectionInterface $resource domain object with State/Step
  *
  * @return string|false template path/name to use; false if no matching template file was found
  */
 protected function getCustomTemplate(ProjectionInterface $resource)
 {
     $view_class = new ReflectionClass($this);
     $view_class_dir = dirname($view_class->getFilename());
     $state = $resource->getWorkflowState();
     $class_file_name = basename($view_class->getFilename());
     $class_name = str_replace('View.class.php', '', $class_file_name);
     $template_name = sprintf('%s_%s', ucfirst($state), $class_name);
     $template_extensions = array('.haml', '.twig', '.php');
     $custom_template = false;
     foreach ($template_extensions as $template_extension) {
         $template_file = $template_name . $template_extension;
         $template_path = $view_class_dir . DIRECTORY_SEPARATOR . $template_file;
         if (is_readable($template_path)) {
             $custom_template = $view_class_dir . DIRECTORY_SEPARATOR . $template_name;
             break;
         }
     }
     return $custom_template;
 }
Example #4
0
 public function __construct($state_machine_name, ProjectionInterface $resource)
 {
     $this->resource = $resource;
     $this->execution_context = new ExecutionContext($state_machine_name, $resource->getWorkflowState(), array_merge($resource->getWorkflowParameters(), ['current_state' => $resource->getWorkflowState()]));
 }
Example #5
0
 protected function calculateMaterializedPath(ProjectionInterface $parent = null)
 {
     $path_parts = [];
     if ($parent) {
         $parent_path = $parent->getMaterializedPath();
         if (!empty($parent_path)) {
             $path_parts = explode('/', $parent_path);
         }
         $path_parts[] = $parent->getIdentifier();
     }
     return implode('/', $path_parts);
 }