コード例 #1
0
 /**
  * Saves the given file both in the database and on the hard disk.
  * @param FileResource $resource the file resource.
  * @param string $name the new name for the file.
  * @param string $path the path relative to the base path.
  * @param string $scenario name of the scenario.
  * @return File the model.
  * @throws CException if saving the image fails.
  */
 public function saveModel(FileResource $resource, $name = null, $path = null, $scenario = 'insert')
 {
     $model = $this->createModel($scenario);
     $model->extension = strtolower($resource->getExtension());
     $model->filename = $resource->getName();
     $model->mimeType = $resource->getMimeType();
     $model->byteSize = $resource->getSize();
     $model->createdAt = date('Y-m-d H:i:s');
     if ($name === null) {
         $filename = $model->filename;
         $name = substr($filename, 0, strrpos($filename, '.'));
     }
     $model->name = $this->normalizeFilename($name);
     if ($path !== null) {
         $model->path = trim($path, '/');
     }
     if (!$model->save()) {
         throw new CException('Failed to save the file model.');
     }
     $filePath = $this->getBasePath(true) . '/' . $model->getPath();
     if (!file_exists($filePath) && !$this->createDirectory($filePath)) {
         throw new CException('Failed to create the directory for the file.');
     }
     $filePath .= $model->resolveFilename();
     if (!$resource->saveAs($filePath)) {
         throw new CException('Failed to save the file.');
     }
     $model->hash = $model->calculateHash();
     $model->save(true, array('hash'));
     return $model;
 }
コード例 #2
0
 public function testFindAllMainByExpressionAndObject()
 {
     $aMainPaths = ResourceFinder::findResourcesByExpressions(array('lib', 'main.php'));
     $this->assertSame(1, count($aMainPaths));
     $oFileRes = new FileResource(ArrayUtil::assocPeek($aMainPaths));
     $this->assertSame(array($oFileRes->getRelativePath() => MAIN_DIR . '/base/lib/main.php'), $aMainPaths);
 }
コード例 #3
0
ファイル: FileResourceTests.php プロジェクト: rapila/cms-base
 public function testSiteDirSubItemFullPathOnlyWithTrailingSlash()
 {
     $sFileResource = new FileResource(SITE_DIR . '/web/');
     $this->assertSame(SITE_DIR . '/web', $sFileResource->getFullPath());
     $this->assertSame('site/', $sFileResource->getInstancePrefix());
     $this->assertSame('web', $sFileResource->getRelativePath());
 }
コード例 #4
0
ファイル: Legacy.php プロジェクト: masev/ezpublish-kernel
 /**
  * Returns the appropriate FileResourceProvider depending on the cluster handler in use
  *
  * @throws \Exception
  *
  * @return \eZ\Publish\Core\IO\Handler\Legacy\FileResourceProvider
  */
 private function getFileResourceProvider()
 {
     if (!isset($this->fileResourceProvider)) {
         $class = __CLASS__ . '\\FileResourceProvider\\' . get_class($this->getClusterHandler());
         if (!class_exists($class)) {
             throw new \Exception("FileResourceProvider {$class} couldn't be found");
         }
         $this->fileResourceProvider = new $class();
         $this->fileResourceProvider->setLegacyKernel($this->getLegacyKernel());
     }
     return $this->fileResourceProvider;
 }
コード例 #5
0
 private function then_resource_returns_file_content()
 {
     $this->resource->changeSource($this->fileName);
     $this->assertSame($this->fileContent, $this->resource->getContent());
 }
コード例 #6
0
ファイル: FileResource.php プロジェクト: rapila/cms-base
 public static function mainDirCanonical()
 {
     if (self::$MAIN_DIR_CANONICAL === null) {
         self::$MAIN_DIR_CANONICAL = realpath(MAIN_DIR);
     }
     return self::$MAIN_DIR_CANONICAL;
 }