Name

Bric::Util::Burner::PHP - Publish stories using PHP templates

Synopsis

use Bric::Util::Burner::PHP;

# Create a new PHP burner using the settings from $burner
my $php_burner = Bric::Util::Burner::PHP->new($burner);

 # Burn an asset, get back a list of resources
my $resources = $php_burner->burn_one($ba, $oc, $cat);

Description

This module handles burning business story resources (files) PHP templates.

Interface

Constructors

$obj = Bric::Util::Burner::PHP->new($burner);

Creates a new PHP burner object. Takes a single parameters - $burner - which is a Bric::Util::Burner object. The new object will has its attributes initialized by the passed object.

Public Instance Methods

my $encoding = $burner->get_encoding

Returns the character set encoding to be used to write out the contents of a burn to a file. Defaults to "raw". Note that this is different than the default for the other burners because the utf8 flag on Perl variables is lost in the conversion to PHP. This should effectively be okay, however, as long as your PHP templates use the mb_* functions and identify the encoding as UTF-8. For example:

$sub = mb_substr($element->get_value('deck'), 0, 255, 'utf-8');

See the Multibyte String Functions manual for more information.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

$burner = $burner->set_encoding($encoding)

Sets the character set encoding to be used to write out the contents of a burn to a file. Use this attribute if templates are converting output data from Bricolage's native UTF-8 encoding to another encoding. Use "raw" if your templates are outputting binary data. Defaults to "raw".

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

$resources = $b->burn_one($ba, $oc, $cat);

Publishes an asset. Returns a list of resources burned. Parameters are:

my $bool = $burner->chk_syntax($ba, \$err)

Compiles the template found in $ba. If the compile succeeds with no errors, chk_syntax() returns true. Otherwise, it returns false, and the error will be in the $err variable passed by reference.

Throws: NONE.

Side Effects: NONE.

Notes: This method has not yet been implemented for PHP templates. For the time being, it always returns success.

my $template = $burner->find_template($uri, $tmpl_name)

Finds the first instance of the template with the name $tmpl_name in the URI directory hierarchy in $uri. Returns the template path, if it exists, and undef if it does not. For example:

my $uri = '/foo/bar/bletch';
my $tmpl_name = 'story.mc';
my $template = $burner->find_template($uri, $tmpl_name);

The find_template() method will look first for '/foo/bar/bletch/story.mc', and return that string if the template exists. If it doesn't, it'll look for '/foo/bar/story.mc'. If it doesn't find that, it'll look for '/foo/story.mc' and then '/story.mc'. If it finds none of these, it will rutrn null (or an empty list in an array context.

Throws: NONE.

Side Effects: NONE.

Notes: Uses HTML::Mason::Interp->comp_exists() internally to determine if the template exists.

my $template = $burner->find_first_template(@tmpl_list)

Returns the path to the first template it finds in @tmpl_list. It uses find_template() (see above) to examine each template in @tmpl_list in turn. Thus, this method looks down the directory hierarchy of each template in @tmpl_list before moving on to the next one. For example:

my @tmpl_list = ('/foo/bar/story.mc', '/sci/anthro/fizzle.mc');
my $template =  $burner->find_first_template(@tmpl_list)

In this example, find_first_template will return the name of the first template it finds in this order:

If no template is found to exist, find_first_template will return undef (or an empty list in an array context).

Throws: NONE.

Side Effects: NONE.

Notes: See also find_template() above.

$success = $b->display_element($element)
$success = $b->display_element($element, %ARGS)

A method to be called from template space. This method will find the mason element associated with the element passed in and call $m->comp. All arguments after the first argument will be passed to the template executed as its %ARGS hash.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

$output = $b->sdisplay_element($element)

A method to be called from template space. This is a sprint-likef version of display_element(), i.e. it returns the output as a string rather than outputting it it as display_element() does.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

my $more_pages = $b->get_more_pages
% unless ($burner->get_more_pages) {
      <h3>Last page</h3>
% }

Returns true if more pages remain to be burned, and false if not. Only enumerated when display_pages() is being used to output pages.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

Private

Private Class Methods

NONE.

Private Instance Methods

$template = $b->_load_template_element($element);

Given an element (a business asset/data element) return the template element that formats it.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

$elem = $b->_current_element

Return the current element in this context.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

$elem = $b->_current_element_type

Return the current element type in this context.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

$b = $b->_push_element($element)
$element = $b->_pop_element;

Push and pops an element from the element stack. As a story is burned, the burn process can travel down several elements deep. This stack records the order in which each element was transversed so when the burn process exits an element, the correct and current element is at the top of the stack.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

$burner->_display_container($element)

Called by display_element() and sidsplay_element() this method uses the PHP::Interpreter object to execute the element template for a container element.

Private Functions

None.

Notes

NONE.

Author

Garth Webb <garth@perijove.com>

Sam Tregar <stregar@about-inc.com>

David Wheeler <david@justatheory.com>

See Also

Bric, Bric::Util::Burner