Exemple #1
0
 /**
  * Decodes a textual representation for a duration
  *
  * @param $s input duration (numeric=seconds, hh:mm:ss=decode to seconds)
  */
 function set($s)
 {
     if (!$s) {
         return;
     }
     if (is_numeric($s)) {
         $this->value = $s;
         return;
     }
     if (is_duration($s)) {
         $this->value = parse_duration($s);
         return;
     }
     $a = explode(':', $s);
     if (count($a) == 3) {
         //handle "00:03:39.00"
         $this->value = $a[0] * 3600 + $a[1] * 60 + $a[2];
         return;
     }
     if (count($a) == 2) {
         //handle "04:29"
         $this->value = $a[0] * 60 + $a[1];
         return;
     }
     dtrace();
     die('Duration->set( ' . $s . ' ) FAIL');
     //$this->duration = $s;
 }
Exemple #2
0
/**
 * Dump pretty XML
 *
 * @param mixed $xml
 */
function dxml($xml)
{
    $xml = null;
    if ($xml instanceof DOMElement) {
        $xml = $xml->ownerDocument->saveXML($xml);
    } else {
        if ($xml instanceof DOMDocument) {
            $xml = $xml->saveXML();
        } else {
            if ($xml instanceof SimpleXMLElement) {
                $xml = $xml->saveXML();
            } else {
                if (is_string($xml)) {
                    $xml = $xml;
                }
            }
        }
    }
    // make the XML readable by human eye!
    if (!is_null($xml)) {
        $er = error_reporting();
        error_reporting(0);
        // PEAR has lots of strict errors
        if (class_exists('XML_Beautifier')) {
            $fmt = new XML_Beautifier();
            $xml = PHP_EOL . $fmt->formatString($xml, "Plain");
        }
        error_reporting($er);
    }
    decorate('<div style="background:#f8f8f8;margin:5px;padding:5px;border: solid grey 1px;">' . PHP_EOL);
    $trace = dtrace();
    echo PHP_EOL . PHP_EOL . 'o----' . $trace . '----o' . PHP_EOL;
    decorate('<pre style="margin:0px;padding:0px;">' . PHP_EOL);
    var_dump($xml) . PHP_EOL;
    if (!is_null($xml)) {
        if (class_exists('Zend_Debug')) {
            // replaces < > with &lt; &gt;
            Zend_Debug::dump($xml) . PHP_EOL;
        } else {
            var_dump(htmlspecialchars($xml)) . PHP_EOL;
        }
    }
    decorate('</pre>' . PHP_EOL);
    decorate('</div>' . PHP_EOL);
    cli_decorate('o----' . str_repeat('-', strlen($trace)) . '----o' . PHP_EOL . PHP_EOL);
}