<?php
namespace Factory\SupportBundle\Contract;
use Factory\SupportBundle\Exception\UnsupportedMethodException;
use Pimcore\Model\DataObject\ClassDefinition\CalculatorClassInterface;
use Pimcore\Model\DataObject\Concrete;
use Pimcore\Model\DataObject\Data\CalculatedValue;
abstract class AbstractComputed implements CalculatorClassInterface
{
public function compute($object, $context): string
{
$methodName = 'get' . ucfirst($context->getFieldname()) . 'Calculation';
$class = new static;
if (method_exists($class, $methodName) and is_callable([$class, $methodName])) {
return strval($class->{$methodName}($object, $context));
}
throw new UnsupportedMethodException($methodName, get_class($class));
}
public function getCalculatedValueForEditMode(Concrete $object, CalculatedValue $context): string
{
return $this->compute($object, $context);
}
}