-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSymlinks.php
72 lines (62 loc) · 1.96 KB
/
Symlinks.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
namespace Solire\Install;
use Composer\Script\Event;
use Solire\Conf\Loader as ConfLoader;
use Solire\Install\Lib\Symlink;
use Solire\Lib\Path;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;
/**
* Create symlinks.
*
* @author thansen <[email protected]>
* @license CC by-nc http://creativecommons.org/licenses/by-nc/3.0/fr/
*/
class Symlinks
{
/**
* A composer installation script to make symlinks.
*
* @param Event $event The composer event
*
* @return void
*/
public static function create(Event $event)
{
Symlink::createDir('public');
$extra = $event->getComposer()->getPackage()->getExtra();
$conf = ConfLoader::load($extra['solire']['frontEnd']['dirs']);
foreach ($conf->dirs as $linkDir => $targetName) {
$targetDirPath = new Path(
sprintf($conf->targetMask, $targetName),
Path::SILENT
);
if ($targetDirPath->get() === false) {
continue;
}
$targetDir = $targetDirPath->get();
$finder = Finder::create()
->in($targetDir)
->depth(0)
->directories()
;
/* @var $target SplFileInfo */
foreach ($finder as $target) {
/*
* $dirName = js|css|img|font|...
*/
$dirName = $target->getBasename();
$linkPath = sprintf($conf->linkMask, $linkDir, $dirName);
$link = new Symlink($target->getRealPath(), $linkPath);
if ($link->create()) {
$msg = sprintf(
'<info>Création d\'un lien "%s" vers le dossier "%s"</info>',
$linkPath,
$target->getRealPath()
);
$event->getIO()->write($msg);
}
}
}
}
}