/**
  * @return \Owebia\ShippingCore\Model\Wrapper\ArrayWrapper
  * @throws \Exception
  */
 public function addMethod()
 {
     $args = func_get_args();
     if (count($args) != 2) {
         throw new \Exception("Invalid arguments count for addMethod FuncCall");
     }
     $methodId = array_shift($args);
     if (!is_string($methodId) || !preg_match('#^[a-z][a-z0-9_]*$#', $methodId)) {
         throw new \Exception("Invalid first argument for addMethod FuncCall: the first argument" . " must be a string and match the following pattern : ^[a-z][a-z0-9_]*\$");
     }
     $methodOptions = array_shift($args);
     if (!is_array($methodOptions)) {
         throw new \Exception("Invalid second argument for addMethod FuncCall:" . " the second argument must be an array");
     }
     $this->result[$methodId] = (object) $methodOptions;
     return $this->registry->create('ArrayWrapper', ['data' => $methodOptions]);
 }
 /**
  * @param RateRequest|null $request
  * @return mixed|null
  */
 public function getConfig(RateRequest $request = null)
 {
     if ($this->isDebugEnabled()) {
         $this->debugLogger->collapseOpen("Carrier[{$this->_code}].getConfig", 'panel-primary');
     }
     $config = null;
     try {
         $this->registryHelper->init($this, $request);
         $configString = $this->getConfigData('config');
         $config = $this->configHelper->parse($configString, $this->registryHelper, (bool) $this->getConfigData('debug'));
     } catch (\Exception $e) {
         $this->_logger->debug($e);
         if ($this->isDebugEnabled()) {
             $this->debugLogger->debug("Carrier[{$this->_code}].getConfig - Error - " . $e->getMessage());
         }
     }
     if ($this->isDebugEnabled()) {
         $this->debugLogger->collapseClose();
     }
     return $config;
 }
 /**
  * @param type $expr
  * @return type
  */
 protected function evaluateFuncCall($expr)
 {
     if (isset($expr->name->parts)) {
         if (count($expr->name->parts) != 1) {
             return $this->error("Unsupported FuncCall expression", $expr);
         }
         $functionName = $expr->name->parts[0];
         $map = ['help' => [$this, 'fnHelp']];
         $isFunctionAllowed = in_array($functionName, $this->allowedFunctions) || in_array($functionName, array_keys($map));
         if (is_callable(array($this->callbackManager, $functionName))) {
             $functionName = array($this->callbackManager, $functionName);
         } else {
             if (!$isFunctionAllowed && function_exists($functionName)) {
                 return $this->error("Unauthorized function '{$functionName}'", $expr);
             } elseif (!$isFunctionAllowed) {
                 return $this->error("Unknown function '{$functionName}'", $expr);
             }
             if (isset($map[$functionName])) {
                 $functionName = $map[$functionName];
             }
         }
         $args = $this->evaluateArgs($expr);
         $result = call_user_func_array($functionName, $args);
         return $this->debug($expr, $result);
     } elseif ($expr->name instanceof \PhpParser\Node\Expr\Variable) {
         $variable = $this->registry->get($expr->name->name);
         if (!isset($variable)) {
             return $this->error("Unsupported FuncCall expression - Unkown function", $expr);
         }
         if (!is_callable($variable)) {
             return $this->error("Unsupported FuncCall expression - Variable is not a function", $expr);
         }
         $result = call_user_func_array($variable, $args = []);
         return $this->debug($expr, $result);
     } else {
         return $this->error("Unsupported FuncCall expression", $expr);
     }
 }
 /**
  * @param mixed $data
  * @return mixed
  */
 protected function wrap($data)
 {
     return $this->registry->wrap($data);
 }