/** {@inheritDoc}. */
 public function buildFinished(BuildEvent $event)
 {
     $this->log("< BUILD FINISHED", Project::MSG_DEBUG);
     if ($this->record && $this->out != null) {
         $error = $event->getException();
         if ($error == null) {
             $this->out->write(Phing::getProperty('line.separator') . "BUILD SUCCESSFUL" . PHP_EOL);
         } else {
             $this->out->write(Phing::getProperty('line.separator') . "BUILD FAILED" . Phing::getProperty('line.separator') . PHP_EOL);
             $this->out->write($error->getTraceAsString());
         }
     }
     $this->cleanup();
 }
 /**
  * Constructor
  *
  * @param   io.streams.OutputStream out
  * @param   int level default 6
  * @throws  lang.IllegalArgumentException if the level is not between 0 and 9
  */
 public function __construct(OutputStream $out, $level = 6)
 {
     if ($level < 0 || $level > 9) {
         throw new \lang\IllegalArgumentException('Level ' . $level . ' out of range [0..9]');
     }
     // Write GZIP format header:
     // * ID1, ID2 (Identification, \x1F, \x8B)
     // * CM       (Compression Method, 8 = deflate)
     // * FLG      (Flags, use 0)
     // * MTIME    (Modification time, Un*x timestamp)
     // * XFL      (Extra flags, 2 = compressor used maximum compression)
     // * OS       (Operating system, 255 = unknown)
     $out->write(pack('CCCCVCC', 0x1f, 0x8b, 8, 0, time(), 2, 255));
     // Now, convert stream to file handle and append deflating filter
     $this->out = Streams::writeableFd($out);
     if (!($this->filter = stream_filter_append($this->out, 'zlib.deflate', STREAM_FILTER_WRITE, $level))) {
         fclose($this->out);
         $this->out = null;
         throw new \io\IOException('Could not append stream filter');
     }
     $this->md = hash_init('crc32b');
 }
Пример #3
0
 /**
  * Prints a message to console.
  * 
  * @param string $message  The message to print. 
  *                 Should not be <code>null</code>.
  * @param resource $stream The stream to use for message printing.
  * @param int $priority The priority of the message. 
  *                 (Ignored in this implementation.)
  * @return void
  */
 protected function printMessage($message, OutputStream $stream, $priority)
 {
     $stream->write($message . PHP_EOL);
 }
Пример #4
0
 /**
  * The thing that actually sends the information to the output.
  *
  * @param string $mesg The message to log.
  * @param int $level The verbosity level of the message.
  */
 private function log($mesg, $level)
 {
     if ($this->record && $level <= $this->loglevel && $this->out != null) {
         $this->out->write($mesg . PHP_EOL);
     }
 }
Пример #5
0
 /**
  * Prints a message to console.
  * 
  * @param string $message  The message to print. 
  *                 Should not be <code>null</code>.
  * @param resource $stream The stream to use for message printing.
  * @param int $priority The priority of the message. 
  *                 (Ignored in this implementation.)
  * @return void
  */
 protected function printMessage($message, OutputStream $stream, $priority)
 {
     $stream->write($message . $this->lSep);
 }
 /**
  * @see DefaultLogger#printMessage
  * @param string $message
  * @param OutputStream $stream
  * @param int $priority
  */
 protected final function printMessage($message, OutputStream $stream, $priority)
 {
     if ($message !== null) {
         if (!$this->colorsSet) {
             $this->setColors();
             $this->colorsSet = true;
         }
         switch ($priority) {
             case Project::MSG_ERR:
                 $message = $this->errColor . $message . self::END_COLOR;
                 break;
             case Project::MSG_WARN:
                 $message = $this->warnColor . $message . self::END_COLOR;
                 break;
             case Project::MSG_INFO:
                 $message = $this->infoColor . $message . self::END_COLOR;
                 break;
             case Project::MSG_VERBOSE:
                 $message = $this->verboseColor . $message . self::END_COLOR;
                 break;
             case Project::MSG_DEBUG:
                 $message = $this->debugColor . $message . self::END_COLOR;
                 break;
         }
         $stream->write($message . PHP_EOL);
     }
 }
 /**
  * Write char data to stream.
  *
  * @param unknown_type $buf
  * @param unknown_type $off
  * @param unknown_type $len
  * @return unknown
  */
 public function write($buf, $off = null, $len = null)
 {
     return $this->outStream->write($buf, $off, $len);
 }
 /**
  * Output the properties as xml output.
  *
  * @param Properties   $props the properties to save
  * @param OutputStream $os    the output stream to write to (Note this gets closed)
  *
  * @throws BuildException
  */
 protected function xmlSaveProperties(Properties $props, OutputStream $os)
 {
     $doc = new DOMDocument('1.0', 'UTF-8');
     $doc->formatOutput = true;
     $rootElement = $doc->createElement(self::$PROPERTIES);
     $properties = $props->getProperties();
     ksort($properties);
     foreach ($properties as $key => $value) {
         $propElement = $doc->createElement(self::$PROPERTY);
         $propElement->setAttribute(self::$ATTR_NAME, $key);
         $propElement->setAttribute(self::$ATTR_VALUE, $value);
         $rootElement->appendChild($propElement);
     }
     try {
         $doc->appendChild($rootElement);
         $os->write($doc->saveXML());
     } catch (IOException $ioe) {
         throw new BuildException("Unable to write XML file", $ioe);
     }
 }
