예제 #1
0
파일: Text.php 프로젝트: ephigenia/ephframe
 /**
  * Return the first $count sentences from a $text
  * 
  * @param string $text
  * @param integer $count
  * @return string
  */
 public static function excerpt($text, $count = 1)
 {
     $sentenceCount = preg_match_all(self::$excerptRegexp, $text, $found, PREG_OFFSET_CAPTURE);
     if ($count > $sentenceCount) {
         return $text;
     }
     $excerpt = substr($text, 0, $found[0][$count - 1][1] + 2);
     return String::closeTags($excerpt);
 }
예제 #2
0
 public function apply($value)
 {
     $result = basename((string) $value);
     $result = preg_replace('@[/?*:;{}\\\\]@', '', $result);
     if ($this->paranoid) {
         $result = preg_replace('@[^A-Z0-9_.-]@i', '', $result);
     }
     if (String::length($result) > $this->maxLength) {
         if (($dotPos = strpos($result, '.')) !== false) {
             $extension = substr($result, $dotPos + 1);
             $basename = substr($result, 0, $dotPos);
             $result = String::substr($basename, 0, $this->maxLength - String::length($extension) - 1) . '.' . $extension;
         } else {
             $result = String::substr($result, 0, $this->maxLength);
         }
     }
     return $result;
 }
예제 #3
0
 public function message()
 {
     return String::substitute($this->message, (array) $this);
 }
예제 #4
0
 public function format(Event $Event)
 {
     return \ephFrame\util\String::substitute($this->format, array('priority' => $Event->priority, 'timestamp' => $Event->created->getTimeStamp(), 'date' => $Event->created->format('Y-m-d'), 'time' => $Event->created->format('h:m:s'), 'message' => (string) $Event->message));
 }
예제 #5
0
 public function testGenerateHumanReadablePassword()
 {
     $this->assertRegExp('@^[a-z]{20}$@i', String::generateHumanReadablePassword(20));
 }
예제 #6
0
 public function validate($value)
 {
     return parent::validate(String::length((string) $value) == $this->length);
 }
예제 #7
0
 public function validate($value)
 {
     return String::length((string) $value) >= $this->limit;
 }