/** * @param string $command * @param array|null &$output * @param int|null &$retval * @return string */ function proc_exec($command, &$output = array(), &$retval = null) { $descriptors = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w")); $res = proc_open($command, $descriptors, $pipes); fclose($pipes[0]); $stdout = stream_get_contents($pipes[1]); fclose($pipes[1]); $stderr = stream_get_contents($pipes[2]); fclose($pipes[2]); $output = explode(PHP_EOL, $stdout); $retval = proc_close($res); if (0 !== $retval) { logger_log("Process returned error." . PHP_EOL . " * Cli: " . $command . PHP_EOL . " * Return value: " . $retval . PHP_EOL . " * Stderr: " . PHP_EOL . str_indent($stderr, 1) . PHP_EOL . " * Stdout: " . PHP_EOL . str_indent($stdout, 1) . PHP_EOL); debug_assert(false); // FIXME: should be enforce but i wont risk it now } $ol = count($output); return $ol > 0 ? $output[$ol - 1] : ''; }
<h1><span><?php echo $this->_['title_long']; ?> </span></h1> <div id="container"> <div class="sec-1" id="content"> <?php str_indent($this->_['content'], 4); ?> </div> <?php if ($this->_['info']) { ?> <div class="sec-2"> <?php str_indent($this->_['info'], 4); ?> </div> <?php } ?> </div> <?php include 'about.tpl.php'; ?> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script type="text/javascript"> $('#sf legend').click(function(){$('#sf input').hide();}); </script> </body> </html>
/** * @param \Exception $exception * @param string $eol * @return string */ function exception_str($exception, $eol = null) { if ($eol === null) { $eol = "\n"; } $ret = ''; $prefix = "Uncaught"; if (debug_assert($exception instanceof \Exception)) { do { $class = get_class($exception); $msg = $exception->getMessage(); $file = $exception->getFile(); $line = $exception->getLine(); $trace = backtrace_string(0, $exception->getTrace()); $ret .= "{$prefix} {$class} in {$file}:{$line}" . $eol . str_indent("Message:" . $eol . implode($eol, array_map_val(explode($eol, $msg), function ($val, $key) { return str_indent($val, 1); })), 1) . $eol; if (!empty($trace)) { $ret .= str_indent("Backtrace:" . $eol . str_indent($trace, 1), 1) . $eol; } $prefix = "Caused by"; $exception = $exception->getPrevious(); } while ($exception !== null); } return $ret; }
if (!function_exists('parallel_each_dg')) { function parallel_each_dg($callable, $array = null) { if ($array === null) { $array = tuple_get(0); } elseif (!is_callable($array)) { $array = return_dg($array); } return function () use($callable, $array) { $args = func_get_args(); parallel_each(call_user_func_array($array, $args), $callable); }; } } $cli_format_error = function ($cmd, $message, $stderr) { $err = $stderr ? 'StdErr:' . PHP_EOL . str_indent($stderr, 1) . PHP_EOL : ''; return "Message: {$message}" . PHP_EOL . "Command: {$cmd}" . PHP_EOL . $err; }; if (!function_exists('parallel_exec')) { /** * @param array $commands * @param callable $onerror ($command,$code,$stderr) * @return array */ function parallel_exec($commands, $onerror = null) { $spec = array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w')); $errors = array(); $ret = array(); foreach (array_chunk($commands, hw_core_get(), true) as $chunk) { $processes = array();
/** * @param int $counter * @param string $character * @return callable */ function str_indent_dg($counter = 1, $character = "\t") { return function () use($counter, $character) { $str = func_get_arg(0); return str_indent($str, $counter, $character); }; }
/** * @param string|\Exception $message * @param int $level * @return null * * @see Zend_Log::WARN * @see LOG_WARNING * * @throws \Exception */ function logger_log($message, $level = LOG_INFO) { global $logger; $eol = "\n"; $indent = "\t"; debug_assert(is_callable($logger), "Logger is not callable. Type: " . gettype($logger)); if ($message instanceof \Exception) { $message = exception_str($message, $eol); if (isset($_SERVER['REQUEST_URI']) && !empty($_SERVER['REQUEST_URI'])) { $message .= str_indent("REQUEST:" . $eol . str_indent($_SERVER['REQUEST_URI'], 1, $indent), 1, $indent) . $eol; } if (isset($_POST) && !empty($_POST)) { $message .= str_indent("PARAMS POST:" . $eol . str_indent(json_encode($_POST), 1, $indent), 1, $indent) . $eol; } if (isset($_SERVER) && !empty($_SERVER)) { $message .= str_indent("SERVER:" . $eol . str_indent(json_encode($_SERVER), 1, $indent), 1, $indent) . $eol; } } $logger($message, $level); return null; }