コード例 #1
0
ファイル: WebTestCase.class.php プロジェクト: johannes85/core
 /**
  * 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);
 }
コード例 #2
0
 /**
  * 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'];
     }
 }
コード例 #3
0
 /**
  * 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 . '}';
 }
コード例 #4
0
 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);
 }
コード例 #5
0
ファイル: Constants.class.php プロジェクト: xp-forge/mirrors
 /**
  * Creates a string representation
  *
  * @return string
  */
 public function toString()
 {
     $s = nameof($this) . "@[\n";
     foreach ($this as $const) {
         $s .= '  ' . (string) $const . "\n";
     }
     return $s . ']';
 }
コード例 #6
0
ファイル: Operator.class.php プロジェクト: xp-lang/compiler
 /**
  * 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));
 }
コード例 #7
0
 /**
  * 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));
     }
 }
コード例 #8
0
 /**
  * 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 . '])';
     }
 }
コード例 #9
0
 /**
  * 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 . '}';
 }
コード例 #10
0
 /**
  * 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 . '}';
 }
コード例 #11
0
 /**
  * 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 . '}';
 }
コード例 #12
0
ファイル: Table.class.php プロジェクト: xp-forge/markdown
 /**
  * Creates a string representation
  *
  * @return string
  */
 public function toString()
 {
     $s = nameof($this) . "@{\n";
     foreach ($this->nodes as $row) {
         $s .= '  ' . $row->toString() . "\n";
     }
     return $s . '}';
 }
コード例 #13
0
 /**
  * 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];
 }
コード例 #14
0
 /**
  * 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);
 }
コード例 #15
0
 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);
 }
コード例 #16
0
ファイル: Link.class.php プロジェクト: xp-framework/rest
 /** @return string */
 public function toString()
 {
     $s = nameof($this) . '<' . $this->uri . '>';
     foreach ($this->params as $param => $value) {
         $s .= '; ' . $param . '="' . $value . '" ';
     }
     return substr($s, 0, -1);
 }
コード例 #17
0
 /**
  * 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));
 }
コード例 #18
0
ファイル: Node.class.php プロジェクト: xp-lang/compiler
 /**
  * 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 . '}';
 }
コード例 #19
0
 /**
  * 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];
 }
コード例 #20
0
ファイル: NodeList.class.php プロジェクト: xp-forge/mustache
 /**
  * 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 . ']';
 }
コード例 #21
0
 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'));
 }
コード例 #22
0
ファイル: ParseTree.class.php プロジェクト: xp-forge/markdown
 /**
  * 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" . "}";
 }
コード例 #23
0
 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());
 }
コード例 #24
0
 /**
  * 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);
 }
コード例 #25
0
 /**
  * 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;
 }
コード例 #26
0
 /**
  * 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;
 }
コード例 #27
0
 /**
  * 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 .= '}';
 }
コード例 #28
0
 /**
  * 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;
 }
コード例 #29
0
 /** @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);
     }
 }
コード例 #30
0
 /**
  * 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'];
 }