This repository was archived by the owner on Jun 3, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathswitchboard.validators.inc
More file actions
148 lines (140 loc) · 3.58 KB
/
switchboard.validators.inc
File metadata and controls
148 lines (140 loc) · 3.58 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
/**
* @file
* Custom validators for Switchboard.
*/
/**
* Validate a site name; assuming a-z, 0-9 and dash, 255 chars max.
*
* @param string $site_name
* The machine name of the Site in question.
*
* @return bool
* TRUE if the check passes.
*/
function switchboard_validate_site_name($site_name) {
return preg_match('/^[-a-z0-9]{1,255}$/', $site_name) ? TRUE : FALSE;
}
/**
* Check to see if a site exists within a particular provider.
*
* @param string $provider_name
* Name of the provider.
* @param string $site_name
* Name of the site.
*
* @return bool
* TRUE if all checks pass.
*/
function switchboard_validate_site($provider_name, $site_name) {
$provider =& \Fluxsauce\Switchboard\Provider::getInstance($provider_name);
return $provider->siteExists($site_name);
}
/**
* Check to see if user is logged-in to provider.
*
* @param string $provider_name
* The machine name of the Provider.
*
* @return bool
* TRUE if logged-in to provider.
*/
function switchboard_validate_auth_logged_in($provider_name) {
$provider =& \Fluxsauce\Switchboard\Provider::getInstance($provider_name);
return $provider->authIsLoggedIn();
}
/**
* Determine if a given provider name is in the list of known provider names.
*
* @param string $provider_name
* The machine name of the Provider.
*
* @return bool
* TRUE if a valid Provider name.
*/
function switchboard_validate_provider_name($provider_name) {
if (!$provider_name) {
return FALSE;
}
return in_array($provider_name, switchboard_get_provider_names());
}
/**
* Determine if an environment exists with a given site.
*
* @param string $provider_name
* The machine name of the Provider.
* @param string $site_name
* The machine name of the Site.
* @param string $env_name
* The machine name of the Site Environment.
*
* @return bool
* TRUE if a valid Site Environment.
*/
function switchboard_validate_site_env($provider_name, $site_name, $env_name) {
if (!$env_name) {
return FALSE;
}
$site = \Fluxsauce\Brain\SiteQuery::create()
->filterByProvider($provider_name)
->filterByName($site_name)
->findOne();
$environment = \Fluxsauce\Brain\EnvironmentQuery::create()
->filterBySite($site)
->filterByName($env_name)
->findOne();
return $environment ? TRUE : FALSE;
}
/**
* Determine if destination can written to and doesn't exist.
*
* @param string $destination_path
* Path to be checked.
*
* @return bool
* TRUE if a valid destination.
*/
function switchboard_validate_destination($destination_path) {
if (!$destination_path) {
return FALSE;
}
if (!file_exists($destination_path)) {
return TRUE;
}
return is_writable($destination_path);
}
/**
* Validate a standard 8-4-4-4-12 UUID.
*
* @param string $uuid
* The theoretically valid UUID.
*
* @return bool
* TRUE if valid.
*/
function switchboard_validate_uuid($uuid) {
return preg_match('#^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$#', $uuid) ? TRUE : FALSE;
}
/**
* Ensure that every option has values.
*
* Drush should do this, but it doesn't.
*
* @param string $command_name
* The name of the drush command.
*
* @return bool
* TRUE if all options have values.
*/
function switchboard_validate_drush_option_required_values($command_name) {
foreach (switchboard_get_drush_options($command_name) as $option_name => $option) {
if (is_array($option)) {
if (isset($option['value']) && $option['value'] == 'required') {
if (is_bool(drush_get_option($option_name, 'dummy'))) {
return FALSE;
}
}
}
}
return TRUE;
}