function testFromArrayToArrayList()
 {
     $input = array("one", "two");
     $output = String::fromPrimitives($input);
     $this->assertEqual(String::create("one"), $output->get(0));
     $this->assertEqual(String::create("two"), $output->get(1));
 }
 function testOkIndex()
 {
     $bla = String::create("Bla");
     $this->assertEqual(String::create("B"), $bla->charAt(0));
     $this->assertEqual(String::create("l"), $bla->charAt(1));
     $this->assertEqual(String::create("a"), $bla->charAt(2));
 }
Exemple #3
0
 public function __construct($url)
 {
     $this->url = $url;
     $viewParts = String::create($url)->split(self::URL_DELIMITER, 2);
     $this->view = $viewParts->get(0)->getPrimitive();
     $this->params = $viewParts->size() > 1 ? String::toPrimitives($viewParts->get(1)->split("/")) : array();
 }
 protected function getHref()
 {
     if (!String::create($this->action)->trim()->startsWith("\$") && $this->isLinkEnabled()) {
         return "#" . $this->action;
     }
     return "#";
 }
Exemple #5
0
 public static function create($lang)
 {
     $content = String::create(file_get_contents("bean/games/boggle/data/blocks/{$lang}"));
     $layout = new ArrayList("String");
     foreach ($content->split("\n") as $die) {
         $layout->add($die->split(" ")->getRandomElement());
     }
     $layout->shuffle();
     return new BoggleGrid($layout);
 }
Exemple #6
0
 private function getChildrenWithTag($tagName)
 {
     $tagNameStr = String::create($tagName);
     $result = new ArrayList("XmlElement");
     foreach ($this->children as $child) {
         if ($child->getName()->equals($tagNameStr)) {
             $result->add($child);
         }
     }
     return $result;
 }
Exemple #7
0
 public function __construct($get, $post, $files)
 {
     $this->get = HashMap::fromArray("string", "?", $get);
     $this->post = HashMap::fromArray("string", "?", $post);
     $this->files = $files;
     $this->postVars = new ArrayList("MovicoPostVar");
     foreach ($post as $name => $value) {
         if (String::create($name)->startsWith("#")) {
             $type = isset($post[self::TYPE_PREFIX . $name]) ? $post[self::TYPE_PREFIX . $name] : self::DEFAULT_TYPE;
             $this->postVars->add(new MovicoPostVar($name, $value, $type));
         }
     }
 }
 private function getXmlElement(SimpleXMLElement $el)
 {
     $result = new XmlElement(String::create($el->getName()));
     $result->setText(String::create($el));
     foreach ($el->children() as $child) {
         $xmlChild = $this->getXmlElement($child);
         $xmlChild->setParent($result);
         $result->addChild($xmlChild);
     }
     foreach ($el->attributes() as $name => $val) {
         $result->addAttribute($name, (string) $val);
     }
     return $result;
 }
Exemple #9
0
 private function getXmlElement(DOMElement $el)
 {
     $result = new XmlElement(String::create($el->tagName));
     for ($i = 0; $i < $el->childNodes->length; $i++) {
         $child = $el->childNodes->item($i);
         if ($child instanceof DOMText) {
             $result->setText(String::create($child->textContent));
         } elseif ($child instanceof DOMElement) {
             $xmlChild = $this->getXmlElement($child);
             $xmlChild->setParent($result);
             $result->addChild($xmlChild);
         }
     }
     for ($i = 0; $i < $el->attributes->length; $i++) {
         $attr = $el->attributes->item($i);
         $result->addAttribute($attr->nodeName, $attr->nodeValue);
     }
     return $result;
 }
Exemple #10
0
 private function verifyXmlContents(XmlFactory $xmlFactory)
 {
     $xmlString = "<root><element1 attribute1=\"value1\" attribute2=\"value2\"/><element2><child>bla</child></element2></root>";
     $file = $xmlFactory->fromString(String::create($xmlString));
     $this->assertEqual("root", $file->getRootElement()->getName());
     $root = $file->getRootElement();
     $this->assertEqual(2, $root->getNbChildren());
     $this->assertEqual(1, $root->getNbChildren("element1"));
     $children = $root->getChildren();
     $el1 = $children->getFirst();
     $this->assertEqual("element1", $el1->getName());
     $this->assertEqual(2, $el1->getNbAttributes());
     $this->assertEqual("value1", $el1->getAttribute("attribute1"));
     $this->assertEqual("value2", $el1->getAttribute("attribute2"));
     $el2 = $children->getLast();
     $this->assertEqual("element2", $el2->getName());
     $child = $el2->getChildren()->getFirst();
     $this->assertEqual("bla", $child->getText());
     $this->assertEqual("element2", $child->getParent()->getName());
     $this->assertEqual($xmlString, $root->asXml());
     $this->assertEqual(1, $root->getNbDescendants("child"));
 }
Exemple #11
0
 /**
  * Matches a string against this regex
  * @param string $input string to matcht he regex against
  * @return array|boolean Array of matching results. False if does not match
  */
 public function match($input)
 {
     String::create($input);
     return preg_match($this->value, $input->value, $matches) ? $matches : false;
 }
Exemple #12
0
 protected function getCurrentColumnClass($i)
 {
     $this->classList = String::create($this->columnClasses)->split(",");
     return $this->classList->get($i % $this->classList->size())->getPrimitive();
 }
 public function __construct($expression)
 {
     $this->expression = String::create($expression);
 }
 private static function str($description = null, $source = null)
 {
     return String::create('validation/error:notEmpty', 'Should be not empty', $description, $source);
 }
Exemple #15
0
 public function shouldBeRendered($index)
 {
     $renderedStr = String::create($this->rendered);
     if ($renderedStr->contains("!")) {
         return !$this->getConvertedValue($renderedStr->replace("!", "")->__toString(), $index);
     } else {
         return $this->getConvertedValue($this->rendered, $index);
     }
 }
Exemple #16
0
 public function __construct($word)
 {
     $this->word = String::create($word)->trim()->toUpperCase();
 }
 public function fromViewtoDom($strValue)
 {
     return String::create($strValue);
 }
 public function testNormalBehavior()
 {
     $this->assertEqual(String::create("er Me"), $this->input->substring(3, 8));
 }
Exemple #19
0
 private static function defaultTranslation($key)
 {
     $string = String::create($key, $key);
     $return = array();
     if (preg_match_all('/(\\b|[A-Z0-9]+)[a-z0-9-]+/', $string->key(), $matches)) {
         foreach ($matches[0] as $part) {
             $part = preg_replace('/([0-9-]+)/', ' $1 ', $part);
             $return[] = preg_match('/[A-Z]{2,}/', $part) ? $part : strtolower($part);
         }
         $return[0] = ucfirst($return[0]);
     }
     return count($return) ? trim(preg_replace('/ +/', ' ', join(' ', $return))) : $key;
 }
Exemple #20
0
 public static function isBeanReference($beanString)
 {
     return String::create($beanString)->contains(self::DELIM);
 }
Exemple #21
0
 public function __set($key, $value)
 {
     $key = String::create($key)->underscoreToCamelcase();
     return $this->{"set{$key}"}($value);
 }
Exemple #22
0
 /**
  * @return string
  * @param string $text
  * @param int $width
  * @param string $break
  */
 public static function wrap($text, $width = 80, $break = PHP_EOL)
 {
     return String::create($text)->wrap($width, $break)->__toString();
 }