forked from ninsuo/symfony-collection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ScriptHandler.php
80 lines (64 loc) · 2.29 KB
/
ScriptHandler.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
73
74
75
76
77
78
79
80
<?php
namespace Fuz\Symfony\Collection;
use Composer\Script\Event;
class ScriptHandler
{
public static function postInstall(Event $event)
{
self::handle($event);
}
public static function postUpdate(Event $event)
{
self::handle($event);
}
protected static function handle(Event $event)
{
$vendorDir = $event->getComposer()->getConfig()->get('vendor-dir');
self::installTwigFormTheme($vendorDir);
self::installJQueryPlugin($vendorDir);
}
protected static function installTwigFormTheme($vendorDir)
{
$collectionDir = $vendorDir.'/ninsuo/symfony-collection';
echo "*** ninsuo/symfony-collection: Installing Twig form theme... \t";
$viewsDir = realpath($vendorDir.'/../app/Resources/views');
if (!is_dir($viewsDir)) {
echo "FAILED: ";
echo "Directory 'app/Resources/views' doesn't exist.\n";
return;
}
if (!is_writable($viewsDir)) {
echo "FAILED: ";
echo "Directory '$viewsDir' is not writeable.\n";
return;
}
copy($collectionDir.'/jquery.collection.html.twig', $viewsDir.'/jquery.collection.html.twig');
echo "SUCCESS: ";
echo "You can now use {% form_theme form 'jquery.collection.html.twig' %}\n";
}
protected static function installJQueryPlugin($vendorDir)
{
$collectionDir = $vendorDir.'/ninsuo/symfony-collection';
echo "*** ninsuo/symfony-collection: Installing jQuery plugin... \t";
$webDir = realpath($vendorDir.'/../web/');
if (!is_dir($webDir)) {
echo "FAILED: ";
echo "Directory 'web' doesn't exist.\n";
return;
}
$jsDir = $webDir.'/js';
if (!is_dir($jsDir) && !mkdir($jsDir)) {
echo "FAILED: ";
echo "Directory '$jsDir' can't be created.\n";
return;
}
if (!is_writable($jsDir)) {
echo "FAILED: ";
echo "Directory '$jsDir' is not writeable.\n";
return;
}
copy($collectionDir.'/jquery.collection.js', $jsDir.'/jquery.collection.js');
echo "SUCCESS: ";
echo 'You can now use <script type="text/javascript" src={{ asset(\'js/jquery.collection.js\') }} />'."\n";
}
}