예제 #1
0
 public function executeFunction(FunctionJob $functionJob, ExecutionContext $context)
 {
     $functionName = $functionJob->getName();
     /* @var $functionResolver FunctionResolverInterface */
     $functionResolver = null;
     if (isset($this->functionOverrides[$functionName])) {
         $functionResolver = $this->functionOverrides[$functionName];
     } else {
         $functionName = preg_replace("/[^a-zA-Z0-9_]/is", "", $functionName);
         $functionResolverClassName = ucfirst(strtolower($functionName)) . "Function";
         $functionResolverClass = "Addiks\\PHPSQL\\ValueResolver\\FunctionResolver\\{$functionResolverClassName}";
         # TODO: This few lines above are bad design, change it!
         if (!class_exists($functionResolverClass)) {
             throw new InvalidArgumentException("Function '{$functionName}' does not exist! ({$functionResolverClass})");
         }
         if (!is_subclass_of($functionResolverClass, FunctionInterface::class)) {
             throw new ErrorException("Function '{$functionName}' does not implement FunctionInterface!");
         }
         $functionResolver = new $functionResolverClass($this->valueResolver);
     }
     $returnValue = $functionResolver->executeFunction($functionJob, $context);
     return $returnValue;
 }
예제 #2
0
 public function resolveFunction(FunctionJob $functionJob, ExecutionContext $context)
 {
     $functionName = $functionJob->getName();
     $classNameFunctionPart = str_replace("_", " ", strtolower($functionName));
     $classNameFunctionPart = ucwords($classNameFunctionPart);
     $classNameFunctionPart = str_replace(" ", "", $classNameFunctionPart);
     $className = "\\Addiks\\PHPSQL\\{{$classNameFunctionPart}}";
     if (!class_exists($className)) {
         throw new ErrorException("Unknown or unimplemented function '{$functionName}' called! (No class '{$className}' found!)");
     }
     /* @var $functionExecuter FunctionResolver */
     $functionExecuter = new $className();
     $functionExecuter->setValueResolver($this);
     $functionArguments = array();
     foreach ($functionJob->getArguments() as $argument) {
         if ($argument instanceof Parameter) {
             $value = $argument->getValue();
         } else {
             $value = $argument;
         }
         $value = $this->resolveValue($value, $context);
         $functionArguments[] = $value;
     }
     return $functionExecuter->executeFunction($functionJob, $functionArguments);
 }