本文整理汇总了PHP中xp::stringOf方法的典型用法代码示例。如果您正苦于以下问题:PHP xp::stringOf方法的具体用法?PHP xp::stringOf怎么用?PHP xp::stringOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xp
的用法示例。
在下文中一共展示了xp::stringOf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: toString
/**
* Creates a string representation of this object. In general, the toString
* method returns a string that "textually represents" this object. The result
* should be a concise but informative representation that is easy for a
* person to read. It is recommended that all subclasses override this method.
*
* Per default, this method returns:
* ```
* [fully-qualified-class-name] '{' [members-and-value-list] '}'
* ```
*
* Example:
* ```
* lang.Object {
* __id => "0.43080500 1158148350"
* }
* ```
*
* @return string
*/
public function toString()
{
if (!$this->__id) {
$this->__id = uniqid('', true);
}
return \xp::stringOf($this);
}
示例2: locate
/**
* Locate a font
*
* @param string font
* @return string
*/
protected function locate($font)
{
$windows = strncasecmp(PHP_OS, 'Win', 3) === 0;
// Compile extension list
$extensions = ['.ttf', '.TTF'];
if (strncasecmp($ext = substr($font, -4, 4), '.ttf', 4) === 0) {
$font = substr($font, 0, -4);
$extensions[] = $ext;
}
// Compose TTF search path
if ($windows) {
$search = ['.\\', getenv('WINDIR') . '\\fonts\\'];
} else {
$search = ['./', '/usr/X11R6/lib/X11/fonts/TrueType/', '/usr/X11R6/lib/X11/fonts/truetype/', '/usr/X11R6/lib/X11/fonts/TTF/', '/usr/share/fonts/TrueType/', '/usr/share/fonts/truetype/', '/usr/openwin/lib/X11/fonts/TrueType/'];
}
// Check for absolute filenames
if (DIRECTORY_SEPARATOR === $font[0] || $windows && strlen($font) > 1 && (':' === $font[1] || '/' === $font[0])) {
array_unshift($search, dirname($font) . DIRECTORY_SEPARATOR);
$font = basename($font);
}
// Search
foreach ($search as $dir) {
foreach ($extensions as $ext) {
if (file_exists($q = $dir . $font . $ext)) {
return $q;
}
}
}
throw new \lang\IllegalArgumentException('Could not locate font "' . $font . '[' . implode(', ', $extensions) . ']" in ' . \xp::stringOf($search));
}
示例3: findEntry
/**
* Find an entry
*
* @param string name
* @return peer.ftp.FtpEntry entry or NULL if nothing was found
* @throws io.IOException in case listing fails
* @throws peer.ProtocolException in case listing yields an unexpected result
*/
protected function findEntry($name)
{
if (NULL === ($list = $this->connection->listingOf($this->name . $name, '-ald'))) {
return NULL;
// Not found
}
// If we get more than one result and the first result ends with a
// dot, the server ignored the "-d" option and listed the directory's
// contents instead. In this case, replace the "." by the directory
// name. Otherwise, we don't expect more than one result!
$entry = $list[0];
if (($s = sizeof($list)) > 1) {
if ('.' === $entry[strlen($entry) - 1]) {
$entry = substr($entry, 0, -1) . basename($name);
} else {
throw new ProtocolException('List "' . $this->name . $name . '" yielded ' . $s . ' result(s), expected: 1 (' . xp::stringOf($list) . ')');
}
}
// Calculate base
$base = $this->name;
if (FALSE !== ($p = strrpos(rtrim($name, '/'), '/'))) {
$base .= substr($name, 0, $p + 1);
}
return $this->connection->parser->entryFrom($entry, $this->connection, $base);
}
示例4: process
/**
* Processes cell value
*
* @param var in
* @return var
* @throws lang.FormatException
*/
public function process($in)
{
if (!(null === $in || is_numeric($in))) {
throw new \lang\FormatException('Cannot format non-number ' . \xp::stringOf($in));
}
return $this->proceed(number_format($in, $this->decimals, $this->decimalPoint, $this->thousandsSeparator));
}
示例5: verify
/**
* Executes this check
*
* @param xp.compiler.ast.Node node
* @param xp.compiler.types.Scope scope
* @return bool
*/
public function verify(\xp\compiler\ast\Node $node, \xp\compiler\types\Scope $scope)
{
$a = \cast($node, 'xp.compiler.ast.AssignmentNode');
if (!$this->isWriteable($a->variable)) {
return ['A403', 'Cannot assign to ' . ($a->variable instanceof \lang\Generic ? nameof($a->variable) : \xp::stringOf($a->variable)) . 's'];
}
}
示例6: 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;
}
示例7: setAlgorithm
/**
* Register an algorithm
*
* @param string name
* @param lang.XPClass<security.password.Algorithm> impl
* @throws lang.IllegalArgumentException in case the given class is not an Algorithm
*/
public static function setAlgorithm($name, \lang\XPClass $impl)
{
if (!$impl->isSubclassOf('security.password.Algorithm')) {
throw new \lang\IllegalArgumentException('Given argument is not an Algorithm class (' . \xp::stringOf($impl) . ')');
}
self::$algorithms[$name] = $impl;
}
示例8: __construct
/**
* Constructor. Accepts one of the following:
*
* <ul>
* <li>The values TRUE or FALSE</li>
* <li>An integer - any non-zero value will be regarded TRUE</li>
* <li>The strings "true" and "false", case-insensitive</li>
* <li>Numeric strings - any non-zero value will be regarded TRUE</li>
* </ul>
*
* @param var value
* @throws lang.IllegalArgumentException if value is not acceptable
*/
public function __construct($value)
{
if (TRUE === $value || FALSE === $value) {
$this->value = $value;
} else {
if (is_int($value)) {
$this->value = 0 !== $value;
} else {
if ('0' === $value) {
$this->value = FALSE;
} else {
if (is_string($value) && ($l = strlen($value)) && strspn($value, '1234567890') === $l) {
$this->value = TRUE;
} else {
if (0 === strncasecmp($value, 'true', 4)) {
$this->value = TRUE;
} else {
if (0 === strncasecmp($value, 'false', 5)) {
$this->value = FALSE;
} else {
throw new IllegalArgumentException('Not a valid boolean: ' . xp::stringOf($value));
}
}
}
}
}
}
}
示例9: export
/**
* Export this keypair
*
* @param string passphrase default NULL
* @return string key
*/
public function export($passphrase = null)
{
if (false === openssl_pkey_export($this->_res, $out, $passphrase)) {
throw new SecurityException('Could not export key: ' . \xp::stringOf(OpenSslUtil::getErrors()));
}
return $out;
}
示例10: process
/**
* Processes cell value
*
* @param var in
* @return var
* @throws lang.FormatException
*/
public function process($in)
{
if (!$in->getClass()->isEnum()) {
throw new FormatException('Cannot format non-enum ' . xp::stringOf($in));
}
return $this->proceed($in->name());
}
示例11: get
public function get($key)
{
$offset = $key instanceof Generic ? $key->hashCode() : serialize($key);
if (!isset($this->elements[$offset])) {
throw new NoSuchElementException('No such key ' . xp::stringOf($key));
}
return $this->elements[$offset];
}
示例12: expect
/**
* Parser helper function
*
* @param text.Tokenizer $st
* @param string $tokens
* @return string
* @throws lang.FormatException
*/
private function expect($st, $tokens)
{
$parsed = $st->nextToken($tokens);
if (false === strpos($tokens, $parsed)) {
throw new FormatException('Expected [' . $tokens . '], have ' . \xp::stringOf($parsed));
}
return $parsed;
}
示例13: toString
/**
* Creates a string representation of this node.
*
* @return string
*/
public function toString()
{
$s = nameof($this) . '(line ' . $this->position[0] . ', offset ' . $this->position[1] . ")@{\n";
foreach (get_object_vars($this) as $name => $value) {
'__id' !== $name && 'position' !== $name && 'holder' !== $name && ($s .= sprintf(" [%-20s] %s\n", $name, str_replace("\n", "\n ", \xp::stringOf($value))));
}
return $s . '}';
}
示例14: stringOf
/**
* Returns a string representation
*
* @param var $val
* @param string $default the value to use for NULL
* @return string
*/
public static function stringOf($val, $default = '')
{
if (null === $val) {
return $default;
} else {
return \xp::stringOf($val);
}
}
示例15: get
public function get($key)
{
$offset = $key->literal();
if (!isset($this->elements[$offset])) {
throw new NoSuchElementException('No such key ' . xp::stringOf($key));
}
return $this->elements[$offset];
}