public static function createKey(Folder $aFolder) { $sFlyweightKey = $aFolder->path(); if (!($aKey = FsKey::flyweight($sFlyweightKey, false))) { $aKey = new FsKey($aFolder); FsKey::setFlyweight($aKey, $sFlyweightKey); } return $aKey; }
public function moveToStoreFolder() { if (empty($this->aStoreFolder)) { throw new Exception("非法的路径属性,无法依赖此路径属性创建对应的文件夹对象"); } if (!$this->aStoreFolder->exists()) { $this->aStoreFolder = $this->aStoreFolder->create(); } // 保存文件 $sSavedFile = $this->aAchiveStrategy->makeFilePath($this->arrUploadedFile); $sSavedFolderPath = $this->aStoreFolder->path() . $sSavedFile; // 创建保存目录 $aFolderOfSavedFile = new Folder($sSavedFolderPath); if (!$aFolderOfSavedFile->exists()) { if (!$aFolderOfSavedFile->create()) { throw new Exception(__CLASS__ . "的" . __METHOD__ . "在创建路径\"%s\"时出错", array($aFolderOfSavedFile->path())); } } $sFileName = $this->aAchiveStrategy->makeFilename($this->arrUploadedFile); $sSavedFullPath = $this->aStoreFolder->path() . $sSavedFile . $sFileName; move_uploaded_file($this->arrUploadedFile['tmp_name'], $sSavedFullPath); $aSavedFile = new FsFile($sSavedFullPath); $aSavedFile->setHttpUrl($this->aStoreFolder->httpUrl() . $sSavedFile . $sFileName); $this->setValue($aSavedFile); return $aSavedFile; }