protected function toString($ident = 1, $name = '') { $lines = []; //$lines[] = get_class($this->getRule()); if ($this->getRule()->hasName()) { $name = ($name ? $name . '.' : '') . $this->getRule()->getName(); $lines[] = $name; } if (false !== ($children = $this->getChildren())) { foreach ($children as $child) { $lines[] = $child->toString($ident + 1, $name); } } elseif (false !== ($related = $this->getRelated())) { $lines[] = $related->toString($ident + 1, $name); } else { $lines[] = 'Message: ' . $this->getRule()->getMessage($this->getInfo(), $this->getInput()); $lines[] = 'Input: ' . \Nora\Nora::dump($this->getInput(), true); } $text = ''; foreach ($lines as $line) { if ($line[0] === ">") { $text .= $line . PHP_EOL; } else { $text .= str_repeat(">", $ident) . ($ident != 0 ? ' ' : '') . $line . PHP_EOL; } } return $text; }
public function getMessage($code, $input) { if (isset($this->_messages[$code])) { $msg = $this->_messages[$code]; } else { $msg = $this->_messages['DEFAULT']; } return preg_replace_callback('/%\\(([^\\)]+)\\)/', function ($m) use($input, $code) { if ($m[1] === 'input') { return trim(\Nora\Nora::dump($input, true)); } if ($m[1] === 'code') { return $code; } if ($this->hasParam($m[1])) { return $this->getParam($m[1]); } return $m[0]; }, $msg); }
public function testMain() { Nora::dump(Nora::getService('config')); }