Completed
Push — master ( 6a50c0...c1563b )
by Vladimir
02:57
created

FileManager::copyFiles()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
nc 1
dl 0
loc 1
1
<?php
2
3
namespace allejo\stakx\Manager;
4
5
use allejo\stakx\System\Folder;
6
use Symfony\Component\Finder\Finder;
7
use Symfony\Component\Finder\SplFileInfo;
8
9
abstract class FileManager extends BaseManager
10
{
11
    /**
12
     * @var Folder
13
     */
14
    protected $outputDirectory;
15
16
    /**
17
     * @var Finder
18
     */
19
    protected $finder;
20
21
    /**
22
     * @var string[]
23
     */
24
    protected $files;
25
26
    /**
27
     * @param Folder $directory
28
     */
29
    public function setFolder ($directory)
30
    {
31
        $this->outputDirectory = $directory;
32
    }
33
34
    /**
35
     * @param SplFileInfo $file   The relative path of the file to be copied
36
     * @param string      $prefix
37
     */
38
    protected function copyToCompiledSite ($file, $prefix = "")
39
    {
40
        if (!$this->fs->exists($file)) { return; }
41
42
        $filePath = $file->getRealPath();
43
        $pathToStrip = $this->fs->appendPath(getcwd(), $prefix);
44
        $siteTargetPath = ltrim(str_replace($pathToStrip, "", $filePath), DIRECTORY_SEPARATOR);
45
46
        try
47
        {
48
            $this->outputDirectory->copyFile($filePath, $siteTargetPath);
49
        }
50
        catch (\Exception $e)
51
        {
52
            $this->output->error($e->getMessage());
53
        }
54
    }
55
56
    abstract public function copyFiles ();
57
}