Beispiel #1
0
 /**
  * @param Configuration $config
  * @throws \Exception
  */
 public function main(Configuration &$config)
 {
     $siteRoot = $config->get(array('task', 'siteRoot'), '');
     $fileDir = $config->get(array('task', 'fileDir'), '');
     if (empty($siteRoot)) {
         throw new \Exception('Task/Typo3/File: No site root defined.');
     }
     if (empty($fileDir)) {
         throw new \Exception('Task/Typo3/File: No file directory defined.');
     }
     // Empty data
     $this->data = [];
     // Trim slashes from paths
     $siteRoot = rtrim($siteRoot, '/');
     $fileDir = '/' . trim($fileDir, '/');
     // List files in the directory
     $files = new Directory($siteRoot . $fileDir);
     // Download files from remote server
     foreach ($files as $file) {
         // Connect to the file
         $identifier = $fileDir . '/' . $file->getFilename();
         // File is invalid
         if ($file->getSize() === 0) {
             continue;
         }
         // Update record info with typo3 sys_file compatible data
         $this->data[] = ['identifier' => $identifier, 'storage' => 1, 'identifier_hash' => sha1($identifier), 'folder_hash' => sha1($fileDir), 'extension' => $file->getExtension(), 'mime_type' => MimeType::get($file->getFilename()), 'name' => $file->getFilename(), 'sha1' => sha1_file($file->getRealPath()), 'size' => $file->getSize(), 'tstamp' => time(), 'last_indexed' => time(), 'creation_date' => $file->getCTime(), 'modification_date' => $file->getMTime()];
     }
 }
Beispiel #2
0
 /**
  * Serve the asset.
  *
  * @param array $args 
  */
 public function get(ServerRequestInterface $request, ResponseInterface $response, $args)
 {
     $module = \Chubby\AppFactory::getApp()->getModules()[$args['module']];
     $fullFile = $this->getFilePath($args['module'], $module['path'], $args['path'], $args['file']);
     if ($fullFile === false) {
         $response = $response->withStatus(404);
     } else {
         $mimeType = \Defr\MimeType::get($args['file']);
         $body = $response->getBody();
         $body->write(file_get_contents($fullFile));
         $response = $response->withStatus(200)->withHeader('Content-type', $mimeType)->withBody($body);
     }
     return $response;
 }
 /**
  * @param $file
  * @return string
  */
 public function getMime($file)
 {
     return \Defr\MimeType::get($file);
 }