Class Scenario_Core

Description

Core class

Base Scenario class, singleton pattern for easy access to the library's functionality.

  • copyright: Copyright (c) 2010 TK Studios. (http://www.tkstudios.com)
  • license: New BSD License

Located in /Scenario/Core.php (line 32)


	
			
Direct descendents
Class Description
Scenario Core subclass
Variable Summary
Method Summary
static void Complete (string|Scenario_Experiment $experiment, [null|Scenario_Identity $identity = null])
static Scenario_Experiment Experiment (string $name)
static Scenario_Identity Identity ([array $params = array()])
static bool IsControl (string|Scenario_Experiment $experiment, [null|Scenario_Identity $ident = null])
static void RenderXml (string|Scenario_Experiment $experiment, [string $style = 'html'], [bool $capture = false])
static Scenario_Treatment Treatment (string|Scenario_Experiment $experiment, [Scenario_Identity $id = null], [bool $create = true])
Scenario_Core __construct ([ $config = array()])
Scenario_Core config ([ $options = array()])
Scenario_Experiment getExperiment (string $experimentname)
mixed getOption (string $str)
array getOptions ()
Variables
static array $_defaultConfig = array(
'classPrefix' => 'Experiment_',
// the following are not yet in use, but are assumed to be these values.
'createMissingExperiments' => true,
'createMissingTreatments' => true,
'defaultIdentityGenerator' => 'session',
'defaultExperimentClass' => 'Scenario_Experiment'
)
(line 40)

Holds the default configuration data, to be selectively overwritten by config method.

  • access: protected
static Scenario_Core $_instance (line 55)

Holds the singleton instance.

  • access: protected
Scenario_Data_Adapter $_adapter (line 233)

Data adapter to handle storage & retrieval of testing data.

  • access: protected
array $_config (line 226)

Configuration data.

  • access: protected
Methods
static method Complete (line 211)

Marks a treatment as being completed.

  • access: public
static void Complete (string|Scenario_Experiment $experiment, [null|Scenario_Identity $identity = null])
static method Experiment (line 132)

Gets the experiment for the specified name.

Example:

  1.  $experiment Scenario_Core::Experiment('experimentname');

  • return: Experiment object for provided name.
  • access: public
static Scenario_Experiment Experiment (string $name)
  • string $name: Name of the experiment to retrieve.
static method getInstance (line 63)

Accesses the Core singleton instance

  • return: The core instance.
  • access: public
static Scenario_Core getInstance ()
static method Identity (line 143)

Calls and returns default Scenario_Identity object from generator.

  • return: Default identity object.
  • access: public
static Scenario_Identity Identity ([array $params = array()])
  • array $params: Parameters to pass to the identity provider.
static method IsControl (line 165)

Shortcut for one-line A/B testing.

Example:

  1.  if (Scenario_Core::IsControl('experimentname')) {
  2.       // control version
  3.  else {
  4.       // alternate version
  5.  }

  • return: Whether or not the specified treatment is named "default"
  • access: public
static bool IsControl (string|Scenario_Experiment $experiment, [null|Scenario_Identity $ident = null])
  • string|Scenario_Experiment $experiment: Name of the experiment or experiment object.
  • null|Scenario_Identity $ident: Scenario_Identity object, defaults to Identity method if null.
static method RenderXml (line 186)

Render the results of an experiment.

Example:

  1.  // to get results as XML
  2.  $xml Scenario_Core::RenderXml('myexperiment','xml',true);
  3.  
  4.  // to output as HTML
  5.  Scenario_Core::RenderXml('myexperiment');

  • access: public
static void RenderXml (string|Scenario_Experiment $experiment, [string $style = 'html'], [bool $capture = false])
  • string|Scenario_Experiment $experiment: The experiment to retrieve results from (string or object)
  • string $style: (Optional) The style parameter to pass to the Scenario_Renderer_Xml object.
  • bool $capture: (Optional) Whether or not to capture output rather than echo it.
static method Treatment (line 93)

Static method for getting a treatment for a given experiment.

Short form usage example:

  1.  // get a treatment by string, using default ID provider (session),
  2.  // and immediately get the treatment name.
  3.  $treatmentName Scenario_Core::Treatment('myTest')->getName();
Verbose usage example:
  1.  $experiment Scenario_Core::getInstance()->getExperiment('myTest');
  2.  $treatment Scenario_Core::Treatment($experiment,$ident);
  3.  $name $treatment->getName();

  • return: Treatment object acquired.
  • access: public
static Scenario_Treatment Treatment (string|Scenario_Experiment $experiment, [Scenario_Identity $id = null], [bool $create = true])
  • string|Scenario_Experiment $experiment: The experiment (or name of the experiment) to get a treatment from.
  • Scenario_Identity $id: Identity object to get treatment for. Defaults to Scenario_Identity_Generator::getIdent()
  • bool $create: (Optional) Whether or not to create the treatment if it does not exist. Defaults to true.
Constructor __construct (line 241)

Constructor. This is usually handled by the singleton pattern, constructing a core outside of that pattern will cause errors on many calls.

  • access: public
Scenario_Core __construct ([ $config = array()])
  • array $config: Configuration options.
config (line 294)

Set configuration options.

Merges the given options array into the configuration data.

Usage example for Zend adapter:

  1.       "adapter"   => new Scenario_Data_Adapter_Zend(),
  2.       "db"        => array(
  3.           "uri"   => "mysqli://user:pass@hostname/schema",
  4.           "tables" => array(
  5.               "experiments" => "scenario_experiments",
  6.               "treatments" => "scenario_treatments",
  7.               "users_treatments" => "scenario_users_treatments"
  8.           )
  9.       )
  10.  ) );

