Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
provision
Commits
fdbb6c7c
Commit
fdbb6c7c
authored
Apr 07, 2010
by
Adrian Rossouw
Browse files
Moved the config class to it's own file.
parent
36eb8414
Changes
2
Hide whitespace changes
Inline
Side-by-side
provision.config.inc
0 → 100644
View file @
fdbb6c7c
<?php
// $Id$
/**
* Provision configuration generation classes.
*/
class
provisionConfig
{
public
$template
=
null
;
public
$data
=
array
();
public
$description
=
null
;
protected
$mode
=
'w'
;
function
__construct
(
$data
=
array
())
{
if
(
is_null
(
$this
->
template
))
{
throw
(
exception
);
}
if
(
sizeof
(
$data
))
{
$this
->
data
=
$data
;
}
}
function
process
()
{
parent
::
process
();
return
true
;
}
function
filename
()
{
return
false
;
}
private
function
load_template
()
{
$reflect
=
new
reflectionObject
(
$this
);
$base_dir
=
dirname
(
$reflect
->
getFilename
());
if
(
isset
(
$this
->
template
))
{
$file
=
$base_dir
.
'/'
.
$this
->
template
;
drush_log
(
"Template loaded:
$file
"
);
if
(
file_exists
(
$file
)
&&
is_readable
(
$file
))
{
return
file_get_contents
(
$file
);
}
}
return
false
;
}
private
function
render_template
(
$template
,
$variables
)
{
drush_errors_off
();
extract
(
$variables
,
EXTR_SKIP
);
// Extract the variables to a local namespace
ob_start
();
// Start output buffering
eval
(
'?>'
.
$template
);
// Generate content
$contents
=
ob_get_contents
();
// Get the contents of the buffer
ob_end_clean
();
// End buffering and discard
drush_errors_on
();
return
$contents
;
// Return the contents
}
function
write
()
{
$filename
=
$this
->
filename
();
if
(
$filename
&&
is_writeable
(
dirname
(
$filename
)))
{
// manipulate data before passing to template.
$this
->
process
();
if
(
$template
=
$this
->
load_template
())
{
#todo - convert to file_service
$file
=
fopen
(
$filename
,
$this
->
mode
);
$text
=
$this
->
render_template
(
$template
,
$this
->
data
);
fwrite
(
$file
,
$text
);
fclose
(
$file
);
if
(
$this
->
description
)
{
drush_log
(
"Generated config : "
.
$this
->
description
,
'success'
);
}
}
}
}
function
unlink
()
{
return
provision_service
(
'file'
)
->
unlink
(
$this
->
filename
())
->
status
();
}
}
provision.service.inc
View file @
fdbb6c7c
<?php
include_once
(
'provision.config.inc'
);
class
provisionService
{
protected
$last_status
;
protected
$tokens
;
...
...
@@ -82,81 +84,7 @@ class provisionService {
}
}
class
provisionConfig
{
public
$template
=
null
;
public
$data
=
array
();
public
$description
=
null
;
protected
$mode
=
'w'
;
function
__construct
(
$data
=
array
())
{
if
(
is_null
(
$this
->
template
))
{
throw
(
exception
);
}
if
(
sizeof
(
$data
))
{
$this
->
data
=
$data
;
}
}
function
process
()
{
parent
::
process
();
return
true
;
}
function
filename
()
{
return
false
;
}
private
function
load_template
()
{
$reflect
=
new
reflectionObject
(
$this
);
$base_dir
=
dirname
(
$reflect
->
getFilename
());
if
(
isset
(
$this
->
template
))
{
$file
=
$base_dir
.
'/'
.
$this
->
template
;
drush_log
(
"Template loaded:
$file
"
);
if
(
file_exists
(
$file
)
&&
is_readable
(
$file
))
{
return
file_get_contents
(
$file
);
}
}
return
false
;
}
private
function
render_template
(
$template
,
$variables
)
{
drush_errors_off
();
extract
(
$variables
,
EXTR_SKIP
);
// Extract the variables to a local namespace
ob_start
();
// Start output buffering
eval
(
'?>'
.
$template
);
// Generate content
$contents
=
ob_get_contents
();
// Get the contents of the buffer
ob_end_clean
();
// End buffering and discard
drush_errors_on
();
return
$contents
;
// Return the contents
}
function
write
()
{
$filename
=
$this
->
filename
();
if
(
$filename
&&
is_writeable
(
dirname
(
$filename
)))
{
// manipulate data before passing to template.
$this
->
process
();
if
(
$template
=
$this
->
load_template
())
{
#todo - convert to file_service
$file
=
fopen
(
$filename
,
$this
->
mode
);
$text
=
$this
->
render_template
(
$template
,
$this
->
data
);
fwrite
(
$file
,
$text
);
fclose
(
$file
);
if
(
$this
->
description
)
{
drush_log
(
"Generated config : "
.
$this
->
description
,
'success'
);
}
}
}
}
function
unlink
()
{
return
provision_service
(
'file'
)
->
unlink
(
$this
->
filename
())
->
status
();
}
}
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment