-
Notifications
You must be signed in to change notification settings - Fork 0
/
funcs_scripts.php
47 lines (40 loc) · 1020 Bytes
/
funcs_scripts.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
<?php
// Use these functions in scripts
function writeTemplateFileEvenIfExists($filename, $content)
{
global $MODULE_DIR;
writeFile("$MODULE_DIR/$filename", $content);
}
function writeTemplateFileIfNotExists($filename, $content)
{
global $MODULE_DIR;
if (!file_exists("$MODULE_DIR/$filename")) {
writeFile("$MODULE_DIR/$filename", $content);
}
}
function writeFile($filename, $contents)
{
$contents = trim($contents) . "\n";
file_put_contents($filename, $contents);
info("Wrote to $filename");
}
function isRecipe()
{
global $MODULE_DIR;
if (strpos('/recipe-', $MODULE_DIR) !== false) {
return true;
}
if (strpos('/silverstripe-installer', $MODULE_DIR) !== false) {
return true;
}
return false;
}
function info($message)
{
// using writeln with <info> instead of ->info() so that it only takes up one line instead of five
getIo()->writeln("<info>$message</>");
}
function warning($message)
{
getIo()->warning($message);
}