创建单次签名

@param string $bucket   bucket 名称
@param string $filepath  文件路径
@return string
774778
protected function createNonreusableSignature($bucket, $filepath)
    {
        if (preg_match('/^\//', $filepath) == 0) {
            $filepath = '/' . $filepath;
        }

        $fileId = '/' . $this->config->get('app_id') . '/' . $bucket . $filepath;

        return $this->createSignature(0, $bucket, $fileId);
    }
465003
protected function readFile(string $filePath): string
    {
        /**
         * read bin
         */
        $handle = fopen($filePath, 'rb');
        $stream = fread($handle, $this->maxByteCacheLen);
        fclose($handle);
        return $stream;
    }
874096
public function getCorePath(string $filePath): string
    {
        $rootPath = $this->getRootApplicationDirectoryPathByFilePath($filePath);
        $corePath = mb_substr($filePath, 0, mb_strpos($filePath, 'src'));
        $corePath = rtrim($corePath, DIRECTORY_SEPARATOR);
        $corePath = explode(DIRECTORY_SEPARATOR, $corePath);

        array_pop($corePath);
        $corePath = implode(DIRECTORY_SEPARATOR, $corePath);

        return rtrim($corePath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
    }
44152
public static function getMimeType($filePath)
    {
        $fInfo = finfo_open(FILEINFO_MIME_TYPE);
        $mime  = finfo_file($fInfo, $filePath);
        finfo_close($fInfo);

        return $mime;
    }
697501
public function uploadShopImage($filePath, $fileName = null)
    {
        $fileName === null && $fileName = pathinfo($filePath, PATHINFO_BASENAME);
        $result = $this->httpRaw(self::WECHAT_SHOP_IMAGE_UPLOAD_URL .
            'access_token=' . $this->getAccessToken() . '&filename=' . $fileName, file_get_contents($filePath));
        return isset($result['errmsg']) && $result['errmsg'] == 'success' ? $result['image_url'] : false;
    }
576745
public static function exists(string ...$filepath)
    {
        if (count($filepath) == 1) {
            return (file_exists($filepath[0]));
        } else {
            $exists = [];
            foreach ($filepath as $one) {
                array_push($exists, [$one => file_exists($one)]);
            }
            return ($exists);
        }
    }
843782
public static function uploadSlice($filePath, $bucket=Conf::BUCKET, $fileid = '', $sliceSize = 0, $session = null,$userid = 0, $magicContext = null,   $params = array()) {  
        $res = self::upload_slice_impl($filePath, $bucket, $fileid, $userid, $magicContext, $sliceSize, $session, $params);      
        if(false === $res)
        {
            $data = array();
        }else{
            $data = $res;
        }

         return array('code' =>self::$_messageInfo["code"], 
                         'message' => self::$_messageInfo["message"],
                         'data' => $data);
    }
1002137
private function getTranslationsInFile($filePath)
    {
        
	 	// File extension ?
        $extOk = in_array(\Jig\Utils\FsUtils::getFileExtension($filePath), $this->getFileTypes());

        if ($extOk){
            foreach ($this->getBannedFileType() as $bannedExt){
                $extOk &= substr_compare($filePath, $bannedExt, strlen($filePath)-strlen($bannedExt), strlen($bannedExt)) !== 0;
            }
        }

        if ($extOk) {
            
		 	// We read the file.
		 	$lines = file($filePath);
		 	foreach ($lines as $line) {
                $strings = $this->getTranslationPhrases( $line );
                //preg_match_all("/__(\(| )+['\"](.*?)['\"](\))?/u", $line, $string);
                
                //lookup for __('to translate') or __ 'to translate'
            //    preg_match_all("/__(\(| )+(('(.*?)')|(\"(.*?)\"))(\))?/u", $line, $string);
            
                foreach($strings as $s) {
                    $tu = new tao_helpers_translation_TranslationUnit();
                    $tu->setSource(tao_helpers_translation_POUtils::sanitize($s));
                    $tus = $this->getTranslationUnits();
                    $found = false;
                    
                    // We must add the string as a new TranslationUnit only
                    // if a similiar source does not exist.
                    foreach ($tus as $t) {
                        if ($tu->getSource() == $t->getSource()) {
                            $found = true;
                            break;
                        }
                    }
                    
                    if (!$found) {
                        $tus[] = $tu;
                        $this->setTranslationUnits($tus);
                    }
                }
		 	}
		}
        
    }
124607
private Set<String> getBucketsForPath(String path) {

        Set<String> result = Sets.newHashSet();
        boolean foundBucket = false;
        for (int i = 0; i < m_bucketNames.size(); i++) {
            for (String bucketPath : m_bucketPathLists.get(i)) {
                if (CmsStringUtil.isPrefixPath(bucketPath, path)) {
                    String bucketName = m_bucketNames.get(i);
                    result.add(bucketName);
                    if (!BUCKET_OTHER.equals(bucketName)) {
                        foundBucket = true;
                    }
                }
            }
        }
        if (!foundBucket) {
            result.add(BUCKET_OTHER);
        }
        return result;
    }
465928
public function setFilepath($filepath)
    {
        $this->_path = pathinfo($filepath);

        if (!isset($this->_path['extension']))
            $this->_path['extension'] = null;

        return $this;
    }
419545
public static function delFile($bucket, $path) {
        if (empty($bucket) || empty($path)) {
            return array(
                    'code' => COSAPI_PARAMS_ERROR,
                    'message' => 'path is empty');
        }

        $path = self::normalizerPath($path);

        return self::delBase($bucket, $path);
    }
421556
private static function setHash($filePath)
    {
        if (stristr(php_uname('s'), 'WIN')) {
            $filePath = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $filePath);
        }

        return md5($filePath);
    }
