本文整理汇总了PHP中xp::typeOf方法的典型用法代码示例。如果您正苦于以下问题:PHP xp::typeOf方法的具体用法?PHP xp::typeOf怎么用?PHP xp::typeOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xp
的用法示例。
在下文中一共展示了xp::typeOf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __invoke
/**
* Invoke match. Returns the handler's result for the first condition to
* match the given value. If no condition matched and no default handler
* was installed, an exception is raised.
*
* @param var $value
* @return var
* @throws lang.IllegalArgumentException
*/
public function __invoke($value)
{
if ($this->mapping) {
$f = $this->mapping;
$expr = $f($value);
} else {
$expr = $value;
}
if (null === $expr) {
$type = null;
} else {
$type = gettype($expr);
}
if (isset($this->primitive[$type])) {
return $this->primitive[$type]($value, $this);
} else {
foreach ($this->instance as $conditional) {
if ($conditional->condition->matches($expr)) {
$f = $conditional->handle;
return $f($value, $this);
}
}
}
if ($this->otherwise) {
$f = $this->otherwise;
return $f($value, $this);
} else {
throw new IllegalArgumentException('Unhandled type ' . \xp::typeOf($expr));
}
}
示例2: setTrace
/**
* Set a LogCategory for tracing communication
*
* @param util.log.LogCategory $cat pass NULL to stop tracing
* @return void
* @throws lang.IllegalArgumentException in case a of a type mismatch
*/
public function setTrace($cat)
{
if (null !== $cat && !$cat instanceof LogCategory) {
throw new IllegalArgumentException('Expected a LogCategory, have ' . \xp::typeOf($cat));
}
$this->cat = $cat;
}
示例3: send
/**
* Send a message
*
* @param peer.mail.Message message the Message object to send
* @return bool success
*/
public function send($message)
{
// Sanity check: Is this a message?
if (!$message instanceof Message) {
throw new TransportException('Can only send messages (given: ' . xp::typeOf($message) . ')', new IllegalArgumentException('Parameter message is not a Message object'));
}
// Sanity check: Do we have at least one recipient?
$to = '';
for ($i = 0, $s = sizeof($message->to); $i < $s; $i++) {
if (!$message->to[$i] instanceof InternetAddress) {
continue;
}
// Ignore!
$to .= $message->to[$i]->toString($message->getCharset()) . ', ';
}
if (empty($to)) {
throw new TransportException('No recipients defined (recipients[0]: ' . xp::typeOf($message->to[0]), new IllegalArgumentException('Recipient #0 is not an InternetAddress object'));
}
// Copy message and unset To / Subject. PHPs mail() function will add them
// to the mail twice, otherwise
$tmp = clone $message;
unset($tmp->to);
unset($tmp->subject);
if (FALSE === mail(substr($to, 0, -2), QuotedPrintable::encode($message->getSubject(), $message->getCharset()), strtr($message->getBody(), array("\r\n" => "\n", "\r" => "\n")), rtrim($tmp->getHeaderString(), "\n"), $this->parameters)) {
throw new TransportException('Could not send mail to ' . xp::stringOf($message->to[0]), new IOException('Call to mail() failed'));
}
return TRUE;
}
示例4: __construct
/**
* Constructor
*
* @param var stream either an io.streams.OutputStream or an io.Stream (BC)
* @throws lang.IllegalArgumentException when types are not met
*/
public function __construct($stream)
{
$this->stream = deref($stream);
if ($this->stream instanceof OutputStream) {
// Already open
} else {
if ($this->stream instanceof Stream) {
$this->stream->open(STREAM_MODE_WRITE);
} else {
throw new IllegalArgumentException('Expected either an io.streams.OutputStream or an io.Stream, have ' . xp::typeOf($this->stream));
}
}
if (self::$GD_USERSTREAMS_BUG) {
$this->writer = function ($writer, $stream, $handle) {
ob_start();
$r = $writer->output($handle);
if ($r) {
$stream->write(ob_get_contents());
}
ob_end_clean();
return $r;
};
} else {
// Use output buffering with a callback method to capture the
// image(gd|jpeg|png|...) functions' output.
$this->writer = function ($writer, $stream, $handle) {
ob_start(function ($data) use($stream) {
$stream->write($data);
});
$r = $writer->output($handle);
ob_end_flush();
return $r;
};
}
}
示例5: __construct
/**
* Constructor
*
* @param var $arg either an io.streams.OutputStream, an io.File or an io.Stream (BC)
* @throws lang.IllegalArgumentException when types are not met
*/
public function __construct($arg)
{
if ($arg instanceof OutputStream) {
$this->write($arg);
} else {
if ($arg instanceof File) {
$this->write($arg->out());
} else {
if ($arg instanceof Stream) {
// BC
$this->stream = $arg;
$this->writer = function ($writer, $stream, $handle) {
ob_start();
if ($r = $writer->output($handle)) {
$stream->open(STREAM_MODE_WRITE);
$stream->write(ob_get_contents());
$stream->close();
}
ob_end_clean();
return $r;
};
} else {
throw new IllegalArgumentException('Expected either an io.streams.OutputStream or an io.File, have ' . \xp::typeOf($arg));
}
}
}
}
示例6: _assertSubtype
/**
* Checks all entries in an array for correct type
*
* @param string type
* @param &array array
* @throws lang.IllegalArgumentException
*/
protected function _assertSubtype($type, $array)
{
foreach (array_keys($array) as $key) {
if ($type != xp::typeOf($array[$key])) {
throw new IllegalArgumentException('Object (in array) not of expected type ' . $type . ', but ' . xp::typeOf($array[$key]) . ' with value ' . var_export($array[$key], 1));
}
}
}
示例7: toString
/**
* Creates a string representation of this handler
*
* @return string
*/
public function toString()
{
$s = sprintf("%s@{\n" . " [name ] %s\n" . " [identifier ] %s\n" . " [wrapper ] %s\n", nameof($this), $this->name, $this->identifier, $this->wrapper ? nameof($this->wrapper) : '(null)');
foreach (array_keys($this->values[HVAL_PERSISTENT]) as $key) {
$s .= sprintf(" [%-20s] %s\n", $key, \xp::typeOf($this->values[$key]));
}
return $s . '}';
}
示例8: addPart
/**
* Add a Mime Part
*
* @param peer.mail.MimePart part
* @return peer.mail.MimePart the part added
* @throws lang.IllegalArgumentException if part argument is not a peer.mail.MimePart
*/
public function addPart($part)
{
if (!$part instanceof MimePart) {
throw new IllegalArgumentException('Parameter part is not a peer.mail.MimePart (given: ' . \xp::typeOf($part) . ')');
}
$this->parts[] = $part;
return $part;
}
示例9: when
/**
* Define handler for a given key
*
* @param var $key Either a string or an integer
* @param function(?): var $function
* @return self
*/
public function when($key, $function)
{
if (is_string($key) || is_int($key)) {
$this->hash[$key] = self::$HANDLE->cast($function);
} else {
throw new IllegalArgumentException('Illegal key type ' . \xp::typeOf($key));
}
return $this;
}
示例10: box
/**
* Box parameter into soap equivalent
*
* @param lang.Generic object
* @return mixed
* @throws lang.IllegalArgumentException if type is not supported
*/
public function box($object)
{
foreach ($this->handler as $handler => $t) {
if (!$object instanceof $handler) {
continue;
}
return call_user_func(array($this, 'box' . $handler), $object);
}
throw new IllegalArgumentException('Type ' . xp::typeOf($object) . ' is not supported.');
}
示例11: box
/**
* Box parameter into soap equivalent
*
* @param lang.Generic object
* @return mixed
* @throws lang.IllegalArgumentException if type is not supported
*/
public function box($object)
{
foreach ($this->handler as $class => $handler) {
if (!$object instanceof $class) {
continue;
}
return call_user_func([$this, $handler], $object);
}
throw new \lang\IllegalArgumentException('Type ' . \xp::typeOf($object) . ' is not supported.');
}
示例12: initialize
/**
* Initializes the attribute with default values, depending on $type
*
*/
public function initialize()
{
// determine type from value if type is not set
if (isset($this->_value)) {
if (!isset($this->_type)) {
$this->_type = xp::typeOf($this->_value);
}
if ($this->_type === 'integer') {
$this->_type = 'int';
}
if (in_array($this->_type, array('float', 'double'))) {
$this->_type = 'real';
}
if ($this->_type === 'bool') {
$this->_type = 'boolean';
}
$value = $this->_value;
} else {
$value = NULL;
}
// set type if defined
if (isset($this->_type)) {
switch ($this->_type) {
case 'int':
$this->set('value', new DiaInt($value));
break;
case 'real':
$this->set('value', new DiaReal($value));
break;
case 'string':
$this->set('value', new DiaString($value));
break;
case 'boolean':
$this->set('value', new DiaBoolean($value));
break;
case 'enum':
$this->set('value', new DiaEnum($value));
break;
case 'point':
$this->set('value', new DiaPoint($value));
break;
case 'rectangle':
$this->set('value', new DiaRectangle($value));
break;
case 'font':
$this->set('value', new DiaFont($value));
break;
case 'color':
$this->set('value', new DiaColor($value));
break;
default:
throw new IllegalArgumentException('Unkown type "' . $this->_type . '"');
}
}
}
示例13: __construct
/**
* Constructor
*
* @param var stream either an io.streams.OutputStream or an io.Stream (BC)
* @throws lang.IllegalArgumentException when types are not met
*/
public function __construct($stream)
{
$this->stream = deref($stream);
if ($this->stream instanceof OutputStream) {
// Already open
} else {
if ($this->stream instanceof Stream) {
$this->stream->open(STREAM_MODE_WRITE);
} else {
throw new IllegalArgumentException('Expected either an io.streams.OutputStream or an io.Stream, have ' . xp::typeOf($this->stream));
}
}
}
示例14: __construct
/**
* Constructor. Creates a new TextWriter on an underlying output
* stream with a given charset.
*
* @param io.streams.OutputStream|io.Channel $arg The target
* @param string $charset the charset the stream is encoded in.
* @throws lang.IllegalArgumentException
*/
public function __construct($arg, $charset = \xp::ENCODING)
{
if ($arg instanceof OutputStream) {
parent::__construct($arg);
} else {
if ($arg instanceof Channel) {
parent::__construct($arg->out());
} else {
throw new IllegalArgumentException('Given argument is neither an input stream, a channel nor a string: ' . \xp::typeOf($arg));
}
}
$this->charset = $charset;
}
示例15: substract
/**
* Substract a TimeSpan
*
* @param util.TimeSpan... args
* @return util.TimeSpan
* @throws lang.IllegalStateException if the result would be a negative timespan
*/
public function substract()
{
foreach (func_get_args() as $span) {
if (!$span instanceof self) {
throw new IllegalArgumentException('Given argument is not a TimeSpan: ' . xp::typeOf($span));
}
if ($span->_seconds > $this->_seconds) {
throw new IllegalStateException('Cannot subtract ' . $span->toString() . ' from ' . $this->toString());
}
$this->_seconds -= $span->_seconds;
}
return $this;
}