TITAN Library for PHP5  5.6.0
Web Software Development Kit for PHP5
csv Class Reference

Titan CSV Input/Output Class. More...

Inheritance diagram for csv:
loadable

Public Member Functions

 __construct ()
 
 clear ($all=false)
 
 required ($fields)
 
 read ($filename=false)
 
read_cb ($cbfunc=false, $filename=false)
 
readall ($filename=false)
 
 write_header ($filename, $data, $overwrite=true, $close=false)
 
 write ($filename, $data, $overwrite=false, $close=true)
 
- Public Member Functions inherited from loadable
 __construct ($class= '', $method= '',...$params)
 
 file ($file)
 
 constructor ($class,...$params)
 
 method ($class, $method,...$params)
 
 func ($function,...$params)
 
 arguments ($type, $value)
 
 values ($name, $value= '')
 
factory_force (...$params)
 
factory (...$params)
 
execute (...$params)
 

Protected Member Functions

 open ($filename, $mode= 'r', $header=true)
 
 close ()
 
 header_proc ($header)
 
 header_test ()
 
 associate ($keys, $vals, $extra= '')
 
 fix_val ($val)
 
 build_line ($data, $header=false)
 
- Protected Member Functions inherited from loadable
process_arguments ($type, array $arguments=[])
 

Detailed Description

Titan CSV Input/Output Class.

Class: \tl\storage\csv

/extends loadable

Author
James E. Bush work@.nosp@m.bush.nosp@m..cc
Version
5.6.0

Constructor & Destructor Documentation

__construct ( )

Constructor

Member Function Documentation

clear (   $all = false)

Close the file and reset the saved header. Optionally reset all internal variables to start over.

Parameters
boolean$all(optional) Reset all internal variables? (default) false
required (   $fields)

Set or erase the list of required fields

Parameters
mixed$fieldsA field name or a list of field names that are "required" for a CSV import. Optionally, you may pass "erase" to erase all saved required fields.
open (   $filename,
  $mode = 'r',
  $header = true 
)
protected

Internal

Parameters
string$filenameThe name of the file to open
string$mode(optional) The fopen() mode (default) 'r'
mixed$header(optional) The CSV header line (default) true = read the first livne of the file and parse it as headers (option) false = ignore header because either no header is present, or open for write (option) an array of strings containing the header information
close ( )
protected

Internal

read (   $filename = false)

Read one line a CSV file

Parameters
string$filename(optional) The name of the file to read (default) Read from the already open file, or fail if no file is open for reading
& read_cb (   $cbfunc = false,
  $filename = false 
)

Read the contents of a CSV file, calling a callback function for each record

Parameters
mixed$cbfunc(optional) \tl\core\loadable object or s atring containing the name of the function to call (default) false = do not call a callback function
string$filename(optional) The name of the file to read (default) Read from the already open file, or fail if no file is open for reading
& readall (   $filename = false)

Read the contents of a CSV file

Parameters
string$filename(optional) The name of the file to read (default) Read from the already open file, or fail if no file is open for reading
header_proc (   $header)
protected

Internal: Process the header to guess the delimiter and return an array of header field names

Parameters
string$headerThe header string to process
header_test ( )
protected

Internal: Used by peader_proc()

associate (   $keys,
  $vals,
  $extra = '' 
)
protected

Internal: Creates an object by using one array for keys and another for its values. Uses PHP 5 array_combine(), creates a stdClass object and allows for $extra, also for values: trims, converts tabs to spaces, and strips newlines

Parameters
array$keysArray of strings to use as keys
array$valsArray of strings to use as values
mixed$extraObject or array of key/value pairs to start with
Returns
\stdClass
fix_val (   $val)
protected

Internal: Used by associate() trims, converts tabs to spaces, and strips newlines

Parameters
string$valThe value to "fix"
Returns
string
write_header (   $filename,
  $data,
  $overwrite = true,
  $close = false 
)

Write a header line to a CSV file

Parameters
string$filenameThe CSV file name
mixed$dataEither an array of objects (only the first object in the array is used), or a single object. The object's property names are used as the header fields.
boolean$overwrite(optional) Open for wite instead of append? (default) true
boolean$close(optional) Close the CSV file after the write? (default) false
write (   $filename,
  $data,
  $overwrite = false,
  $close = true 
)

Write a single line or an array of lines to a CSV file. The contents of each line must be passed as an object.

Parameters
string$filenameThe CSV file name
mixed$dataEither an array of objects, or a single object. Each object will be converted to a line in the CSV file.
boolean$overwrite(optional) Open for wite instead of append? (default) false
boolean$close(optional) Close the CSV file after the write? (default) true
build_line (   $data,
  $header = false 
)
protected

Internal: Build a CSV line from an object

Parameters
object$datathe object whose property values will be converted to CSV data
boolean$header(optional) Gereate a header from property names instead? (default) false

The documentation for this class was generated from the following file: