/** * In this test, we will evaluate an undefined const, * because we know that the Function_const class is designed to * log a warning. * One can wrap any implementation of the PSR-3 Logging they wish, * by supplying to FigDice a LoggerFactoryDelegate. * You supply a delegate by giving the FigDice's LoggerFactory static * utility class, an instance of figdice\LoggerFactoryDelegate. * This instance accepts the name of a class, and provides the corresponding * PSR-3 LoggerInterface of your choice. */ public function testUnfedinedConstWillWarn() { $capturableLoggerInterface = new YouHaveBeenWarned(); LoggerFactory::setDelegate(new TestLoggerFactoryDelegate($capturableLoggerInterface)); $result = $this->lexExpr(" const('myUndefinedConst') "); $this->assertEquals(false, $result); $this->assertContains('Undefined constant: myUndefinedConst', $capturableLoggerInterface->getCapturedWarnings()); }
public function evaluate(ViewElementTag $viewElement, $arity, $arguments) { $funcName = array_shift($arguments); if (!function_exists($funcName)) { $logger = LoggerFactory::getLogger(get_class($this)); $logger->error('Invalid PHP function: ' . $funcName); $this->error = true; return false; } return call_user_func_array($funcName, $arguments); }
/** * @param ViewElement $viewElement * @param integer $arity * @param array $arguments one element: name of global constant, or class constant (myClass::myConst) */ public function evaluate(ViewElementTag $viewElement, $arity, $arguments) { $constantName = trim($arguments[0]); if (preg_match('#([^:]+)::#', $constantName, $matches)) { $className = $matches[1]; if (!class_exists($className)) { $logger = LoggerFactory::getLogger(__CLASS__); $logger->warning("Undefined class: {$className} in static: {$constantName}"); return null; } } //Global constant if (defined($constantName)) { return constant($constantName); } else { $logger = LoggerFactory::getLogger(__CLASS__); $logger->warning("Undefined constant: {$constantName}"); return null; } }
/** * @param Lexer $lexer * @param string $message */ protected function throwErrorWithMessage($lexer, $message) { $message = get_class($this) . ': file: ' . $lexer->getViewFile()->getFilename() . '(' . $lexer->getViewLine() . '): ' . $message . ' in expression: ' . $lexer->getExpression(); if (!$this->logger) { $this->logger = LoggerFactory::getLogger(get_class($this)); } $this->logger->error($message); throw new LexerUnexpectedCharException($message, $lexer->getViewFile()->getFilename(), $lexer->getViewLine()); }
public function __construct() { $this->logger = LoggerFactory::getLogger(get_class($this)); }
/** * @return LoggerInterface */ private function getLogger() { if (null == $this->logger) { $this->logger = LoggerFactory::getLogger(__CLASS__); } return $this->logger; }
/** * Returns the logger instance, * or creates one beforehand, if null. * * @return LoggerInterface */ private function getLogger() { if (!$this->logger) { $this->logger = LoggerFactory::getLogger(get_class($this)); } return $this->logger; }
public function __construct() { $this->source = ''; $this->result = ''; $this->rootNode = null; $this->stack = array(); $this->logger = LoggerFactory::getLogger(get_class($this)); $this->parentViewElement = null; $this->lexers = array(); $this->callStackData = array(array()); $this->functionFactories = array(new NativeFunctionFactory()); $this->language = null; }
/** * @param ViewElement $viewElement */ public function evaluate(ViewElementTag $viewElement) { if ($this->function === null) { //Instantiate the Function handler: /** @var FunctionFactory[] $factories */ $factories = $viewElement->getView()->getFunctionFactories(); if (null != $factories && is_array($factories)) { foreach ($factories as $factory) { if (null !== ($this->function = $factory->lookup($this->name))) { break; } } } if ($this->function == null) { $logger = LoggerFactory::getLogger(__CLASS__); $message = 'Undeclared function: ' . $this->name; $logger->error($message); throw new FunctionNotFoundException($this->name); } } $arguments = array(); if ($this->operands) { foreach ($this->operands as $operandToken) { $arguments[] = $operandToken->evaluate($viewElement); } } return $this->function->evaluate($viewElement, $this->arity, $arguments); }