Skip to content

Instantly share code, notes, and snippets.

@mheadd
Created February 14, 2010 22:07
Show Gist options
  • Save mheadd/304297 to your computer and use it in GitHub Desktop.
Save mheadd/304297 to your computer and use it in GitHub Desktop.
<?php
/*
* Contents of vxml.php
*/
abstract class :xhp:vxml-element extends :x:primitive {
protected
$tagName;
protected final function renderBaseAttrs() {
$buf = '<'.$this->tagName;
foreach ($this->getAttributes() as $key => $val) {
if ($val !== null && $val !== false) {
$buf .= ' ' . htmlspecialchars($key) . '="' . htmlspecialchars($val, true) . '"';
}
}
return $buf;
}
public function addClass($class) {
$class = trim($class);
$currentClasses = $this->getAttribute('class');
$has = strpos(' '.$currentClasses.' ', ' '.$class.' ') !== false;
if ($has) {
return $this;
}
$this->setAttribute('class', trim($currentClasses.' '.$class));
return $this;
}
protected function stringify() {
$buf = $this->renderBaseAttrs() . '>';
foreach ($this->getChildren() as $child) {
$buf .= :x:base::renderChild($child);
}
$buf .= '</'.$this->tagName.'>';
return $buf;
}
}
abstract class :xhp:vxml-singleton extends :xhp:vxml-element {
children empty;
protected function stringify() {
return $this->renderBaseAttrs() . ' />';
}
}
class :block extends :xhp:vxml-element {
attribute
enum {"true", "false"} cond, string name;
children (:log, :prompt*);
protected $tagName = 'block';
}
class :prompt extends :xhp:vxml-element {
children (pcdata | %phrase)*;
protected $tagName = 'prompt';
}
class :log extends :xhp:vxml-element {
children (pcdata | %phrase)*;
protected $tagName = 'log';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment