Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
provision
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
provision
Commits
19a68535
Commit
19a68535
authored
Mar 31, 2010
by
Adrian Rossouw
Browse files
Options
Downloads
Patches
Plain Diff
playing with the factory pattern to create an environment object
parent
6b78a6d6
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
db/db.drush.inc
+27
-36
27 additions, 36 deletions
db/db.drush.inc
http/http.drush.inc
+6
-10
6 additions, 10 deletions
http/http.drush.inc
provision.environment.inc
+127
-0
127 additions, 0 deletions
provision.environment.inc
provision.service.inc
+21
-3
21 additions, 3 deletions
provision.service.inc
with
181 additions
and
49 deletions
db/db.drush.inc
+
27
−
36
View file @
19a68535
...
...
@@ -12,40 +12,11 @@
include_once
(
dirname
(
__FILE__
)
.
'/../provision.service.inc'
);
function
db_drush_init
()
{
include_once
(
'mysql/mysql_service.inc'
);
$command
=
drush_get_command
();
$command
=
explode
(
" "
,
$command
[
'command'
]);
if
(
preg_match
(
"/^provision-/"
,
$command
[
0
]))
{
// TODO - remove this shit
$master_db
=
drush_get_option
(
'master_db'
);
$db
=
parse_url
(
$master_db
);
drush_set_default
(
'master_db_user'
,
urldecode
(
$db
[
'user'
]));
drush_set_default
(
'master_db_passwd'
,
urldecode
(
$db
[
'pass'
]));
drush_set_default
(
'master_db_host'
,
urldecode
(
$db
[
'host'
]));
drush_set_default
(
'db_host'
,
urldecode
(
$db
[
'host'
]));
drush_set_default
(
'master_db_type'
,
$db
[
'scheme'
]);
drush_set_default
(
'db_type'
,
$db
[
'scheme'
]);
$creds
=
array
();
$options
=
array
(
'master_db_user'
=>
'user'
,
'master_db_passwd'
=>
'pass'
,
'master_db_host'
=>
'host'
,
'master_db_type'
=>
'type'
);
foreach
(
$options
as
$option
=>
$key
)
{
$creds
[
$key
]
=
drush_get_option
(
$option
,
''
);
}
provision_service
(
'db'
,
new
provisionService_db_mysql
(
$creds
));
provisionService
::
spawn
(
'db'
,
'mysql'
);
}
// this is where we generate the db service object.
}
function
db_drush_exit
()
{
...
...
@@ -67,11 +38,33 @@ function db_drush_help($section) {
class
provisionService_db
extends
provisionService
{
function
__construct
(
$creds
)
{
function
init
()
{
$master_db
=
drush_get_option
(
'master_db'
);
$db
=
parse_url
(
$master_db
);
drush_set_default
(
'master_db_user'
,
urldecode
(
$db
[
'user'
]));
drush_set_default
(
'master_db_passwd'
,
urldecode
(
$db
[
'pass'
]));
drush_set_default
(
'master_db_host'
,
urldecode
(
$db
[
'host'
]));
drush_set_default
(
'db_host'
,
urldecode
(
$db
[
'host'
]));
drush_set_default
(
'master_db_type'
,
$db
[
'scheme'
]);
drush_set_default
(
'db_type'
,
$db
[
'scheme'
]);
$creds
=
array
();
$options
=
array
(
'master_db_user'
=>
'user'
,
'master_db_passwd'
=>
'pass'
,
'master_db_host'
=>
'host'
,
'master_db_type'
=>
'type'
);
foreach
(
$options
as
$option
=>
$key
)
{
$creds
[
$key
]
=
drush_get_option
(
$option
,
''
);
}
$this
->
creds
=
$creds
;
return
TRUE
;
}
function
verify
()
{
if
(
!
$this
->
can_create_database
())
{
drush_set_error
(
'PROVISION_CREATE_DB_FAILED'
);
...
...
@@ -302,10 +295,8 @@ class provisionService_db_pdo extends provisionService_db {
protected
$creds
;
private
$dsn
;
function
__construct
(
$creds
)
{
parent
::
__construct
(
$creds
);
print_r
(
$creds
);
function
init
()
{
parent
::
init
();
$this
->
dsn
=
sprintf
(
"%s:dbname=%s;host=%s"
,
$this
->
PDO_type
,
$this
->
creds
[
'name'
],
$this
->
creds
[
'host'
]);
}
...
...
This diff is collapsed.
Click to expand it.
http/http.drush.inc
+
6
−
10
View file @
19a68535
...
...
@@ -6,11 +6,12 @@ function http_drush_init() {
$command
=
drush_get_command
();
$command
=
explode
(
" "
,
$command
[
'command'
]);
if
(
preg_match
(
"/^provision-/"
,
$command
[
0
]))
{
provisionService
::
spawn
(
'http'
,
'apache'
);
}
}
include_once
(
'apache/apache_service.inc'
);
provision_service
(
'http'
,
new
provisionService_http_apache
());
class
provisionService_http
extends
provisionService
{
function
init
()
{
// Set up defines for platform
$docroot
=
drush_get_option
(
array
(
"r"
,
"root"
),
$_SERVER
[
'PWD'
]);
...
...
@@ -48,11 +49,6 @@ function http_drush_init() {
drush_set_default
(
'site_port'
,
80
);
}
}
class
provisionService_http
extends
provisionService
{
/**
* Ask the web server to check for and load configuration changes.
*/
...
...
This diff is collapsed.
Click to expand it.
provision.environment.inc
0 → 100644
+
127
−
0
View file @
19a68535
<?php
function
provision_environment_factory
(
$options
)
{
$classes
=
array
(
'provisionServer'
,
'provisionPlatform'
,
'provisionSite'
);
if
(
provisionServer
::
evaluate
(
$options
))
{
$classname
=
array_shift
(
$classes
);
if
(
provisionPlatform
::
evaluate
(
$options
))
{
$classname
=
array_shift
(
$classes
);
if
(
provisionSite
::
evaluate
(
$options
))
{
$classname
=
array_shift
(
$classes
);
}
}
}
$object
=
new
$classname
(
$options
);
$object
->
clean
();
return
$object
;
}
class
provisionEnvironment
{
protected
$options
=
array
();
protected
$properties
=
array
();
protected
$map
=
array
();
protected
$type
=
null
;
function
__get
(
$name
)
{
if
(
array_key_exists
(
$name
,
$this
->
properties
))
{
return
$this
->
properties
[
$name
];
}
}
function
__set
(
$name
,
$value
)
{
if
(
!
property_exists
(
$this
,
$name
))
{
$this
->
properties
[
$name
]
=
$value
;
$this
->
map
[
$name
]
=
(
array_key_exists
(
$name
,
$this
->
map
))
?
$this
->
map
[
$name
]
:
$this
->
type
;
}
else
{
$this
->
$name
=
$value
;
}
}
function
__isset
(
$name
)
{
if
(
property_exists
(
$this
->
properties
,
$name
)
||
property_exists
(
$this
,
$name
))
{
return
TRUE
;
}
return
FALSE
;
}
function
__unset
(
$name
)
{
if
(
property_exists
(
$this
->
properties
,
$name
))
{
unset
(
$this
->
properties
[
$name
]);
}
elseif
(
property_exists
(
$this
,
$name
))
{
unset
(
$this
->
$name
);
}
}
function
__construct
(
$options
)
{
$this
->
options
=
$options
;
}
function
clean
()
{
$this
->
options
=
array
();
}
function
setProperty
(
$field
,
$default
=
null
)
{
if
(
isset
(
$this
->
options
[
$field
]))
{
$this
->
$field
=
$this
->
options
[
$field
];
}
else
{
$this
->
$field
=
$default
;
}
}
function
setMap
(
$field
,
$context
)
{
$this
->
map
[
$field
]
=
$context
;
}
}
class
provisionServer
extends
provisionEnvironment
{
public
static
function
evaluate
(
$options
)
{
return
TRUE
;
}
function
__construct
(
$options
)
{
parent
::
__construct
(
$options
);
$this
->
type
=
'server'
;
$this
->
setProperty
(
'remote_host'
,
'localhost'
);
$this
->
setProperty
(
'script_user'
,
get_current_user
());
$this
->
setProperty
(
'aegir_root'
,
'/var/aegir'
);
$this
->
setProperty
(
'config_path'
,
$this
->
aegir_root
.
'/config'
);
$this
->
setProperty
(
'backup_path'
,
$this
->
aegir_root
.
'/backup'
);
}
}
class
provisionPlatform
extends
provisionServer
{
public
static
function
evaluate
(
$options
)
{
if
(
$options
[
'root'
])
{
return
true
;
}
}
function
__construct
(
$options
)
{
parent
::
__construct
(
$options
);
$this
->
type
=
'platform'
;
$this
->
setProperty
(
'root'
,
$_SERVER
[
'PWD'
]);
}
}
class
provisionSite
extends
provisionPlatform
{
public
static
function
evaluate
(
$options
)
{
if
(
$options
[
'uri'
])
{
return
true
;
}
}
function
__construct
(
$options
)
{
parent
::
__construct
(
$options
);
$this
->
type
=
'site'
;
$this
->
setProperty
(
'uri'
);
}
}
This diff is collapsed.
Click to expand it.
provision.service.inc
+
21
−
3
View file @
19a68535
<?php
class
provisionService
{
function
__construct
()
{
$this
->
init
();
}
function
verify
()
{
return
TRUE
;
...
...
@@ -13,6 +10,27 @@ class provisionService {
return
TRUE
;
}
static
function
spawn
(
$service
,
$default
=
null
)
{
$reflect
=
new
reflectionClass
(
'provisionService_'
.
$service
);
$base_dir
=
dirname
(
$reflect
->
getFilename
());
$type
=
drush_get_option
(
$service
.
'-service-type'
,
$default
);
if
(
$type
)
{
$file
=
sprintf
(
"%s/%s/%s_service.inc"
,
$base_dir
,
$type
,
$type
);
$className
=
sprintf
(
"provisionService_%s_%s"
,
$service
,
$type
);
if
(
file_exists
(
$file
))
{
drush_log
(
"Loading
$type
driver for the
$service
service"
);
include_once
(
$file
);
provision_service
(
$service
,
new
$className
())
->
init
();
return
TRUE
;
}
}
return
false
;
}
}
class
provisionConfig
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment