Ejemplo n.º 1
0
 public function endsWith($element)
 {
     $rep = Condition::stringOf($element);
     return $this->is(new Match(function ($value) use($element) {
         return sizeof($value) > 0 && Objects::equal($value[sizeof($value) - 1], $element);
     }, ['%s does not end with ' . $rep, '%s ends with ' . $rep]));
 }
Ejemplo n.º 2
0
 public function get($key)
 {
     $offset = Objects::hashOf($key);
     if (!isset($this->elements[$offset])) {
         throw new \util\NoSuchElementException('No such key ' . \xp::stringOf($key));
     }
     return $this->elements[$offset];
 }
Ejemplo n.º 3
0
 /**
  * Performs measurement
  *
  * @param  util.profiling.Measurement $m
  */
 public function run($m)
 {
     $m->perform(newinstance('util.profiling.Run', [], ['before' => function ($iteration) {
         Console::write($iteration->name(), ': ');
     }, 'after' => function ($result) {
         Console::writeLinef('%d iteration(s), %.3f seconds, result= %s', $result->iteration()->times(), $result->elapsed(), Objects::stringOf($result->result()));
     }]));
 }
 /**
  * Load a template by a given name
  *
  * @param  string $name The template name without file extension
  * @return io.streams.InputStream
  * @throws com.github.mustache.TemplateNotFoundException
  */
 public function load($name)
 {
     $variants = $this->variantsOf($name);
     foreach ($variants as $variant) {
         if ($stream = $this->inputStreamFor($variant)) {
             return $stream;
         }
     }
     throw new TemplateNotFoundException('Cannot find template [' . implode(', ', $variants) . '] in ' . Objects::stringOf($this->base));
 }
Ejemplo n.º 5
0
 public function pop()
 {
     if (empty($this->_elements)) {
         throw new NoSuchElementException('Stack is empty');
     }
     $element = array_shift($this->_elements);
     $h = Objects::hashOf($element);
     $this->_hash += HashProvider::hashOf($h);
     return $element;
 }
 /**
  * Assertion helpeer
  *
  * @param  string[] $patterns
  * @param  unittest.assert.Value $assert
  * @throws unittest.AssertionFailedError
  */
 protected function assertUnverified($patterns, $assert)
 {
     $messages = new AssertionsFailed();
     $failures = $this->failed->failures();
     if (sizeof($failures) !== sizeof($patterns)) {
         $messages->add(new AssertionFailedError(new FormattedMessage('Expected %d failures but have %d: %s', [sizeof($patterns), sizeof($failures), Objects::stringOf($failures)])));
     }
     foreach ($failures as $i => $failure) {
         $message = $failure->getMessage();
         if (!preg_match($patterns[$i], $message)) {
             $messages->add(new AssertionFailedError(new FormattedMessage('Expected `%s` to match %s', [$message, $patterns[$i]])));
         }
     }
     $messages->raiseIf();
 }
Ejemplo n.º 7
0
 /**
  * Gets properties
  *
  * @param  string $name
  * @return util.PropertyAccess
  * @throws lang.ElementNotFoundException
  */
 public function properties($name)
 {
     $found = [];
     foreach ($this->sources as $source) {
         if ($source->provides($name)) {
             $found[] = $source->fetch($name);
         }
     }
     switch (sizeof($found)) {
         case 0:
             throw new ElementNotFoundException(sprintf('Cannot find properties "%s" in any of %s', $name, Objects::stringOf($this->sources)));
         case 1:
             return $found[0];
         default:
             return new CompositeProperties($found);
     }
 }
Ejemplo n.º 8
0
 /** @return string */
 public function hashCode()
 {
     return crc32($this->uri) . Objects::hashOf($this->params);
 }
Ejemplo n.º 9
0
 /** @return string */
 public function toString()
 {
     return nameof($this) . ($this->sources ? Objects::stringOf($this->sources) : '[]');
 }
Ejemplo n.º 10
0
 /**
  * Creates a string representation
  *
  * @return string
  */
 public function toString()
 {
     $params = $this->params ? Objects::stringOf($this->params) : '';
     return nameof($this) . '<(' . $params . ') -> ' . $this->code . '>';
 }
Ejemplo n.º 11
0
 /**
  * Compare to another schema
  *
  * @param  var $value
  * @return int
  */
 public function compareTo($value)
 {
     return $value instanceof self ? Objects::compare($this->definition, $value->definition) : 1;
 }
Ejemplo n.º 12
0
 /**
  * Returns whether a given comparison value is equal to this node list
  *
  * @param  var $cmp
  * @return string
  */
 public function equals($cmp)
 {
     return $cmp instanceof self && $this->url === $cmp->url && $this->title === $cmp->title && Objects::equal($this->text, $cmp->text);
 }
Ejemplo n.º 13
0
 /**
  * Get string representation
  *
  * @return  string
  */
 public function toString()
 {
     return nameof($this) . '<key= ' . Objects::stringOf($this->key) . ', value= ' . Objects::stringOf($this->value) . '>';
 }
Ejemplo n.º 14
0
 /**
  * Creates a string representation
  *
  * @return string
  */
 public function toString()
 {
     return nameof($this) . '@' . Objects::stringOf($this->indexed);
 }
