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

Class: Config_Container

Source Location: /Config-1.10.12/Config/Container.php

Class Overview


Interface for Config containers


Author(s):

Variables

Methods


Child classes:

Config_Container_PHPConstants
Config parser for PHP constant files

Inherited Variables

Inherited Methods


Class Details

[line 28]
Interface for Config containers


[ Top ]


Class Variables

$attributes =

[line 65]

Array of attributes for this item

Type:   array


[ Top ]

$children = array()

[line 53]

Container object children

Type:   array


[ Top ]

$content =  ''

[line 47]

Container object content

Type:   string


[ Top ]

$name =  ''

[line 41]

Container object name

Type:   string


[ Top ]

$parent =

[line 59]

Reference to container object's parent

Type:   object


[ Top ]

$type =

[line 35]

Container object type

Ex: section, directive, comment, blank


Type:   string


[ Top ]



Method Detail

Config_Container (Constructor)   [line 85]

Config_Container Config_Container( [string $type = 'section'], [string $name = ''], [string $content = ''], [array $attributes = null])

Constructor

Parameters:

string   $type     Type of container object
string   $name     Name of container object
string   $content     Content of container object
array   $attributes     Array of attributes for container object

[ Top ]

addItem   [line 123]

mixed &addItem( &$item, [string $where = 'bottom'], [object $target = null], object $item)

Adds an item to this item.
  • Return: reference to added container on success, Pear_Error on error

Parameters:

object   $item     a container object
string   $where     choose a position 'bottom', 'top', 'after', 'before'
object   $target     needed if you choose 'before' or 'after' in $where
   &$item     

[ Top ]

countChildren   [line 403]

int countChildren( [string $type = null], [string $name = null])

Returns how many children this container has
  • Return: number of children found

Parameters:

string   $type     type of children counted
string   $name     name of children counted

[ Top ]

createBlank   [line 182]

object reference &createBlank( [ $where = 'bottom'], [ $target = null])

Adds a blank line to this item.

This is a helper method that calls createItem

  • Return: to new item or Pear_Error

Parameters:

   $where     
   $target     

[ Top ]

createComment   [line 171]

object reference &createComment( [string $content = ''], [string $where = 'bottom'], [object $target = null])

Adds a comment to this item.

This is a helper method that calls createItem

  • Return: to new item or Pear_Error

Parameters:

string   $content     Object content
string   $where     Position : 'top', 'bottom', 'before', 'after'
object   $target     Needed when $where is 'before' or 'after'

[ Top ]

createDirective   [line 198]

object reference &createDirective( string $name, string $content, [mixed $attributes = null], [string $where = 'bottom'], [object $target = null])

Adds a directive to this item.

This is a helper method that calls createItem

  • Return: to new item or Pear_Error

Parameters:

string   $name     Name of new directive
string   $content     Content of new directive
mixed   $attributes     Directive attributes
string   $where     Position : 'top', 'bottom', 'before', 'after'
object   $target     Needed when $where is 'before' or 'after'

[ Top ]

createItem   [line 109]

object reference &createItem( string $type, $name, string $content, [array $attributes = null], [string $where = 'bottom'], [object $target = null], mixed $item)

Create a child for this item.
  • Return: to new item or Pear_Error

Parameters:

string   $type     type of item: directive, section, comment, blank...
mixed   $item     item name
string   $content     item content
array   $attributes     item attributes
string   $where     choose a position 'bottom', 'top', 'after', 'before'
object   $target     needed if you choose 'before' or 'after' for where
   $name     

[ Top ]

createSection   [line 216]

object reference &createSection( string $name, [array $attributes = null], [string $where = 'bottom'], [object $target = null])

Adds a section to this item.

This is a helper method that calls createItem If the section already exists, it won't create a new one. It will return reference to existing item.

  • Return: to new item or Pear_Error

Parameters:

string   $name     Name of new section
array   $attributes     Section attributes
string   $where     Position : 'top', 'bottom', 'before', 'after'
object   $target     Needed when $where is 'before' or 'after'

[ Top ]

directiveContent   [line 383]

mixed directiveContent( mixed $args, [int $index = -1])

Return a child directive's content.

This method can use two different search approach, depending on the parameter it is given. If the parameter is an array, it will use the Config_Container::searchPath() method. If it is a string, it will use the Config_Container::getItem() method.

Example:

  1.  require_once 'Config.php';
  2.  $ini = new Config();
  3.  $conf =$ini->parseConfig('/path/to/config.ini''inicommented');
  4.  
  5.  // Will return the value found at :
  6.  // [Database]
  7.  // host=localhost
  8.  echo $conf->directiveContent(array('Database''host')));
  9.  
  10.  // Will return the value found at :
  11.  // date="dec-2004"
  12.  echo $conf->directiveContent('date');

  • Return: Content of directive or false if not found.
  • Access: public

Parameters:

mixed   $args     Search path and attributes or a directive name
int   $index     Index of the item in the returned directive list. Eventually used if args is a string.

[ Top ]

getAttribute   [line 617]

mixed getAttribute( string $attribute)

Get one attribute value of this item
  • Return: item's attribute value

Parameters:

string   $attribute     Attribute key

[ Top ]

getAttributes   [line 607]

array getAttributes( )

