/** * Construct an attachment with a stream and a name. * * @param \Hoa\Stream $stream Stream that contains the attachment. * @param string $name Name of the attachment (if null, will * use the stream basename). * @param string $mimeType Force a MIME type. * @return void */ public function __construct(Stream $stream, $name = null, $mimeType = null) { parent::__construct(); if (null === $name) { if ($stream instanceof Stream\IStream\Pathable) { $name = $stream->getBasename(); } else { $name = basename($stream->getStreamName()); } } if (null === $mimeType) { $mimeType = null; try { $mime = new Mime($stream); $mimeType = $mime->getMime(); } catch (Mime\Exception $e) { } if (null === $mimeType) { $mimeType = 'application/octet-stream'; } } $size = null; if ($stream instanceof Stream\IStream\Statable && false !== ($_size = $stream->getSize())) { $size = '; size=' . $_size; } $this['content-type'] = $mimeType; $this['content-disposition'] = 'attachment; filename="' . str_replace('"', '-', $name) . '"' . $size; $this->setStream($stream); return; }
/** * Open a new string buffer. * * @param string $streamName Stream name. * @return void * @throws \Hoa\Stream\Exception */ public function __construct($streamName = null) { if (null === $streamName) { $streamName = 'hoa://Library/Stringbuffer#' . self::$_i++; } parent::__construct($streamName, null); return; }
/** * Connect. * * @return \Hoa\Socket\Connection */ public function connect() { parent::__construct($this->getSocket()->__toString(), $this->getContext()); $this->_disconnect = false; return $this; }
/** * Start a processus. * * @access public * @param string $command Command name. * @param array $options Command options. * @param array $descriptors Descriptors (descriptor => mode —r, w or * a—). * @param string $cwd Current working directory. * @param array $environment Environment. * @return void * @throw \Hoa\Console\Exception */ public function __construct($command, array $options = null, array $descriptors = null, $cwd = null, array $environment = null, $timeout = 30) { $this->setCommand($command); if (null !== $options) { $this->setOptions($options); } if (null !== $descriptors) { $this->_descriptors = array(); foreach ($descriptors as $descriptor => $nature) { if (isset($this->_descriptors[$descriptor])) { throw new Exception('Pipe descriptor %d already exists, cannot ' . 'redefine it.', 0, $descriptor); } $this->_descriptors[$descriptor] = $nature; } } $this->setCwd($cwd ?: getcwd()); if (null !== $environment) { $this->setEnvironment($environment); } $this->setTimeout($timeout); parent::__construct($this->getCommandLine(), null, true); $this->_on->addIds(array('input', 'output', 'timeout', 'start', 'stop')); return; }