Пример #9
0
 /**
  * @see DefaultLogger#printMessage
  * @param string $message
  * @param OutputStream $stream
  * @param int $priority
  */
 protected final function printMessage($message, OutputStream $stream, $priority)
 {
     if ($message !== null) {
         if (!$this->colorsSet) {
             $this->setColors();
             $this->colorsSet = true;
         }
         $search = array('<', '>');
         $replace = array('&lt;', '&gt;');
         $message = str_replace($search, $replace, $message);
         $search = array("\t", "\n", "\r");
         $replace = array('&nbsp;&nbsp;&nbsp;', '<br>', '');
         $message = str_replace($search, $replace, $message);
         if (preg_match('@^( +)([^ ].+)@', $message, $matches)) {
             $len = strlen($matches[1]);
             $space = '&nbsp;';
             for ($i = 1; $i < $len; $i++) {
                 $space .= '&nbsp;';
             }
             $message = $space . $matches[2];
         }
         switch ($priority) {
             case Project::MSG_ERR:
                 $message = $this->errColor . $message . self::END_COLOR;
                 break;
             case Project::MSG_WARN:
                 $message = $this->warnColor . $message . self::END_COLOR;
                 break;
             case Project::MSG_INFO:
                 $message = $this->infoColor . $message . self::END_COLOR;
                 break;
             case Project::MSG_VERBOSE:
                 $message = $this->verboseColor . $message . self::END_COLOR;
                 break;
             case Project::MSG_DEBUG:
                 $message = $this->debugColor . $message . self::END_COLOR;
                 break;
         }
         $stream->write($message . '<br>');
     }
 }
Пример #10
0
 /**
  * Serialize and write to output
  *
  * @param  io.streams.OutputStream out
  * @param  webservices.rest.Payload value
  */
 public function write(OutputStream $out, Payload $value = NULL)
 {
     $out->write($this->serializer->serialize($value));
 }