Get this item's attributes.
  • Return: item's attributes

[ Top ]

getChild   [line 516]

mixed &getChild( [ $index = 0])

Returns the item parent object.
  • Return: returns reference to child object or false if child does not exist

Parameters:

   $index     

[ Top ]

getContent   [line 556]

string getContent( )

Get this item's content.
  • Return: item's content

[ Top ]

getItem   [line 242]

mixed &getItem( [string $type = null], [mixed $name = null], [mixed $content = null], [array $attributes = null], [int $index = -1])

Tries to find the specified item(s) and returns the objects.

Examples: $directives =& $obj->getItem('directive'); $directive_bar_4 =& $obj->getItem('directive', 'bar', null, 4); $section_foo =& $obj->getItem('section', 'foo');

This method can only be called on an object of type 'section'. Note that root is a section. This method is not recursive and tries to keep the current structure. For a deeper search, use searchPath()

  • Return: reference to item found or false when not found
  • See: &searchPath()

Parameters:

string   $type     Type of item: directive, section, comment, blank...
mixed   $name     Item name
mixed   $content     Find item with this content
array   $attributes     Find item with attribute set to the given value
int   $index     Index of the item in the returned object list. If it is not set, will try to return the last item with this name.

[ Top ]

getItemIndex   [line 459]

int getItemIndex( )

Returns the item index in its parent children array.
  • Return: returns int or null if root object

[ Top ]

getItemPosition   [line 479]

int getItemPosition( [bool $byType = true])

Returns the item rank in its parent children array according to other items with same type and name.
  • Return: returns int or null if root object

Parameters:

bool   $byType     count items differently by type

[ Top ]

getName   [line 538]

string getName( )

Get this item's name.
  • Return: item's name

[ Top ]

getParent   [line 507]

object returns &getParent( )

Returns the item parent object.
  • Return: reference to parent object or null if root object

[ Top ]

getType   [line 574]

string getType( )

Get this item's type.
  • Return: item's type

[ Top ]

isRoot   [line 655]

bool isRoot( )

Is this item root, in a config container object
  • Return: true if item is root

[ Top ]

removeItem   [line 442]

mixed removeItem( )

Deletes an item (section, directive, comment...) from the current object

TODO: recursive remove in sub-sections

  • Return: true if object was removed, false if not, or PEAR_Error if root

[ Top ]

searchPath   [line 323]

mixed &searchPath( mixed $args)

Finds a node using XPATH like format.

The search format is an array: array(item1, item2, item3, ...)

Each item can be defined as the following: item = 'string' : will match the container named 'string' item = array('string', array('name' => 'xyz')) will match the container name 'string' whose attribute name is equal to "xyz" For example : <string name="xyz">

  • Return: Config_Container object, array of Config_Container objects or false on failure.
  • Access: public

Parameters:

mixed   $args     Search path and attributes

[ Top ]

setAttributes   [line 584]

void setAttributes( array $attributes)

Set this item's attributes.

Parameters:

array   $attributes     Array of attributes

[ Top ]

setContent   [line 547]

void setContent( $content)

Set this item's content.

Parameters:

   $content     

[ Top ]

setDirective   [line 637]

object newly &setDirective( string $name, mixed $content, [int $index = -1])

Set a children directive content.

This is an helper method calling getItem and addItem or setContent for you. If the directive does not exist, it will be created at the bottom.

  • Return: set directive

Parameters:

string   $name     Name of the directive to look for
mixed   $content     New content
int   $index     Index of the directive to set, in case there are more than one directive with the same name

[ Top ]

setName   [line 529]

void setName( $name)

Set this item's name.

Parameters:

   $name     

[ Top ]

setType   [line 565]

void setType( $type)

Set this item's type.

Parameters:

   $type     

[ Top ]

toArray   [line 692]

array toArray( [bool $useAttr = true])

Returns a key/value pair array of the container and its children.

Format : section[directive][index] = value If the container has attributes, it will use '@' and '#' index is here because multiple directives can have the same name.


Parameters:

bool   $useAttr     Whether to return the attributes too

[ Top ]

toString   [line 669]

mixed toString( string $configType, [array $options = array()])

Call the toString methods in the container plugin
  • Return: true on success or PEAR_ERROR

Overridden in child classes as:

Config_Container_PHPConstants::toString()
Returns a formatted string of the object

Parameters:

string   $configType     Type of configuration used to generate the string
array   $options     Specify special options used by the parser

[ Top ]

updateAttributes   [line 594]

void updateAttributes( array $attributes)

Set this item's attributes.

Parameters:

array   $attributes     Array of attributes

[ Top ]

writeDatasrc   [line 745]

mixed writeDatasrc( mixed $datasrc, string $configType, [array $options = array()])

Writes the configuration to a file
  • Return: true on success or PEAR_ERROR
  • Access: public

Overridden in child classes as:

Config_Container_PHPConstants::writeDatasrc()
Writes the configuration to a file

Parameters:

mixed   $datasrc     Info on datasource such as path to the configuraton file or dsn...
string   $configType     Type of configuration
array   $options     Options for writer

[ Top ]


Documentation generated on Fri, 24 Dec 2010 08:30:04 +0000 by phpDocumentor 1.4.3. PEAR Logo Copyright © PHP Group 2004.