Ejemplo n.º 15
0
 /**
  * Returns whether another instance is equal to this
  *
  * @param  var $cmp
  * @return bool
  */
 public function equals($cmp)
 {
     return $cmp instanceof self && Objects::equal($this->links, $cmp->links);
 }
Ejemplo n.º 16
0
 /**
  * Compares a given value to this
  *
  * @param  var $value
  * @return int
  */
 public function compareTo($value)
 {
     return $value instanceof self ? Objects::compare($this, $value) : self::$NOT_INSTANCE;
 }
Ejemplo n.º 17
0
 public function update($element)
 {
     $h = $this->prefix . Objects::hashOf($element);
     unset($this->_elements[$h]);
     $this->_elements = $this->_elements + [$h => $element];
 }
Ejemplo n.º 18
0
 /**
  * Returns true if a given value matches this `IsEqualToArray` condition.
  *
  * @param  var $value
  * @return bool
  */
 public function matches($value)
 {
     return Objects::equal($this->value, $value);
 }
Ejemplo n.º 19
0
 /**
  * Returns whether another value is equal to this
  *
  * @param  var $value
  * @return int
  */
 public function compareTo($value)
 {
     return $value instanceof self ? Objects::compare($this->backing, $value->backing) : 1;
 }
Ejemplo n.º 20
0
 /**
  * Returns whether a given value is equal to this mime part
  *
  * @param  var $cmp
  * @return bool
  */
 public function equals($cmp)
 {
     return $cmp instanceof self && $this->contenttype === $cmp->contenttype && $this->charset === $cmp->charset && $this->encoding === $cmp->encoding && $this->disposition === $cmp->disposition && $this->name === $cmp->name && $this->filename === $cmp->filename && $this->id === $cmp->id && $this->body === $cmp->body && Objects::equal($this->headers, $cmp->headers);
 }
Ejemplo n.º 21
0
 public function remove($element)
 {
     if (-1 == ($pos = $this->search($element))) {
         return false;
     }
     $element = $this->_elements[$pos];
     $h = Objects::hashOf($element);
     $this->_hash -= HashProvider::hashOf($h);
     unset($this->_elements[$pos]);
     $this->_elements = array_values($this->_elements);
     // Re-index
     return true;
 }
Ejemplo n.º 22
0
 /**
  * Check whether a given value is equal to this node list
  *
  * @param  var $cmp The value
  * @return bool
  */
 public function equals($cmp)
 {
     return $cmp instanceof self && $this->name === $cmp->name && $this->escape === $cmp->escape && \util\Objects::equal($this->options, $cmp->options);
 }
Ejemplo n.º 23
0
 /**
  * Returns whether another object is equal to this
  *
  * @param   lang.Generic $cmp
  * @return  bool
  */
 public function equals($cmp)
 {
     return $cmp instanceof self && $this->name === $cmp->name && $this->debug === $cmp->debug && $this->arguments === $cmp->arguments && $this->environment === $cmp->environment && $this->scriptlet === null ? null === $cmp->scriptlet : $this->scriptlet->equals($cmp->scriptlet) && Objects::equal($this->logLevels, $cmp->logLevels) && 0 === $this->config->compareTo($cmp->config);
 }
Ejemplo n.º 24
0
 /** @return string */
 public function message()
 {
     return Objects::stringOf($this->target) . ' is not equal to ' . Objects::stringOf($this->comparison);
 }
Ejemplo n.º 25
0
 /**
  * Returns whether a given value is equal to this code unit
  *
  * @param  var $cmp
  * @return bool
  */
 public function equals($cmp)
 {
     return $cmp instanceof self && ($this->package === $cmp->package && Objects::equal($this->imports, $cmp->imports) && Objects::equal($this->declaration, $cmp->declaration));
 }
Ejemplo n.º 26
0
 /**
  * Returns whether a given value is equal to this code unit
  *
  * @param  var $cmp
  * @return bool
  */
 public function equals($cmp)
 {
     return $cmp instanceof self && (Objects::equal($this->parameters, $cmp->parameters) && $this->return->equals($cmp->return));
 }
Ejemplo n.º 27
0
 /**
  * Check whether a given value is equal to this node list
  *
  * @param  var $cmp The value
  * @return bool
  */
 public function equals($cmp)
 {
     return $cmp instanceof self && $this->name === $cmp->name && $this->invert === $cmp->invert && $this->start === $cmp->start && $this->end === $cmp->end && \util\Objects::equal($this->options, $cmp->options) && $this->nodes->equals($cmp->nodes);
 }
Ejemplo n.º 28
0
 /**
  * Creates a string representation of this sequence
  *
  * @return string
  */
 public function toString()
 {
     if ([] === $this->elements) {
         return nameof($this) . '<EMPTY>';
     } else {
         return nameof($this) . '@' . Objects::stringOf($this->elements);
     }
 }
Ejemplo n.º 29
0
 /**
  * Creates a string representation of any given value.
  *
  * @param  var $value
  * @return string
  */
 public static function stringOf($value)
 {
     return null === $value ? 'null' : Objects::stringOf($value);
 }
Ejemplo n.º 30
0
 /**
  * Creates a string representation
  *
  * @return string
  */
 public function toString()
 {
     return nameof($this) . '(' . Objects::stringOf($this->value) . ')';
 }