Пример #11
0
 /**
  * Encode PHP data into JSON via stream
  *
  * Gets the PHP data and a stream.<br/>
  * It converts the data to JSON and will put every atom into the stream as soon
  * as it is available.<br/>
  * The usage is similar to encode() except the second argument.
  *
  * @param   var data
  * @param   io.streams.OutputStream stream
  * @return  boolean
  * @throws  webservices.json.JsonException if the data could not be serialized
  */
 public function encodeTo($data, OutputStream $stream)
 {
     switch (gettype($data)) {
         case 'string':
             $stream->write('"' . $this->escape(iconv(xp::ENCODING, 'utf-8', $data)) . '"');
             return TRUE;
         case 'integer':
             $stream->write(strval($data));
             return TRUE;
         case 'double':
             $stream->write(strval($data));
             return TRUE;
         case 'boolean':
             $stream->write($data ? 'true' : 'false');
             return TRUE;
         case 'NULL':
             $stream->write('null');
             return TRUE;
         case 'array':
             if ($this->_isVector($data)) {
                 // Bail out early on bordercase
                 if (0 == sizeof($data)) {
                     $stream->write('[ ]');
                     return TRUE;
                 }
                 $stream->write('[ ');
                 // Get first element
                 $stream->write($this->encode(array_shift($data)));
                 foreach ($data as $value) {
                     $stream->write(' , ' . $this->encode($value));
                 }
                 $stream->write(' ]');
                 return TRUE;
             } else {
                 // Reset array internal pointer
                 reset($data);
                 $stream->write('{ ');
                 $value = each($data);
                 $stream->write($this->encode((string) $value['key']) . ' : ' . $this->encode($value['value']));
                 while ($value = each($data)) {
                     $stream->write(' , ' . $this->encode((string) $value['key']) . ' : ' . $this->encode($value['value']));
                 }
                 $stream->write(' }');
                 return TRUE;
             }
         case 'object':
             // Converts a string object into an normal json string
             if ($data instanceof String) {
                 $stream->write('"' . $this->escape((string) $data->getBytes('utf-8')) . '"');
                 break;
             }
             if ($data instanceof Generic) {
                 if (!method_exists($data, '__sleep')) {
                     $vars = get_object_vars($data);
                 } else {
                     $vars = array();
                     foreach ($data->__sleep() as $var) {
                         $vars[$var] = $data->{$var};
                     }
                 }
                 $this->encodeTo($vars, $stream);
                 return TRUE;
             }
             // Break missing intentially
         default:
             throw new JsonException('Cannot encode data of type ' . gettype($data));
     }
 }
Пример #12
0
 /**
  * Store to an output stream, e.g. a file
  *
  * @param   io.streams.OutputStream out
  * @throws  io.IOException
  */
 public function store(OutputStream $out)
 {
     foreach (array_keys($this->_data) as $section) {
         $out->write(sprintf("[%s]\n", $section));
         foreach ($this->_data[$section] as $key => $val) {
             if (';' == $key[0]) {
                 $out->write(sprintf("\n; %s\n", $val));
             } else {
                 if ($val instanceof Hashmap) {
                     $str = '';
                     foreach ($val->keys() as $k) {
                         $str .= '|' . $k . ':' . $val->get($k);
                     }
                     $val = (string) substr($str, 1);
                 }
                 if (is_array($val)) {
                     $val = implode('|', $val);
                 }
                 if (is_string($val)) {
                     $val = '"' . $val . '"';
                 }
                 $out->write(sprintf("%s=%s\n", $key, strval($val)));
             }
         }
         $out->write("\n");
     }
 }
Пример #13
0
 /**
  * Write markup
  *
  * @param   io.streams.OutputStream
  * @param   string input
  */
 protected function writeMarkup($input, OutputStream $stream)
 {
     $stream->write('<div class="markup"><p>');
     $stream->write(strtr($this->processor->markupFor($input), array('<code>' => '<pre class="code">', '</code>' => '</pre>', '<h1>' => '<h2>', '</h1>' => '</h2>', '<h2>' => '<h3>', '</h2>' => '</h3>', '<h3>' => '<h4>', '</h3>' => '</h4>')));
     $stream->write('</p></div>');
 }
Пример #14
0
 /**
  * Store to an output stream, e.g. a file
  *
  * @param   io.streams.OutputStream out
  * @throws  io.IOException
  */
 public function store(OutputStream $out)
 {
     foreach (array_keys($this->_data) as $section) {
         $out->write('[' . $section . "]\n");
         foreach ($this->_data[$section] as $key => $val) {
             if (';' == $key[0]) {
                 $out->write("\n; " . $val . "\n");
             } else {
                 if (is_array($val)) {
                     if (empty($val)) {
                         $out->write($key . "=\n");
                     } else {
                         if (0 === key($val)) {
                             foreach ($val as $v) {
                                 $out->write($key . '[]=' . $this->quote($v) . "\n");
                             }
                         } else {
                             foreach ($val as $k => $v) {
                                 $out->write($key . '[' . $k . ']=' . $this->quote($v) . "\n");
                             }
                         }
                     }
                 } else {
                     $out->write($key . '=' . $this->quote($val) . "\n");
                 }
             }
         }
         $out->write("\n");
     }
 }