446217
public function uploadObject(string $bucket, string $object, string $filePath)
    {
        try {
            $response = $this->client->uploadFile($bucket, $object, $filePath);
            return $this->success('上传文件成功', $response['info']);
        } catch (\Exception $exception) {
            return $this->error('调用阿里云接口出错：' . $exception->getMessage());
        }
    }
4664
public function uploadFile($filePath, $key = null, $bucket = '')
    {
        if (!file_exists($filePath)) {
            throw new \Exception("上传的文件不存在",400);
        }
        $bucket = $bucket ? $bucket : $this->bucket;

        $uploadToken = $this->uploadToken(array('scope' => $bucket));
        $data = [];
        if (class_exists('\CURLFile')) {
            $data['file'] = new \CURLFile($filePath);
        } else {
            $data['file'] = '@' . $filePath;
        }
        $data['token'] = $uploadToken;
        if ($key) {
            $data['key'] = $key;
        }
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $this->up_host);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        $result = curl_exec($ch);
        $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
        $result = $this->response($result);
        if ($status == 200) {
            return $result;
        } else {
            throw new \Exception($result['error'],$status);
        }
    }
980119
private function delBase($bucket, $path)
    {
        if ($path == "/") {
            return [
                'code'      => Response::COSAPI_PARAMS_ERROR,
                'message'   => 'can not delete bucket using api! go to ' .
                    'http://console.qcloud.com/cos to operate bucket'
            ];
        }

        $path       = self::cosUrlEncode($path);
        $url        = self::generateResUrl($bucket, $path);
        $signature  = $this->createNonreusableSignature($bucket, $path);
        $data       = ['op' => 'delete'];
        $data       = json_encode($data);

        $req = [
            'url'       => $url,
            'method'    => 'post',
            'timeout'   => self::$timeout,
            'data'      => $data,
            'header'    => [
                'Authorization: ' . $signature,
                'Content-Type: application/json',
            ],
        ];

        return self::sendRequest($req);
    }
677597
public static function statFolder($bucketName, $path) {
        $path = self::normalizerPath($path, True);	

        return self::statBase($bucketName, $path);
    }
518584
public function upload($filePath, $contentType = 'text/plain')
    {
        $s3FileName = $this->getFilePathAndUniquePrefix() . basename($filePath);
        list($bucket, $prefix) = explode('/', $this->s3path, 2);

        $this->s3client->putObject([
            'Bucket' => $bucket,
            'Key' => (empty($prefix) ? '' : (trim($prefix, '/') . '/')) . $s3FileName,
            'ContentType' => $contentType,
            'ACL' => 'private',
            'ServerSideEncryption' => 'AES256',
            'SourceFile' => $filePath,
        ]);

        return $this->withUrlPrefix($s3FileName);
    }