/** * @param string $configuration * @param \Owebia\ShippingCore\Helper\Registry $registry * @param boolean $debug * @return array */ public function parse($configuration, \Owebia\ShippingCore\Helper\Registry $registry, $debug = false) { $t0 = microtime(true); ini_set('xdebug.max_nesting_level', 3000); $parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP5); $hash = md5($configuration); if (!isset($this->parsingCache[$hash])) { // $stmts is an array of statement nodes $stmts = $parser->parse("<?php " . $configuration . ";"); $this->parsingCache[$hash] = $stmts; } else { $stmts = $this->parsingCache[$hash]; } $this->registry = $registry; $this->evaluator->reset(); $this->evaluator->setDebug($debug); $this->evaluator->setRegistry($registry); $this->evaluator->setCallbackManager($this); $this->result = []; foreach ($stmts as $node) { $this->parseNode($node, $debug); $this->evaluator->reset(); } $t1 = microtime(true); if ($debug) { $this->debugLogger->debug("Duration " . round($t1 - $t0, 2) . " s"); } return $this->result; }
/** * @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; }