public function toString()
{
$exprString = $this->expr->toString();
if ($this->expr instanceof AndX || $this->expr instanceof OrX) {
return $this->key . '{' . $exprString . '}';
}
// Append "functions" with "."
if (isset($exprString[0]) && ctype_alpha($exprString[0])) {
return $this->key . '.' . $exprString;
}
return $this->key . $exprString;
}
public function testToString() { $expr1 = new Key('name', new GreaterThan(10)); $expr2 = new Key('name', new EndsWith('.css')); $expr3 = new Key('name', new AndX(array(new GreaterThan(10), new EndsWith('.css')))); $this->assertSame('name>10', $expr1->toString()); $this->assertSame('name.endsWith(".css")', $expr2->toString()); $this->assertSame('name{>10 && endsWith(".css")}', $expr3->toString()); }