Пример #1
0
 public function testStringChopdown()
 {
     $str = "abcdefg";
     $this->assertEquals("abcd", StringUtils::stringChopdown($str, 4));
     $chinese = "中国人";
     $this->assertEquals("中", StringUtils::stringChopdown($chinese, 1));
     $this->assertNotEquals("中", StringUtils::stringChopdown($chinese, 1, true));
     $this->assertEquals("中", StringUtils::stringChopdown($chinese, 3, true));
 }
 public function validate()
 {
     if ($this->md5OfBody) {
         if ($this->md5OfBody != md5($this->body)) {
             throw new \UnexpectedValueException("Body md5 doesn't match!");
         }
     }
     if ($this->md5OfAttributes) {
         $encoded_data = '';
         $attributes = $this->attributes;
         // make copy to avoid touching original data
         ksort($attributes);
         foreach ($attributes as $k => $v) {
             $klen = intval(strlen($k));
             $tlen = intval(strlen($v['DataType']));
             if (StringUtils::stringStartsWith($v['DataType'], "Binary")) {
                 $transport_type = 2;
             } else {
                 $transport_type = 1;
             }
             switch ($v['DataType']) {
                 case "String":
                 case "Number":
                     $value = $v['StringValue'];
                     break;
                 case "Binary":
                     $value = $v['BinaryValue'];
                     break;
                 default:
                     throw new \UnexpectedValueException("Unknown data type: {$v['DataType']}");
                     break;
             }
             $vlen = intval(strlen($value));
             $encoded_data .= pack('N', $klen);
             $encoded_data .= $k;
             $encoded_data .= pack('N', $tlen);
             $encoded_data .= $v['DataType'];
             $encoded_data .= pack('C', $transport_type);
             $encoded_data .= pack('N', $vlen);
             $encoded_data .= $value;
         }
         //mdebug("Calculated md5 = " . md5($encoded_data));
         if ($this->md5OfAttributes != md5($encoded_data)) {
             throw new \UnexpectedValueException("Attribute md5 doesn't match!");
         }
     }
 }
 protected function prepareDirectoryStructure()
 {
     $this->fs->mkdir($this->rootDir . "/bin");
     $this->fs->mkdir($this->rootDir . "/cache");
     $this->fs->mkdir($this->rootDir . "/config");
     $this->fs->mkdir($this->rootDir . "/templates");
     $this->fs->mkdir($this->rootDir . "/web");
     $this->fs->mkdir($this->rootDir . "/assets");
     $this->fs->mkdir(StringUtils::stringStartsWith($this->projectSrcDir, "/") ? $this->projectSrcDir : $this->rootDir . "/" . $this->projectSrcDir);
 }
Пример #4
0
 public function normalizeS3Path($s3path)
 {
     static $protocol = "s3://";
     if (StringUtils::stringStartsWith($s3path, $protocol)) {
         $s3path = substr($s3path, strlen($protocol));
     }
     $s3path = preg_replace('#/+#', "/", $s3path);
     return $protocol . $s3path;
 }