本文整理汇总了PHP中lang\XPClass类的典型用法代码示例。如果您正苦于以下问题:PHP XPClass类的具体用法?PHP XPClass怎么用?PHP XPClass使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了XPClass类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: register
/**
* Register transport implementation for a specific scheme
*
* @param string scheme
* @param lang.XPClass<peer.http.HttpTransport> class
*/
public static function register($scheme, XPClass $class)
{
if (!$class->isSubclassOf('peer.http.HttpTransport')) {
throw new \lang\IllegalArgumentException(sprintf('Given argument must be lang.XPClass<peer.http.HttpTransport>, %s given', $class->toString()));
}
self::$transports[$scheme] = $class;
}
示例2: 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;
}
示例3: qnameFor
/**
* Fetch a qname for a class.
*
* @param lang.XPClass class
* @return var xml.QName or NULL if no mapping exists
*/
public function qnameFor(\lang\XPClass $class)
{
if (!isset($this->_c2q[$class->getName()])) {
return null;
}
return $this->_qnames[$this->_c2q[$class->getName()]];
}
示例4: register
/**
* Register an implementation
*
* @param string algorithm
* @param lang.XPClass<security.checksum.MessageDigestImpl> class
* @throws lang.IllegalArgumentException
*/
public static function register($algorithm, \lang\XPClass $impl)
{
if (!$impl->isSubclassOf('security.checksum.MessageDigestImpl')) {
throw new \lang\IllegalArgumentException('Implementation class must be a security.checksum.MessageDigestImpl');
}
self::$implementations[$algorithm] = $impl;
}
示例5: lineFor
/**
* Tries to get method start line
*
* @param lang.XPClass $class
* @param string $methodname
* @return int
*/
private function lineFor(XPClass $class, $methodname)
{
try {
return $class->reflect()->getMethod($methodname)->getStartLine();
} catch (\Exception $ignored) {
return 0;
}
}
示例6: toCollection
/**
* Creates a new collector gathering the elements in a collection class
*
* @param lang.XPClass $class
* @return util.data.ICollector
*/
public static function toCollection(XPClass $class)
{
return new Collector(function () use($class) {
return $class->newInstance();
}, function ($result, $arg) {
$result->add($arg);
});
}
示例7: interfaceNamed
/**
* Locate interface by a given name
*
* @param lang.XPClass $class
* @param string $name
* @return lang.XPClass
* @throws lang.ElementNotFoundException
*/
private function interfaceNamed($class, $name)
{
foreach ($class->getInterfaces() as $iface) {
if (strstr($iface->getName(), $name)) {
return $iface;
}
}
throw new ElementNotFoundException('Class ' . $class->getName() . ' does not implement ' . $name);
}
示例8: methodsAnnotatedWith
/**
* Returns methods annotated with a given annotatoons
*
* @param lang.XPClass $self
* @param string $annotation
* @return lang.reflect.Method[]
*/
public static function methodsAnnotatedWith(\lang\XPClass $self, $annotation)
{
$name = substr($annotation, 1);
$r = array();
foreach ($self->getMethods() as $method) {
if ($method->hasAnnotation($name)) {
$r[] = $method;
}
}
return $r;
}
示例9: permutationOf
/**
* Add a measurable class
*
* @param lang.XPClass $class
* @param lang.reflect.Method $method
* @param var $source
* @return util.data.Sequence
*/
private function permutationOf($class, $method, $source)
{
if (is_array($source)) {
$seq = Sequence::of($source);
} else {
$seq = Sequence::of($class->getMethod($source)->setAccessible(true)->invoke(null));
}
return $seq->map(function ($args) use($class, $method) {
return $class->newInstance($method, (array) $args);
});
}
示例10: __construct
/**
* Constructor
*
* @param lang.XPClass $scriptlet
* @param string[] args
* @param [:string] env
*/
public function __construct(XPClass $scriptlet, $args, $env = [], $filters = [])
{
if ($scriptlet->hasConstructor()) {
$this->scriptlet = $scriptlet->getConstructor()->newInstance((array) $args);
} else {
$this->scriptlet = $scriptlet->newInstance();
}
foreach ($filters as $filter) {
$this->scriptlet->filter($filter);
}
$this->scriptlet->init();
$this->env = $env;
}
示例11: commandUsage
/**
* Show usage
*
* @param lang.XPClass class
* @return void
*/
protected function commandUsage(XPClass $class)
{
// Description
if (null !== ($comment = $class->getComment())) {
self::$err->writeLine(self::textOf($comment));
self::$err->writeLine(str_repeat('=', 72));
}
$extra = $details = $positional = [];
foreach ($class->getMethods() as $method) {
if (!$method->hasAnnotation('arg')) {
continue;
}
$arg = $method->getAnnotation('arg');
$name = strtolower(preg_replace('/^set/', '', $method->getName()));
$comment = self::textOf($method->getComment());
if (0 == $method->numParameters()) {
$optional = true;
} else {
list($first, ) = $method->getParameters();
$optional = $first->isOptional();
}
if (isset($arg['position'])) {
$details['#' . ($arg['position'] + 1)] = $comment;
$positional[$arg['position']] = $name;
} else {
if (isset($arg['name'])) {
$details['--' . $arg['name'] . ' | -' . (isset($arg['short']) ? $arg['short'] : $arg['name'][0])] = $comment;
$extra[$arg['name']] = $optional;
} else {
$details['--' . $name . ' | -' . (isset($arg['short']) ? $arg['short'] : $name[0])] = $comment;
$extra[$name] = $optional;
}
}
}
// Usage
asort($positional);
self::$err->write('Usage: $ xpcli ', Commands::nameOf($class), ' ');
foreach ($positional as $name) {
self::$err->write('<', $name, '> ');
}
foreach ($extra as $name => $optional) {
self::$err->write($optional ? '[' : '', '--', $name, $optional ? '] ' : ' ');
}
self::$err->writeLine();
// Argument details
self::$err->writeLine('Arguments:');
foreach ($details as $which => $comment) {
self::$err->writeLine('* ', $which, "\n ", str_replace("\n", "\n ", $comment), "\n");
}
}
示例12: commandUsage
/**
* Shows usage
*
* @param lang.XPClass $class
* @return void
*/
protected function commandUsage(XPClass $class)
{
$comment = $class->getComment();
if ('' === (string) $comment) {
$markdown = '# ' . $class->getSimpleName() . "\n\n";
$text = '';
} else {
@(list($headline, $text) = explode("\n", $comment, 2));
$markdown = '# ' . ltrim($headline, ' #') . "\n\n";
}
$markdown .= "- Usage\n ```sh\n\$ xp cmd " . Commands::nameOf($class);
$extra = $details = $positional = [];
foreach ($class->getMethods() as $method) {
if (!$method->hasAnnotation('arg')) {
continue;
}
$arg = $method->getAnnotation('arg');
$name = strtolower(preg_replace('/^set/', '', $method->getName()));
$optional = 0 === $method->numParameters() || $method->getParameters()[0]->isOptional();
$comment = $method->getComment();
if (isset($arg['position'])) {
$details[$name] = [$comment, null];
$positional[$arg['position']] = $name;
} else {
if (isset($arg['name'])) {
$details['--' . $arg['name']] = [$comment, isset($arg['short']) ? $arg['short'] : $arg['name'][0]];
$extra[$arg['name']] = $optional;
} else {
$details['--' . $name] = [$comment, isset($arg['short']) ? $arg['short'] : $name[0]];
$extra[$name] = $optional;
}
}
}
// Usage
asort($positional);
foreach ($positional as $name) {
$markdown .= ' ' . $name;
}
foreach ($extra as $name => $optional) {
$markdown .= ' ' . (($optional ? '[' : '') . '--' . $name . ($optional ? '] ' : ' '));
}
$markdown .= "\n ```\n";
// Argument details
foreach ($details as $which => $detail) {
$markdown .= sprintf(" **%s**: %s%s\n\n", $which, str_replace("\n", "\n ", $detail[0]), $detail[1] ? ' *(also: -' . $detail[1] . ')*' : '');
}
Help::render(self::$err, substr($markdown, 0, -1) . $text, $class->getClassLoader());
}
示例13: putParameters
public function putParameters()
{
$params = $this->fixture->getClass()->getMethod('put')->getParameters();
$this->assertEquals(2, sizeof($params));
$this->assertEquals(Primitive::$STRING, $params[0]->getType());
$this->assertEquals(XPClass::forName('unittest.TestCase'), $params[1]->getType());
}
示例14: object_return_type
public function object_return_type()
{
$fixture = $this->define('{
public function fixture(): \\lang\\Object { return new \\lang\\Object(); }
}');
$this->assertEquals(XPClass::forName('lang.Object'), $this->newFixture($fixture)->methods()->named('fixture')->returns());
}
示例15: __construct
/**
* Creates a new instance
*
* @param string $source
* @param xp.scriptlet.Config $config
* @throws lang.IllegalArgumentException
*/
public function __construct($source, Config $config = null)
{
if ('-' === $source) {
$this->layout = new ServeDocumentRootStatically();
} else {
if (is_file($source)) {
$this->layout = new WebConfiguration(new Properties($source), $config);
} else {
if (is_dir($source)) {
$this->layout = new BasedOnWebroot($source, $config);
} else {
$name = ltrim($source, ':');
try {
$class = XPClass::forName($name);
} catch (ClassLoadingException $e) {
throw new IllegalArgumentException('Cannot load ' . $name, $e);
}
if ($class->isSubclassOf('xp.scriptlet.WebLayout')) {
if ($class->hasConstructor()) {
$this->layout = $class->getConstructor()->newInstance([$config]);
} else {
$this->layout = $class->newInstance();
}
} else {
if ($class->isSubclassOf('scriptlet.HttpScriptlet')) {
$this->layout = new SingleScriptlet($class->getName(), $config);
} else {
throw new IllegalArgumentException('Expecting either a scriptlet or a weblayout, ' . $class->getName() . ' given');
}
}
}
}
}
}