Usage example for Pdo adapter:

  1.  // define the PDO DSN
  2.  $dsn 'mysql:host=localhost;dbname=scenario';
  3.  
  4.  // create the adapter
  5.  require_once 'Scenario/Data/Adapter/Pdo.php';
  6.  $adapter new Scenario_Data_Adapter_Pdo($dsn'username''pass');
  7.  
  8.  // configure the core
  9.  Scenario_Core::getInstance()->configarray"adapter" => $adapter ) );
  10.  // Note: if [db][tables] is omitted, adapter will use default table names.

  • access: public
Scenario_Core config ([ $options = array()])
  • array $options
getAdapter (line 337)

Get the data adapter.

  • access: public
Scenario_Data_Adapter getAdapter ()
getExperiment (line 375)

Retrieve an experiment by name.

Gets an experiement by the specified name, first checking for the existence of a class in the format [classPrefix].ucfirst(name), and defaulting to Scenario_Experiment if unable to find a custom class. Custom classes may be used to alter the behavior of experiments, particularly in regards to treatment selection.

  • access: public
Scenario_Experiment getExperiment (string $experimentname)
  • string $experimentname
getOption (line 421)

Retrieve a specific value from the configuration array.

Retrieves a specific value, sub-arrays delimited by periods. _config['test']['othertest'] may be referenced by

  1.  Scenario_Core::getInstance()->getOption('test.othertest');

  • return: Value at the given location (or null if it doesn't exist)
  • access: public
mixed getOption (string $str)
  • string $str: Period-separated'd path to desired option.
getOptions (line 405)

Retrieve the entire configuration array.

  • access: public
array getOptions ()
getTreatment (line 348)

Retrieves a treatment from an experiment,

  • access: public
Scenario_Treatment getTreatment (mixed $experiment, Scenario_Identity $id)
setAdapter (line 326)

Set the data adapter.

Sets the data adapter in use by this instance and links the adapter back to this instance.

  • access: public
Scenario_Core setAdapter (Scenario_Data_Adapter $adapter)

Documentation generated on Sat, 23 Oct 2010 18:10:45 -0400 by phpDocumentor 1.4.3