bundles/Factory/SupportBundle/Contract/AbstractComputed.php line 11

Open in your IDE?
  1. <?php
  2. namespace Factory\SupportBundle\Contract;
  3. use Factory\SupportBundle\Exception\UnsupportedMethodException;
  4. use Pimcore\Model\DataObject\ClassDefinition\CalculatorClassInterface;
  5. use Pimcore\Model\DataObject\Concrete;
  6. use Pimcore\Model\DataObject\Data\CalculatedValue;
  7. abstract class AbstractComputed implements CalculatorClassInterface
  8. {
  9.     public function compute($object$context): string
  10.     {
  11.         $methodName 'get' ucfirst($context->getFieldname()) . 'Calculation';
  12.         $class = new static;
  13.         if (method_exists($class$methodName) and is_callable([$class$methodName])) {
  14.             return strval($class->{$methodName}($object$context));
  15.         }
  16.         throw new UnsupportedMethodException($methodNameget_class($class));
  17.     }
  18.     public function getCalculatedValueForEditMode(Concrete $objectCalculatedValue $context): string
  19.     {
  20.        return $this->compute($object$context);
  21.     }
  22. }