1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the core-bundle package. |
5
|
|
|
* |
6
|
|
|
* (c) 2019 WEBEWEB |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace WBW\Bundle\CoreBundle\Helper; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\Finder\Exception\DirectoryNotFoundException; |
15
|
|
|
use Symfony\Component\Finder\Finder; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Skeleton helper. |
19
|
|
|
* |
20
|
|
|
* @author webeweb <https://github.com/webeweb/> |
21
|
|
|
* @package WBW\Bundle\CoreBundle\Helper |
22
|
|
|
*/ |
23
|
|
|
class SkeletonHelper { |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Copy skeleton. |
27
|
|
|
* |
28
|
|
|
* @param string $src The source directory. |
29
|
|
|
* @param string $dst The destination directory. |
30
|
|
|
* @return bool[] Returns the assets. |
31
|
|
|
*/ |
32
|
|
|
public static function copySkeleton($src, $dst) { |
33
|
|
|
|
34
|
|
|
$files = static::listSkeleton($src); |
35
|
|
|
|
36
|
|
|
$result = []; |
37
|
|
|
|
38
|
|
|
/** @var string $current */ |
39
|
|
|
foreach ($files as $current) { |
40
|
|
|
|
41
|
|
|
$pathname = str_replace($src, $dst, dirname($current)); |
42
|
|
|
if (false === file_exists($pathname)) { |
43
|
|
|
mkdir($pathname, 0755, true); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
$filename = implode("/", [$pathname, basename($current)]); |
47
|
|
|
$result[] = copy($current, $filename); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
return $result; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* List skeleton. |
55
|
|
|
* |
56
|
|
|
* @param string $directory The directory. |
57
|
|
|
* @return string[] Returns the skeletons. |
58
|
|
|
* @throws DirectoryNotFoundException Throws a directory not found exception if the directory does not exist. |
59
|
|
|
*/ |
60
|
|
|
public static function listSkeleton($directory) { |
61
|
|
|
|
62
|
|
|
$finder = new Finder(); |
63
|
|
|
$finder->sortByName()->files()->in($directory); |
64
|
|
|
|
65
|
|
|
$files = []; |
66
|
|
|
|
67
|
|
|
foreach ($finder as $current) { |
68
|
|
|
$files[] = $current->getRealPath(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
return $files; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|