/** * Create a dependency injection container function. * * @return the dependency injection container function */ function dependency_injection_container() : callable { $container = sequence(decorate(container(), function (array $args) use(&$container) { if (is_callable($definition = $args[1] ?? null) && !($args[2] ?? false)) { $args[1] = call_once(set_args($definition, $container)); } return $args; }), conditionally(is_callable, call_user_func, pass_through)); return $container; }
} if (file_exists($prefix . '.append')) { $output = append_file_to_url($_GET['url'], $prefix . '.append'); break 2; } break; } } // set up standard HTTP caching $ten_years = 315569260; header('Cache-Control: max-age=' . $ten_years); // ten years header('Last-Modified: Mon, 29 Jun 1998 02:28:12 GMT'); // it was modifed long ago, so is most likely fresh header("Expires: " . gmdate("D, d M Y H:i:s", time() + $ten_years) . " GMT"); echo decorate($output, $_GET); exit; function append_file_to_url($url, $file) { $output = get_url($url); return str_ireplace('</body>', file_get_contents($file) . '</body>', $output); } /** * Decorates resulting HTML file, replacing %%variables%% with actual values and appending manifest URL to <html> tag. * @param string $text * @param array $variables * @return string */ function decorate($text, $variables = array()) { $text = str_ireplace('<html', '<html manifest="%%manifest%%" ', $text);
/** * 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 < > 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); }