CMS  Version 3.9
CompoundSerializationHandler Class Reference

Provides serialization for a number of DataItem classes, grouped under a common tag in the serialized XML. More...

Public Member Functions

 __construct ($groupTag)
 Creates the CompoundSerializationHandler. More...
 
 addTarget ($class, $constraint="")
 Add a target DataItem with optional constraint. More...
 
 export ()
 Exports the target DataItems to XML. More...
 
 import ($doc, $tx)
 Import from a serialized XML document. More...
 
 retrieve ($doc, $class)
 Retrieves serialized objects from the provided XML document, but does not store them in the database. More...
 

Public Attributes

 $groupTag
 
 $classes = array()
 
 $constraints = array()
 

Detailed Description

Provides serialization for a number of DataItem classes, grouped under a common tag in the serialized XML.

Use this when your component needs to serialize a number of related objects under the same transaction.

To serialize two or more items, you would create the handler like this: new ComponentSerializationHandler("GroupTag", Class1, Class2)

You can provide database constraints for export for each class by passing an array containing the class name and the constraint:

new CompoundSerializationHandler("GroupTag", array(Class1, "WHERE active=1"), Class2)

Author
Andy Green

Definition at line 456 of file serialization_manager.inc.

Constructor & Destructor Documentation

◆ __construct()

CompoundSerializationHandler::__construct (   $groupTag)

Creates the CompoundSerializationHandler.

Parameters
string$groupTagthe tag name to be used to group the XML output
Exceptions
FakoliException

Definition at line 467 of file serialization_manager.inc.

468  {
469  if (!$groupTag)
470  {
471  throw new FakoliException("No group tag specified for compound serialization handler");
472  }
473 
474  $this->groupTag = $groupTag;
475  for($i = 1; $i < func_num_args(); ++$i)
476  {
477  $arg = func_get_arg($i);
478  if (is_array($arg))
479  {
480  $this->classes[] = $arg;
481  }
482  else
483  {
484  $this->classes[] = array($arg, "");
485  }
486  }
487  }
FakoliException is the base exception class for all Fakoli errors.
Definition: core.inc:53

Member Function Documentation

◆ addTarget()

CompoundSerializationHandler::addTarget (   $class,
  $constraint = "" 
)

Add a target DataItem with optional constraint.

Parameters
string$classthe target DataItem class
string$constraintoptional database constraint to use for export

Definition at line 494 of file serialization_manager.inc.

495  {
496  $this->classes[] = array($class, $constraint);
497  }
$constraint

◆ export()

CompoundSerializationHandler::export ( )

Exports the target DataItems to XML.

Returns
string the XML serialization of the objects

Definition at line 503 of file serialization_manager.inc.

504  {
505  $xml = "\n<{$this->groupTag}>";
506  foreach($this->classes as $class)
507  {
509  }
510 
511  $xml .= "\n</{$this->groupTag}>";
512  return $xml;
513  }
static serialize($class, $constraint="")
Serializes the specified DataItems to XML.

◆ import()

CompoundSerializationHandler::import (   $doc,
  $tx 
)

Import from a serialized XML document.

Parameters
DOMDocument$docThe document to be used as the source of the import
DataTransaction$txThe database transaction to join when creating imported objects

Definition at line 520 of file serialization_manager.inc.

521  {
522  global $process;
523 
524  foreach($this->classes as $class)
525  {
527  }
528 
529  if ($process)
530  {
531  $process->setProgress("Completed", "Import successful", 100);
532  }
533  }
static store($class, $doc, $tx)
$process
Definition: run.php:54

◆ retrieve()

CompoundSerializationHandler::retrieve (   $doc,
  $class 
)

Retrieves serialized objects from the provided XML document, but does not store them in the database.

Instead they are returned as an array so that further processing can be carried out.

Parameters
DOMDocument$docThe document to be used as the source of the retrieval
string$classThe class of objects to retrieve
Returns
array an array of DataItems

Definition at line 542 of file serialization_manager.inc.

543  {
544  return SerializationManager::unserialize($class, $doc, null, false);
545  }
static unserialize($class, $doc, $tx, $save=true)
Instantiates DataItems from the supplied XML document and stores them in the database.

Member Data Documentation

◆ $classes

CompoundSerializationHandler::$classes = array()

Definition at line 459 of file serialization_manager.inc.

◆ $constraints

CompoundSerializationHandler::$constraints = array()

Definition at line 460 of file serialization_manager.inc.

◆ $groupTag

CompoundSerializationHandler::$groupTag

Definition at line 458 of file serialization_manager.inc.


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