/** * Get connection * * @param string url * @return peer.http.HttpConnection */ protected function getConnection($url = null) { if (null === $url) { throw new \lang\IllegalArgumentException(nameof($this) . ' requires a URL as its argument'); } return new HttpConnection($url); }
/** * 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']; } }
/** * Creates a string representation of this iterator * * @return string */ public function toString() { $s = nameof($this) . '(' . $this->_size . ")@{\n"; for ($i = 0; $i < $this->_size; $i++) { $s .= ' ' . \xp::stringOf($this->list[$i], ' ') . "\n"; } return $s . '}'; }
public function class_name_of_generic_package_class() { $instance = newinstance('net.xp_framework.unittest.core.generics.ArrayFilter<lang.Object>', [], '{ protected function accept($e) { return true; } }'); $n = nameof($instance); $this->assertEquals('net.xp_framework.unittest.core.generics.ArrayFilter··lang¦Object', substr($n, 0, strrpos($n, '·')), $n); }
/** * Creates a string representation * * @return string */ public function toString() { $s = nameof($this) . "@[\n"; foreach ($this as $const) { $s .= ' ' . (string) $const . "\n"; } return $s . ']'; }
/** * Creates a string representation of this Operator * * @return string */ public function toString() { $signature = ''; foreach ($this->parameters as $parameter) { $signature .= ', ' . $parameter->compoundName(); } return sprintf('%s<%s %s %s(%s)>', nameof($this), implode(' ', \lang\reflect\Modifiers::namesOf($this->modifiers)), $this->returns->compoundName(), $this->symbol, substr($signature, 2)); }
/** * Fluent interface * * @param string name * @param var[] args * @return var */ public function __call($name, $args) { if (method_exists($this->finder, $name)) { return $this->select($this->finder->{$name}(...$args)); } else { throw new FinderException('No such method ' . $name . ' in ' . nameof($this->finder)); } }
/** * Creates a string representation of this tolerance instance. * * @return string */ public function toString() { if ($this->past === $this->future) { return nameof($this) . '(' . $this->future . ')'; } else { return nameof($this) . '([' . $this->past . '..+' . $this->future . '])'; } }
/** * Creates a string representation * * @return string */ public function toString() { $s = nameof($this) . "@{\n"; foreach ($this->keys as $target => $source) { $s .= ' ' . $target . ' => ' . $this->source . '.' . $source . "\n"; } return $s . '}'; }
/** * Creates a string representation of this object * * @return string */ public function toString() { $s = nameof($this) . '(' . $this->impl->size() . ")@{\n"; foreach ($this->impl->keys() as $key) { $s .= sprintf(" [%-20s] %s\n", $key->getSimpleName(), nameof($this->impl->get($key))); } return $s . '}'; }
/** * 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 . '}'; }
/** * Creates a string representation * * @return string */ public function toString() { $s = nameof($this) . "@{\n"; foreach ($this->nodes as $row) { $s .= ' ' . $row->toString() . "\n"; } return $s . '}'; }
/** * Defines a type * * @param string $declaration * @param string[] $extends * @return lang.XPClass */ protected function define($declaration, $extends = [Object::class]) { if (!isset(self::$fixtures[$declaration])) { $definition = ['kind' => 'class', 'extends' => $extends, 'implements' => [], 'use' => [], 'imports' => [Identity::class => null]]; self::$fixtures[$declaration] = ClassLoader::defineType(nameof($this) . sizeof(self::$fixtures), $definition, $declaration); } return self::$fixtures[$declaration]; }
/** * Creates a string representation of this result set * * @return string */ public function toString() { $entries = ''; foreach ($this->entries as $entry) { $entries .= ' ' . str_replace("\n", "\n ", $entry->toString()) . "\n"; } return sprintf("%s(total ~ %d%s)@{\n%s}", nameof($this), $this->total, $this->filtered ? ', filtered' : '', $entries); }
public function passes_args_to_constructor() { $fixture = newinstance(Object::class, [], '{ public $passed= null; public function __construct(... $args) { $this->passed= $args; } }'); $this->assertEquals(['Test', 1], (new NewInstance(nameof($fixture), [new Value('Test'), new Value(1)]))->resolve($this->source)->passed); }
/** @return string */ public function toString() { $s = nameof($this) . '<' . $this->uri . '>'; foreach ($this->params as $param => $value) { $s .= '; ' . $param . '="' . $value . '" '; } return substr($s, 0, -1); }
/** * Creates a string representation of this method * * @return string */ public function toString() { $signature = ''; foreach ($this->parameters as $parameter) { $signature .= ', ' . $parameter->toString(); } return sprintf('%s<%s __construct(%s)>', nameof($this), implode(' ', \lang\reflect\Modifiers::namesOf($this->modifiers)), substr($signature, 2)); }
/** * 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 . '}'; }
/** * Add test result node, if it does not yet exist. * * @param unittest.TestCase case * @return xml.Node */ protected function testNode(TestCase $case) { $class = nameof($case); if (!isset($this->classes[$class])) { $this->classes[$class] = $this->tree->addChild(new \xml\Node('testsuite', null, ['name' => $class->getName(), 'file' => $this->uriFor($class), 'tests' => 0, 'failures' => 0, 'errors' => 0, 'skipped' => 0, 'time' => 0])); } return $this->classes[$class]; }
/** * Creates a string representation of this node * * @return string */ public function toString() { $s = nameof($this) . "@[\n"; foreach ($this->nodes as $node) { $s .= ' ' . $node->toString() . "\n"; } return $s . ']'; }
public function register_algorithm() { $algorithm = newinstance(Algorithm::class, [], ['strengthOf' => function ($password) { return 0; }]); PasswordStrength::setAlgorithm('test', typeof($algorithm)); $this->assertInstanceOf(nameof($algorithm), PasswordStrength::getAlgorithm('test')); }
/** * Creates a string representation * * @return string */ public function toString() { $s = ''; foreach ($this->nodes as $node) { $s .= ' ' . str_replace("\n", "\n ", $node->toString()) . "\n"; } return nameof($this) . "@{\n" . "urls : " . \xp::stringOf($this->urls) . "\n" . "nodes : [\n" . $s . "]\n" . "}"; }
public function longClassUsage() { $command = $this->newCommand(); $return = $this->runWith([nameof($command), '--help']); $this->assertEquals(0, $return); $this->assertOnStream($this->err, '$ xp cmd ' . nameof($command)); $this->assertEquals('', $this->out->getBytes()); $this->assertFalse($command->wasRun()); }
/** * Wraps around a function which defines types, giving it unique names and * verifying the type has not been defined before. * * @param string $annotations * @param string $name Uses a unique name if NULL is passed * @param var $define A function * @return lang.XPClass * @throws unittest.AssertionFailedError */ protected function defineType($annotations, $name, $define) { $t = $name ?: nameof($this) . '__' . $this->name; $spec = trim($annotations . ' ' . $t); if (interface_exists(literal($t), false) || class_exists(literal($t), false)) { $this->fail('Type may not exist!', $t, null); } return $define($spec); }
/** * Load the class by the specified name * * @param string class fully qualified class name io.File * @return string class name * @throws lang.ClassNotFoundException in case the class can not be found * @throws lang.ClassFormatException in case the class format is invalud */ public function loadClass0($class) { $name = strtr($class, '.', '\\'); if (isset(\xp::$cl[$class])) { return $name; } // Load class \xp::$cl[$class] = nameof($this) . '://' . $this->path; \xp::$cll++; try { $r = (include $this->classUri($class)); } catch (ClassLoadingException $e) { unset(\xp::$cl[$class]); \xp::$cll--; // If class was declared, but loading threw an exception it means // a "soft" dependency, one that is only required at runtime, was // not loaded, the class itself has been declared. if (class_exists($name, false) || interface_exists($name, false) || trait_exists($name, false)) { throw new ClassDependencyException($class, [$this], $e); } // If otherwise, a "hard" dependency could not be loaded, eg. the // base class or a required interface and thus the class could not // be declared. throw new ClassLinkageException($class, [$this], $e); } \xp::$cll--; if (false === $r) { unset(\xp::$cl[$class]); $e = new ClassNotFoundException($class, [$this]); \xp::gc(__FILE__); throw $e; } else { if (!class_exists($name, false) && !interface_exists($name, false) && !trait_exists($name, false)) { $details = XPClass::detailsForClass($class); $uri = $this->classUri($class); unset(\xp::$cl[$class]); if (isset($details['class'])) { $reflect = new \ReflectionClass($details['class'][DETAIL_ARGUMENTS]); \xp::$errors[$uri][$reflect->getStartLine()] = ['' => 1]; $e = new ClassFormatException('File does not declare type `' . $class . '`, but `' . strtr($reflect->getName(), '\\', '.') . '`'); \xp::gc($uri); throw $e; } else { throw new ClassFormatException('Loading `' . $class . '`: No types declared in ' . $this->classUri($class)); } } } method_exists($name, '__static') && (\xp::$cli[] = [$name, '__static']); if (0 === \xp::$cll) { $invocations = \xp::$cli; \xp::$cli = []; foreach ($invocations as $inv) { $inv($name); } } return $name; }
/** * Iterates on a given list * * @param string[] list * @return string[] results each element as {qualified.className}({elementName}) */ protected function iterationOn($list) { $it = new FtpListIterator($list, $this->conn); $r = []; foreach ($it as $entry) { $r[] = nameof($entry) . '(' . $entry->getName() . ')'; } return $r; }
/** * Create a string representation of this list * * @return string */ public function toString() { $s = sizeof($this->items); $r = sprintf("%s (operator='%s',#items=%d,truncated=%s)@{\n", nameof($this), $this->operator, $s, var_export($this->truncated, 1)); for ($i = 0; $i < $s; $i++) { $r .= ' ' . \xp::stringOf($this->items[$i], ' ') . "\n"; } return $r .= '}'; }
/** * Returns segments with a given class * * @param var type either a class name or an XPClass instance * @return img.io.Segment[] */ public function segmentsOf($type) { $class = $type instanceof \lang\XPClass ? $type->getName() : $type; $r = []; foreach ($this->segments as $segment) { if (nameof($segment) === $class) { $r[] = $segment; } } return $r; }
/** @return void */ public function setUp() { $env = strtoupper($this->driverName()) . '_DSN'; if (!($this->dsn = getenv($env))) { throw new PrerequisitesNotMetError('No credentials for ' . nameof($this) . ', use ' . $env . ' to set'); } try { $this->conn = DriverManager::getConnection($this->dsn); } catch (Throwable $t) { throw new PrerequisitesNotMetError($t->getMessage(), $t); } }
/** * Returns a varargs method with a given signature. Uses caching. * * @param string $signature * @return string[] A reference to the method */ private function compile($signature, $apidoc = []) { $class = nameof($this) . md5($signature); if (!isset(self::$compiled[$class])) { self::$compiled[$class] = ClassLoader::defineClass($class, 'lang.Object', [], '{ /** ' . implode("\n* ", $apidoc) . ' */ public static function fixture(' . $signature . ') { } }'); } return [$class, 'fixture']; }