File_Therion_Writers
[ class tree: File_Therion_Writers ] [ index: File_Therion_Writers ] [ all elements ]

Class: File_Therion_StructuredWriter

Source Location: /File_Therion-0.4.1/File/Therion/Writers/StructuredWriter.php

Class Overview

File_Therion_DirectWriter
   |
   --File_Therion_StructuredWriter

The writer creates nested file structures linked with 'input' commands.


Author(s):

Copyright:

  • 2016 Benedikt Hallinger

Variables

Methods


Inherited Variables

Inherited Methods

Class: File_Therion_DirectWriter

File_Therion_DirectWriter::switchCreateDirs()
Switch automatic creation of intermediate directorys.
File_Therion_DirectWriter::switchOverwrite()
Switch overwriting permission.
File_Therion_DirectWriter::write()
Write a Therion file structure.

Class Details

[line 58]
The writer creates nested file structures linked with 'input' commands.

The exact file generation is controlled with file path templates. Everytime a template generates a new path at the current context, an input command is created in the parent file and a new file is created instead. The actual write is performed using the basic DirectWriter (options from there apply in this writer too); Existing target files are overwritten. The encoding-setting of the generated subfiles is expected to be the same as for the initial root file item passed to the writer.

The default survey structure is written in a nested fashion where:

  • each survey forms a new directory in the parent folder
  • each surveys content go into a separate .th file
  • each surveys scrap data go into a separate .th2 file per survey
  • subsurveys are handled like that too, but the files are linked together with input-commands.
  • grade definitions go into a common file 'grades.th' at the root level.
An alternative structure could be one, where you want to introduce another subfolder for therions data, so the therion files do not interfer with other files (eg. photos) stored in the default folder structure:
  1.  $writer->changeTemplate('File_Therion_Survey''$(base)/../$(name)/therion/$(name).th');
  2.  $writer->changeTemplate('File_Therion_Scrap''$(base)/$(parent).th2');
With this, each survey still forms a subfolder containing folders for the subsurveys. Therion data however will go into a subfolder "therion" (example assumes a survey structure like "main/sub1/sub2"):
  • .../main/therion/main.th -> first survey level
  • .../main/sub1/therion/sub1.th -> second survey level data
  • .../main/sub1/therion/sub1.th2 -> second survey level scraps
  • .../main/sub1/sub2/therion/sub2.th -> third survey level data
  • .../main/sub1/sub2/therion/sub2.th2 -> third survey level scraps



[ Top ]


Class Variables

$_files = array()

[line 81]

Registered files.

This gets filled by handleLines().

  • Var: of File_Therion objects
  • Access: protected

Type:   array


[ Top ]

$_fp_tpl = array(
        'File_Therion_Survey'  =>  '$(base)/$(name)/$(name).th',
        'File_Therion_Scrap'   =>  '$(base)/$(parent).th2',
        'File_Therion_Grade'   =>  '$(root)/grades.th'
    )

[line 68]

Configured filepath templates.
  • Access: protected

Type:   array


[ Top ]

$_inputCMDs = array()

[line 92]

Registered input commands.

This gets filled by handleLines(). It is used to suppress multiple occurences of the same input-command at the same file.

  • Var: index=filename, value=array of input cmds
  • Access: protected

Type:   array


[ Top ]



Method Detail

changeTemplate   [line 256]

void changeTemplate( string $item, string $template)

Change filepath template.

The template defines where the content of an object is written to. A template may contain variables (see below).

Recognized $items are class names of Therion objects.

Valid template variables are:

  • root: The full directory path of initial file
  • base: The full directory path of the parent survey
  • name: Name of the current object
  • parent: Name of the current survey context (parent survey)

  • Todo: check on syntax of template
  • Throws: File_Therion_Exception if template item is not supported
  • Throws: File_Therion_SyntaxException in case of invalid template
  • Access: public

Parameters:

string   $item   —  Class name to configure
string   $template   — 

[ Top ]

getFileInstance   [line 357]

null|File_Therion getFileInstance( string $filename)

Return file instance for template.

Instantiates a new file object for the given file path or returns the already present one.

NULL is returned, if the passed string is also NULL.

  • Return: object for the target file
  • Access: protected

Parameters:

string   $filename   —  Path to file resolved from template

[ Top ]

getTemplate   [line 272]

null|string getTemplate( string $name)

Return template for therion command or class name.
  • Return: NULL when no such template is defined
  • Access: public

Parameters:

string   $name   —  Therion command or class name

[ Top ]

handleLines   [line 144]

void handleLines( array &$lineBuffer, File_Therion $file, [array $ctx = array()])

Handle a given set of therion lines.

Sort the lines into appropriate file items depending on template evaluation results.

  • Access: public

Parameters:

File_Therion   $file   —  the current file context
array   $ctx   —  current object context (path of names)
array   &$lineBuffer   —  array with File_Therion_Line objects

[ Top ]

resolveTemplate   [line 306]

null|string resolveTemplate( File_Therion_Line $line, File_Therion $file, array $ctx)

Resolve a template to an actual file path.

Returns either the resolved template as viewed from the given file as base or NULL in case resolution was not possible.

  • Return: the resolved path
  • Access: protected

Parameters:

File_Therion_Line   $line   —  Definition of object
File_Therion   $file   —  the file object to resolve from
array   $ctx   —  Context array (array of names leading to the line obj)

[ Top ]

write   [line 109]

void write( File_Therion $file)

Write a Therion file structure.

The lines of the File_Therion instance will be split different context collections. Local lines are written to the filepath of the given File_Therion instance. Multiline commands (e.g. 'survey', etc) are first evaulated against the matching file template. The lines are then written to the template file.

  • Throws: File_Therion_Exception for other errors
  • Throws: File_Therion_IOException in case of IO error
  • Access: public

Overrides File_Therion_DirectWriter::write() (Write a Therion file structure.)

Parameters:

File_Therion   $file   —  the file object to write

[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:09:45 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.