Esempio n. 1
0
 /**
  * 
  * Enter description here...
  * @param $input
  * @param $replacement
  * @param $limit
  * @param $count
  * @return unknown_type
  */
 public function replace($input, $replacement, $limit = -1, &$count = null)
 {
     if (is_callable($replacement)) {
         return box_str(preg_replace_callback($this->pattern, $replacement, $input, $limit, $count));
     }
     return box_str(preg_replace($this->pattern, $replacement, $input, $limit, $count));
 }
Esempio n. 2
0
 /**
  * 
  * @param $value
  */
 public function __construct($value = "now")
 {
     $value = unbox($value);
     if ($value == null) {
         $this->value = null;
         return;
     }
     if ($value instanceof \DateTime) {
         $this->value = $value;
         return;
     }
     if (is_int($value)) {
         $this->value = new \DateTime(date(CultureInfo::currentCulture()->dateFormat, (int) $value));
         return;
     }
     if (is_string($value)) {
         if (box_str($value)->trim()->isNullOrEmpty == true) {
             $this->value = null;
             return;
         }
         if (is_numeric($value)) {
             $this->value = new \DateTime(date(CultureInfo::currentCulture()->dateFormat, (int) $value));
             return;
         } else {
             $this->value = new \DateTime($value);
             return;
         }
     }
     $this->value = null;
     return;
 }
 public function validate($value, $object)
 {
     $proc = $this->if;
     if ($proc && call_user_func_array($proc, array($value, $object))) {
         return true;
     }
     return !is_null($value) && !box_str($value)->empty;
 }
Esempio n. 4
0
 public function join($delimiter = ",")
 {
     $string = "";
     $count = $this->count();
     for ($i = 0; $i < $count; $i++) {
         $string .= $this->items[$i] . $delimiter;
     }
     return box_str($string)->trimEnd($delimiter);
 }
Esempio n. 5
0
 /**
  * @test
  * Enter description here...
  * @return unknown_type
  */
 public function itShouldMapOrFindAll()
 {
     $result = $this->enumerable->map(function ($item) {
         return box_str($item)->startsWith("t");
     });
     $this->expectsThat($result)->shouldBe(array("two", "three"));
     $result = $this->enumerable->findAll(function ($item) {
         return box_str($item)->startsWith("f");
     });
     $this->expectsThat($result)->shouldBe(array("four", "five"));
 }
Esempio n. 6
0
 public static function fetch()
 {
     $args = func_get_args();
     if (is_array($args[0])) {
         $array = $args[0];
     } else {
         $array = $args;
     }
     $type = $array[0];
     $config = $array[1];
     $type = box_str($type)->replace("_", "\\");
     $class = "Midori\\Data\\Adapters\\" . $type . "Adapter";
     return new $class($config);
 }
Esempio n. 7
0
 public function validate($value, $object)
 {
     $proc = $this->if;
     if ($proc && call_user_func_array($proc, array($value, $object))) {
         return true;
     }
     $length = box_str($value)->length;
     if ($this->min != null && $this->min > $length) {
         return false;
     }
     if ($this->max != null && $this->max < $length) {
         return false;
     }
     return true;
 }
Esempio n. 8
0
 /**
  * 
  * @test
  */
 public function itShouldReplaceTheCharactersByIndex()
 {
     $str = box_str("abcdef");
     $str[3] = "hi";
     $this->expectsThat($str)->shouldBe("abchief");
     $str = box_str("abcdef");
     $str["ef"] = "hi";
     $this->expectsThat($str)->shouldBe("abcdhi");
     $str = box_str("abcdef");
     $str[box_regex('/ab/')] = "hi";
     $this->expectsThat($str)->shouldBe("hicdef");
 }
Esempio n. 9
0
 /**
  * @test
  */
 public function itShouldMapValuesIntoANewHash()
 {
     $hash = $this->createHash();
     $results = $hash->map(function ($key, $value) {
         return box_str($key)->startsWith("b", true);
     });
     $this->expectsThat($results)->isNotNull();
     $this->expectsThat(count($results))->shouldBe(2);
     $this->expectsThat(isset($results["Braveheart"]))->isTrue();
 }